@httpland/compression-middleware 1.0.0-beta.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/esm/deps.js +1 -1
- package/esm/middleware.js +5 -5
- package/package.json +1 -1
- package/script/deps.js +2 -1
- package/script/middleware.js +4 -4
- package/types/deps.d.ts +2 -2
- package/types/middleware.d.ts +2 -2
- package/types/mod.d.ts +1 -0
package/README.md
CHANGED
@@ -29,7 +29,7 @@ For a definition of Universal HTTP middleware, see the
|
|
29
29
|
Middleware convert message body and adds the `Content-Encoding` header to the
|
30
30
|
response.
|
31
31
|
|
32
|
-
Also, safely add `Accept-Encoding` to the `
|
32
|
+
Also, safely add `Accept-Encoding` to the `Vary` header in response.
|
33
33
|
|
34
34
|
```ts
|
35
35
|
import { compression } from "https://deno.land/x/compression_middleware@$VERSION/mod.ts";
|
package/esm/deps.js
CHANGED
@@ -3,6 +3,6 @@
|
|
3
3
|
export { CachingHeader, ContentNegotiationHeader, RepresentationHeader, } from "@httpland/http-utils";
|
4
4
|
export { acceptsEncodings } from "./deps/deno.land/std@0.180.0/http/negotiation.js";
|
5
5
|
export { parseMediaType } from "./deps/deno.land/std@0.180.0/media_types/mod.js";
|
6
|
-
export { isNull } from "isxx";
|
6
|
+
export { isIterable, isNull, } from "isxx";
|
7
7
|
export { default as compressible } from "compressible";
|
8
8
|
export { vary } from "./deps/deno.land/x/vary@1.0.0/mod.js";
|
package/esm/middleware.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
|
2
2
|
// This module is browser compatible.
|
3
|
-
import { acceptsEncodings, ContentNegotiationHeader, vary, } from "./deps.js";
|
3
|
+
import { acceptsEncodings, ContentNegotiationHeader, isIterable, vary, } from "./deps.js";
|
4
4
|
import { withContentEncoding } from "./transform.js";
|
5
5
|
import { Gzip } from "./encoders/gzip.js";
|
6
6
|
import { Deflate } from "./encoders/deflate.js";
|
7
|
-
const
|
7
|
+
const BuiltInEncoders = [Gzip, Deflate];
|
8
8
|
/** Create HTTP content compression middleware.
|
9
9
|
*
|
10
10
|
* @example
|
@@ -30,8 +30,8 @@ const DefaultEncoders = [Gzip, Deflate];
|
|
30
30
|
*/
|
31
31
|
export function compression(encoders) {
|
32
32
|
const encodingMap = {
|
33
|
-
...fromEncoders(
|
34
|
-
...
|
33
|
+
...fromEncoders(BuiltInEncoders),
|
34
|
+
...isIterable(encoders) ? fromEncoders(encoders) : encoders,
|
35
35
|
};
|
36
36
|
const encodings = Object.keys(encodingMap);
|
37
37
|
return async (request, next) => {
|
@@ -50,6 +50,6 @@ export function flat(encoder) {
|
|
50
50
|
return [encoder.encoding, encoder.encode];
|
51
51
|
}
|
52
52
|
export function fromEncoders(encoders) {
|
53
|
-
return Object.fromEntries(encoders.map(flat));
|
53
|
+
return Object.fromEntries(Array.from(encoders).map(flat));
|
54
54
|
}
|
55
55
|
const IDENTITY = "identity";
|
package/package.json
CHANGED
package/script/deps.js
CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
6
6
|
};
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
8
|
-
exports.vary = exports.compressible = exports.isNull = exports.parseMediaType = exports.acceptsEncodings = exports.RepresentationHeader = exports.ContentNegotiationHeader = exports.CachingHeader = void 0;
|
8
|
+
exports.vary = exports.compressible = exports.isNull = exports.isIterable = exports.parseMediaType = exports.acceptsEncodings = exports.RepresentationHeader = exports.ContentNegotiationHeader = exports.CachingHeader = void 0;
|
9
9
|
var http_utils_1 = require("@httpland/http-utils");
|
10
10
|
Object.defineProperty(exports, "CachingHeader", { enumerable: true, get: function () { return http_utils_1.CachingHeader; } });
|
11
11
|
Object.defineProperty(exports, "ContentNegotiationHeader", { enumerable: true, get: function () { return http_utils_1.ContentNegotiationHeader; } });
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "acceptsEncodings", { enumerable: true, get: func
|
|
15
15
|
var mod_js_1 = require("./deps/deno.land/std@0.180.0/media_types/mod.js");
|
16
16
|
Object.defineProperty(exports, "parseMediaType", { enumerable: true, get: function () { return mod_js_1.parseMediaType; } });
|
17
17
|
var isxx_1 = require("isxx");
|
18
|
+
Object.defineProperty(exports, "isIterable", { enumerable: true, get: function () { return isxx_1.isIterable; } });
|
18
19
|
Object.defineProperty(exports, "isNull", { enumerable: true, get: function () { return isxx_1.isNull; } });
|
19
20
|
var compressible_1 = require("compressible");
|
20
21
|
Object.defineProperty(exports, "compressible", { enumerable: true, get: function () { return __importDefault(compressible_1).default; } });
|
package/script/middleware.js
CHANGED
@@ -7,7 +7,7 @@ const deps_js_1 = require("./deps.js");
|
|
7
7
|
const transform_js_1 = require("./transform.js");
|
8
8
|
const gzip_js_1 = require("./encoders/gzip.js");
|
9
9
|
const deflate_js_1 = require("./encoders/deflate.js");
|
10
|
-
const
|
10
|
+
const BuiltInEncoders = [gzip_js_1.Gzip, deflate_js_1.Deflate];
|
11
11
|
/** Create HTTP content compression middleware.
|
12
12
|
*
|
13
13
|
* @example
|
@@ -33,8 +33,8 @@ const DefaultEncoders = [gzip_js_1.Gzip, deflate_js_1.Deflate];
|
|
33
33
|
*/
|
34
34
|
function compression(encoders) {
|
35
35
|
const encodingMap = {
|
36
|
-
...fromEncoders(
|
37
|
-
...
|
36
|
+
...fromEncoders(BuiltInEncoders),
|
37
|
+
...(0, deps_js_1.isIterable)(encoders) ? fromEncoders(encoders) : encoders,
|
38
38
|
};
|
39
39
|
const encodings = Object.keys(encodingMap);
|
40
40
|
return async (request, next) => {
|
@@ -55,7 +55,7 @@ function flat(encoder) {
|
|
55
55
|
}
|
56
56
|
exports.flat = flat;
|
57
57
|
function fromEncoders(encoders) {
|
58
|
-
return Object.fromEntries(encoders.map(flat));
|
58
|
+
return Object.fromEntries(Array.from(encoders).map(flat));
|
59
59
|
}
|
60
60
|
exports.fromEncoders = fromEncoders;
|
61
61
|
const IDENTITY = "identity";
|
package/types/deps.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
export { type Middleware } from "@httpland/http-middleware";
|
1
|
+
export { type Handler, type Middleware, } from "@httpland/http-middleware";
|
2
2
|
export { CachingHeader, ContentNegotiationHeader, RepresentationHeader, } from "@httpland/http-utils";
|
3
3
|
export { acceptsEncodings } from "./deps/deno.land/std@0.180.0/http/negotiation.js";
|
4
4
|
export { parseMediaType } from "./deps/deno.land/std@0.180.0/media_types/mod.js";
|
5
|
-
export { isNull } from "isxx";
|
5
|
+
export { isIterable, isNull, } from "isxx";
|
6
6
|
export { default as compressible } from "compressible";
|
7
7
|
export { vary } from "./deps/deno.land/x/vary@1.0.0/mod.js";
|
package/types/middleware.d.ts
CHANGED
@@ -23,6 +23,6 @@ import type { Encode, Encoder, EncodingMap } from "./types.js";
|
|
23
23
|
* assertEquals(response.headers.get("content-encoding"), "gzip");
|
24
24
|
* ```
|
25
25
|
*/
|
26
|
-
export declare function compression(encoders?: Encoder
|
26
|
+
export declare function compression(encoders?: Iterable<Encoder> | EncodingMap): Middleware;
|
27
27
|
export declare function flat(encoder: Encoder): [encoding: string, encode: Encode];
|
28
|
-
export declare function fromEncoders(encoders:
|
28
|
+
export declare function fromEncoders(encoders: Iterable<Encoder>): EncodingMap;
|
package/types/mod.d.ts
CHANGED