
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@httpland/content-range-parser
Advanced tools
HTTP Content-Range header field parser.
Compliant with RFC 9110, 14.4. Content-Range.
Parses string into ContentRange.
import { parseContentRange } from "https://deno.land/x/content_range_parser@$VERSION/parse.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(parseContentRange("bytes 0-100/1000"), {
rangeUnit: "bytes",
firstPos: 0,
lastPos: 100,
completeLength: 1000,
});
assertEquals(parseContentRange("bytes 100-200/*"), {
rangeUnit: "bytes",
firstPos: 100,
lastPos: 200,
completeLength: undefined,
});
assertEquals(parseContentRange("bytes */1000"), {
rangeUnit: "bytes",
completeLength: 1000,
});
If input is invalid, the following error occurs:
Throws SyntaxError if the input is invalid
<Content-Range>
syntax.
import { parseContentRange } from "https://deno.land/x/content_range_parser@$VERSION/parse.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() => parseContentRange("<invalid>"));
Throw Error if the input contains invalid semantics.
Invalid semantics are indicated as follows:
A Content-Range field value is invalid if it contains a range-resp that has a last-pos value less than its first-pos value, or a complete-length value less than or equal to its last-pos value. The recipient of an invalid Content-Range MUST NOT attempt to recombine the received content with a stored representation.
import { parseContentRange } from "https://deno.land/x/content_range_parser@$VERSION/parse.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() => parseContentRange("bytes 100-0/*"));
assertThrows(() => parseContentRange("bytes 100-200/0"));
Serialize ContentRange into string.
import { stringifyContentRange } from "https://deno.land/x/content_range_parser@$VERSION/stringify.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
assertEquals(
stringifyContentRange({
rangeUnit: "bytes",
firstPos: 0,
lastPos: 100,
completeLength: 1000,
}),
"bytes 0-100/1000",
);
assertEquals(
stringifyContentRange({
rangeUnit: "bytes",
firstPos: 100,
lastPos: 200,
completeLength: undefined,
}),
"bytes 100-200/*",
);
assertEquals(
stringifyContentRange({ rangeUnit: "bytes", completeLength: 1000 }),
"bytes */1000",
);
Throws TypeError if ContentRange contains invalid value.
import { stringifyContentRange } from "https://deno.land/x/content_range_parser@$VERSION/stringify.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() =>
stringifyContentRange({ rangeUnit: "<range-unit>", completeLength: NaN })
);
then, semantic errors are also checked.
import { stringifyContentRange } from "https://deno.land/x/content_range_parser@$VERSION/stringify.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() =>
stringifyContentRange({
rangeUnit: "<range-unit>",
firstPos: 1,
lastPos: 0, // firstPos <= lastPos
completeLength: undefined,
})
);
assertThrows(() =>
stringifyContentRange({
rangeUnit: "<range-unit>",
firstPos: 0,
lastPos: 100,
completeLength: 0, // lastPos < completeLength
})
);
ContentRange is a structured object for Content-Range header.
Each field name is from camel Case of ABNF definition name.
| Name | Type | Description |
|---|---|---|
| rangeUnit | string | Representation of <range-unit>. |
and
| Name | Type | Description |
|---|---|---|
| firstPost | number | Representation of <first-pos>. |
| lastPos | number | Representation of <last-pos>. |
| completeLength | number | undefined | Representation of <unsatisfied-range>. |
or
| Name | Type | Description |
|---|---|---|
| completeLength | number | Representation of <unsatisfied-range> |
It provides utilities.
Whether the input is RangeResp or not.
import {
type ContentRange,
isRangeResp,
} from "https://deno.land/x/content_range_parser@$VERSION/mod.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";
declare const contentRange: ContentRange;
assert(isRangeResp(contentRange));
Whether the input is UnsatisfiedRange or not.
import {
type ContentRange,
isUnsatisfiedRange,
} from "https://deno.land/x/content_range_parser@$VERSION/mod.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";
declare const contentRange: ContentRange;
assert(isUnsatisfiedRange(contentRange));
All APIs can be found in the deno doc.
Copyright © 2023-present httpland.
Released under the MIT license
FAQs
HTTP Content-Range header field parser
We found that @httpland/content-range-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.