@httpland/compression-middleware 1.0.0-beta.1
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/LICENSE +20 -0
- package/README.md +208 -0
- package/esm/deps/deno.land/std@0.180.0/http/_negotiation/common.js +40 -0
- package/esm/deps/deno.land/std@0.180.0/http/_negotiation/encoding.js +121 -0
- package/esm/deps/deno.land/std@0.180.0/http/_negotiation/language.js +110 -0
- package/esm/deps/deno.land/std@0.180.0/http/_negotiation/media_type.js +174 -0
- package/esm/deps/deno.land/std@0.180.0/http/negotiation.js +36 -0
- package/esm/deps/deno.land/std@0.180.0/media_types/_db.js +33 -0
- package/esm/deps/deno.land/std@0.180.0/media_types/_util.js +122 -0
- package/esm/deps/deno.land/std@0.180.0/media_types/content_type.js +54 -0
- package/esm/deps/deno.land/std@0.180.0/media_types/extension.js +25 -0
- package/esm/deps/deno.land/std@0.180.0/media_types/extensions_by_type.js +30 -0
- package/esm/deps/deno.land/std@0.180.0/media_types/format_media_type.js +60 -0
- package/esm/deps/deno.land/std@0.180.0/media_types/get_charset.js +36 -0
- package/esm/deps/deno.land/std@0.180.0/media_types/mod.js +22 -0
- package/esm/deps/deno.land/std@0.180.0/media_types/parse_media_type.js +121 -0
- package/esm/deps/deno.land/std@0.180.0/media_types/type_by_extension.js +23 -0
- package/esm/deps/deno.land/std@0.180.0/media_types/vendor/mime-db.v1.52.0.js +8555 -0
- package/esm/deps/deno.land/x/vary@1.0.0/mod.js +108 -0
- package/esm/deps.js +8 -0
- package/esm/encoders/deflate.js +11 -0
- package/esm/encoders/gzip.js +11 -0
- package/esm/encoders/utils.js +7 -0
- package/esm/middleware.js +55 -0
- package/esm/mod.js +3 -0
- package/esm/package.json +3 -0
- package/esm/transform.js +23 -0
- package/esm/types.js +3 -0
- package/esm/utils.js +19 -0
- package/package.json +55 -0
- package/script/deps/deno.land/std@0.180.0/http/_negotiation/common.js +45 -0
- package/script/deps/deno.land/std@0.180.0/http/_negotiation/encoding.js +125 -0
- package/script/deps/deno.land/std@0.180.0/http/_negotiation/language.js +114 -0
- package/script/deps/deno.land/std@0.180.0/http/_negotiation/media_type.js +178 -0
- package/script/deps/deno.land/std@0.180.0/http/negotiation.js +42 -0
- package/script/deps/deno.land/std@0.180.0/media_types/_db.js +39 -0
- package/script/deps/deno.land/std@0.180.0/media_types/_util.js +132 -0
- package/script/deps/deno.land/std@0.180.0/media_types/content_type.js +58 -0
- package/script/deps/deno.land/std@0.180.0/media_types/extension.js +29 -0
- package/script/deps/deno.land/std@0.180.0/media_types/extensions_by_type.js +34 -0
- package/script/deps/deno.land/std@0.180.0/media_types/format_media_type.js +64 -0
- package/script/deps/deno.land/std@0.180.0/media_types/get_charset.js +40 -0
- package/script/deps/deno.land/std@0.180.0/media_types/mod.js +38 -0
- package/script/deps/deno.land/std@0.180.0/media_types/parse_media_type.js +125 -0
- package/script/deps/deno.land/std@0.180.0/media_types/type_by_extension.js +27 -0
- package/script/deps/deno.land/std@0.180.0/media_types/vendor/mime-db.v1.52.0.js +8557 -0
- package/script/deps/deno.land/x/vary@1.0.0/mod.js +113 -0
- package/script/deps.js +22 -0
- package/script/encoders/deflate.js +14 -0
- package/script/encoders/gzip.js +14 -0
- package/script/encoders/utils.js +10 -0
- package/script/middleware.js +61 -0
- package/script/mod.js +7 -0
- package/script/package.json +3 -0
- package/script/transform.js +27 -0
- package/script/types.js +4 -0
- package/script/utils.js +24 -0
- package/types/deps/deno.land/std@0.180.0/http/_negotiation/common.d.ts +37 -0
- package/types/deps/deno.land/std@0.180.0/http/_negotiation/encoding.d.ts +33 -0
- package/types/deps/deno.land/std@0.180.0/http/_negotiation/language.d.ts +30 -0
- package/types/deps/deno.land/std@0.180.0/http/_negotiation/media_type.d.ts +30 -0
- package/types/deps/deno.land/std@0.180.0/http/negotiation.d.ts +126 -0
- package/types/deps/deno.land/std@0.180.0/media_types/_db.d.ts +5 -0
- package/types/deps/deno.land/std@0.180.0/media_types/_util.d.ts +21 -0
- package/types/deps/deno.land/std@0.180.0/media_types/content_type.d.ts +38 -0
- package/types/deps/deno.land/std@0.180.0/media_types/extension.d.ts +17 -0
- package/types/deps/deno.land/std@0.180.0/media_types/extensions_by_type.d.ts +20 -0
- package/types/deps/deno.land/std@0.180.0/media_types/format_media_type.d.ts +16 -0
- package/types/deps/deno.land/std@0.180.0/media_types/get_charset.d.ts +15 -0
- package/types/deps/deno.land/std@0.180.0/media_types/mod.d.ts +20 -0
- package/types/deps/deno.land/std@0.180.0/media_types/parse_media_type.d.ts +37 -0
- package/types/deps/deno.land/std@0.180.0/media_types/type_by_extension.d.ts +17 -0
- package/types/deps/deno.land/std@0.180.0/media_types/vendor/mime-db.v1.52.0.d.ts +8518 -0
- package/types/deps/deno.land/x/vary@1.0.0/mod.d.ts +23 -0
- package/types/deps.d.ts +7 -0
- package/types/encoders/deflate.d.ts +3 -0
- package/types/encoders/gzip.d.ts +3 -0
- package/types/encoders/utils.d.ts +4 -0
- package/types/middleware.d.ts +28 -0
- package/types/mod.d.ts +2 -0
- package/types/transform.d.ts +3 -0
- package/types/types.d.ts +15 -0
- package/types/utils.d.ts +2 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Based on https://github.com/jshttp/vary/blob/master/index.js
|
|
3
|
+
* Copyright(c) 2014-2017 Douglas Christopher Wilson
|
|
4
|
+
* Copyright(c) 2020 Henry Zhuang
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Append a field to a vary header.
|
|
9
|
+
*
|
|
10
|
+
* @param {String} header
|
|
11
|
+
* @param {String|Array} field
|
|
12
|
+
* @return {String}
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare function append(header: string, field: string | string[]): string;
|
|
16
|
+
/**
|
|
17
|
+
* Mark that a request is varied on a header field.
|
|
18
|
+
*
|
|
19
|
+
* @param {Headers} header
|
|
20
|
+
* @param {String|Array} field
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare function vary(header: Headers, field: string | string[]): void;
|
package/types/deps.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { type Middleware } from "@httpland/http-middleware";
|
|
2
|
+
export { CachingHeader, ContentNegotiationHeader, RepresentationHeader, } from "@httpland/http-utils";
|
|
3
|
+
export { acceptsEncodings } from "./deps/deno.land/std@0.180.0/http/negotiation.js";
|
|
4
|
+
export { parseMediaType } from "./deps/deno.land/std@0.180.0/media_types/mod.js";
|
|
5
|
+
export { isNull } from "isxx";
|
|
6
|
+
export { default as compressible } from "compressible";
|
|
7
|
+
export { vary } from "./deps/deno.land/x/vary@1.0.0/mod.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Middleware } from "./deps.js";
|
|
2
|
+
import type { Encode, Encoder, EncodingMap } from "./types.js";
|
|
3
|
+
/** Create HTTP content compression middleware.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { compression } from "https://deno.land/x/compression_middleware@$VERSION/mod.ts";
|
|
8
|
+
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
|
|
9
|
+
*
|
|
10
|
+
* const middleware = compression();
|
|
11
|
+
* const request = new Request("test:", {
|
|
12
|
+
* headers: {
|
|
13
|
+
* "accept-encoding": "deflate;q=0.5, gzip;q=1.0, deflate-raw;q=0.3",
|
|
14
|
+
* },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const response = await middleware(
|
|
18
|
+
* request,
|
|
19
|
+
* () => new Response("<body>"),
|
|
20
|
+
* );
|
|
21
|
+
*
|
|
22
|
+
* assertEquals(await response.text(), "<gzip:body>");
|
|
23
|
+
* assertEquals(response.headers.get("content-encoding"), "gzip");
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function compression(encoders?: Encoder[] | EncodingMap): Middleware;
|
|
27
|
+
export declare function flat(encoder: Encoder): [encoding: string, encode: Encode];
|
|
28
|
+
export declare function fromEncoders(encoders: readonly Encoder[]): EncodingMap;
|
package/types/mod.d.ts
ADDED
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Encoding and encode mapping. */
|
|
2
|
+
export interface EncodingMap {
|
|
3
|
+
[k: string]: Encode;
|
|
4
|
+
}
|
|
5
|
+
/** Stream encode API. */
|
|
6
|
+
export interface Encode {
|
|
7
|
+
(stream: ReadableStream<Uint8Array>): BodyInit | Promise<BodyInit>;
|
|
8
|
+
}
|
|
9
|
+
/** Stream encoder API. */
|
|
10
|
+
export interface Encoder {
|
|
11
|
+
/** Encoding format. */
|
|
12
|
+
readonly encoding: string;
|
|
13
|
+
/** Encode stream. */
|
|
14
|
+
readonly encode: Encode;
|
|
15
|
+
}
|
package/types/utils.d.ts
ADDED