@browsercore/http1 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/decompress.d.ts +9 -5
- package/dist/decompress.d.ts.map +1 -1
- package/dist/decompress.js +19 -41
- package/dist/decompress.js.map +1 -1
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -53,8 +53,10 @@ await conn.close();
|
|
|
53
53
|
|
|
54
54
|
```
|
|
55
55
|
@browsercore/http1
|
|
56
|
+
└─ @browsercore/compression
|
|
56
57
|
└─ @browsercore/transport
|
|
57
58
|
└─ node:net / node:dns / node:crypto
|
|
58
59
|
```
|
|
59
60
|
|
|
60
|
-
|
|
61
|
+
`@browsercore/compression` wraps `node:zlib`; `@browsercore/http1` calls it
|
|
62
|
+
never `node:zlib` directly.
|
package/dist/decompress.d.ts
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
* Content-encoding decompression for HTTP/1.1 responses.
|
|
3
3
|
*
|
|
4
4
|
* Pure function — operates on the full buffered body bytes (after any
|
|
5
|
-
* transfer-encoding has been removed).
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* transfer-encoding has been removed). Delegates to `@browsercore/compression`
|
|
6
|
+
* so the zlib backend is replaceable; maps the provider's typed errors onto
|
|
7
|
+
* HTTP/1.1's `ContentEncodingError` to preserve this package's public contract.
|
|
8
|
+
*
|
|
9
|
+
* Kept out of `message.ts` so the message parser stays a pure wire-format
|
|
10
|
+
* function with no dependency on zlib.
|
|
8
11
|
*/
|
|
9
12
|
/** Content-encoding values we can decode — literal union, never bare `string`. */
|
|
10
13
|
export type ContentEncoding = "gzip" | "deflate" | "br";
|
|
@@ -14,8 +17,9 @@ export declare function isSupportedContentEncoding(value: string): value is Cont
|
|
|
14
17
|
* Decompress a body according to a `content-encoding` header value.
|
|
15
18
|
*
|
|
16
19
|
* For `deflate`, servers disagree on framing: some send a zlib-wrapped stream
|
|
17
|
-
* (what the RFC calls for), some send raw deflate.
|
|
18
|
-
* back to raw inflate, matching the de-facto
|
|
20
|
+
* (what the RFC calls for), some send raw deflate. The underlying provider
|
|
21
|
+
* tries zlib first and falls back to raw inflate, matching the de-facto
|
|
22
|
+
* browser tolerance.
|
|
19
23
|
*
|
|
20
24
|
* @throws {ContentEncodingError} on an unsupported value or corrupt stream.
|
|
21
25
|
*/
|
package/dist/decompress.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompress.d.ts","sourceRoot":"","sources":["../src/decompress.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"decompress.d.ts","sourceRoot":"","sources":["../src/decompress.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AASH,kFAAkF;AAClF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAIxD,mEAAmE;AACnE,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,eAAe,CAElF;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAc7E"}
|
package/dist/decompress.js
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
* Content-encoding decompression for HTTP/1.1 responses.
|
|
3
3
|
*
|
|
4
4
|
* Pure function — operates on the full buffered body bytes (after any
|
|
5
|
-
* transfer-encoding has been removed).
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* transfer-encoding has been removed). Delegates to `@browsercore/compression`
|
|
6
|
+
* so the zlib backend is replaceable; maps the provider's typed errors onto
|
|
7
|
+
* HTTP/1.1's `ContentEncodingError` to preserve this package's public contract.
|
|
8
|
+
*
|
|
9
|
+
* Kept out of `message.ts` so the message parser stays a pure wire-format
|
|
10
|
+
* function with no dependency on zlib.
|
|
8
11
|
*/
|
|
9
|
-
import {
|
|
12
|
+
import { compression, DecompressionError, UnsupportedEncodingError, } from "@browsercore/compression";
|
|
10
13
|
import { ContentEncodingError } from "./errors.js";
|
|
11
14
|
const SUPPORTED_ENCODINGS = ["gzip", "deflate", "br"];
|
|
12
15
|
/** Whether `value` is a content-encoding we know how to decode. */
|
|
@@ -17,51 +20,26 @@ export function isSupportedContentEncoding(value) {
|
|
|
17
20
|
* Decompress a body according to a `content-encoding` header value.
|
|
18
21
|
*
|
|
19
22
|
* For `deflate`, servers disagree on framing: some send a zlib-wrapped stream
|
|
20
|
-
* (what the RFC calls for), some send raw deflate.
|
|
21
|
-
* back to raw inflate, matching the de-facto
|
|
23
|
+
* (what the RFC calls for), some send raw deflate. The underlying provider
|
|
24
|
+
* tries zlib first and falls back to raw inflate, matching the de-facto
|
|
25
|
+
* browser tolerance.
|
|
22
26
|
*
|
|
23
27
|
* @throws {ContentEncodingError} on an unsupported value or corrupt stream.
|
|
24
28
|
*/
|
|
25
29
|
export function decompressBody(body, encoding) {
|
|
26
|
-
switch (encoding) {
|
|
27
|
-
case "gzip":
|
|
28
|
-
case "x-gzip":
|
|
29
|
-
return decompressWith((b) => gunzipSync(b), body, encoding);
|
|
30
|
-
case "deflate": {
|
|
31
|
-
// Try the RFC-mandated zlib-wrapped form first, then raw deflate.
|
|
32
|
-
try {
|
|
33
|
-
return decompressWith((b) => inflateSync(b), body, encoding);
|
|
34
|
-
}
|
|
35
|
-
catch (zlibErr) {
|
|
36
|
-
if (zlibErr instanceof ContentEncodingError) {
|
|
37
|
-
return decompressWith((b) => inflateRawSync(b), body, encoding);
|
|
38
|
-
}
|
|
39
|
-
throw zlibErr;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
case "br":
|
|
43
|
-
return decompressWith((b) => brotliDecompressSync(b), body, encoding);
|
|
44
|
-
default:
|
|
45
|
-
throw new ContentEncodingError(encoding);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/** Run a zlib sync decoder, normalizing its Buffer output to a Uint8Array. */
|
|
49
|
-
function runDecoder(fn, body) {
|
|
50
|
-
const out = fn(body);
|
|
51
|
-
return out instanceof Uint8Array ? out : new Uint8Array(out);
|
|
52
|
-
}
|
|
53
|
-
/** Run a decoder and wrap any failure in a typed {@link ContentEncodingError}. */
|
|
54
|
-
function decompressWith(fn, body, encoding) {
|
|
55
30
|
try {
|
|
56
|
-
return
|
|
31
|
+
return compression.decompress(body, encoding);
|
|
57
32
|
}
|
|
58
33
|
catch (err) {
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
throw new ContentEncodingError(encoding, { cause });
|
|
34
|
+
// The provider throws its own typed errors; re-wrap as http1's
|
|
35
|
+
// ContentEncodingError so this package's public contract is stable.
|
|
36
|
+
if (err instanceof UnsupportedEncodingError) {
|
|
37
|
+
throw new ContentEncodingError(err.encoding, { cause: err });
|
|
38
|
+
}
|
|
39
|
+
if (err instanceof DecompressionError) {
|
|
40
|
+
throw new ContentEncodingError(err.encoding, { cause: err });
|
|
63
41
|
}
|
|
64
|
-
throw
|
|
42
|
+
throw err;
|
|
65
43
|
}
|
|
66
44
|
}
|
|
67
45
|
//# sourceMappingURL=decompress.js.map
|
package/dist/decompress.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompress.js","sourceRoot":"","sources":["../src/decompress.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"decompress.js","sourceRoot":"","sources":["../src/decompress.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACH,WAAW,EACX,kBAAkB,EAClB,wBAAwB,GAC3B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAKnD,MAAM,mBAAmB,GAA+B,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;AAElF,mEAAmE;AACnE,MAAM,UAAU,0BAA0B,CAAC,KAAa;IACpD,OAAQ,mBAAyC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACtE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,IAAgB,EAAE,QAAgB;IAC7D,IAAI,CAAC;QACD,OAAO,WAAW,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,+DAA+D;QAC/D,oEAAoE;QACpE,IAAI,GAAG,YAAY,wBAAwB,EAAE,CAAC;YAC1C,MAAM,IAAI,oBAAoB,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QACjE,CAAC;QACD,IAAI,GAAG,YAAY,kBAAkB,EAAE,CAAC;YACpC,MAAM,IAAI,oBAAoB,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QACjE,CAAC;QACD,MAAM,GAAG,CAAC;IACd,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@browsercore/http1",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "HTTP/1.1 client over any duplex byte stream. No knowledge of TLS or TCP
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "HTTP/1.1 client over any duplex byte stream. No knowledge of TLS or TCP \u2014 only the protocol.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/jverneuer/browsercore-http1.git"
|
|
@@ -20,7 +20,11 @@
|
|
|
20
20
|
"import": "./dist/index.js"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
|
-
"files": [
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
24
28
|
"publishConfig": {
|
|
25
29
|
"access": "public",
|
|
26
30
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -38,6 +42,7 @@
|
|
|
38
42
|
"vitest": "^2.1.8"
|
|
39
43
|
},
|
|
40
44
|
"dependencies": {
|
|
45
|
+
"@browsercore/compression": "latest",
|
|
41
46
|
"@browsercore/transport": "latest"
|
|
42
47
|
},
|
|
43
48
|
"engines": {
|