@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.
Files changed (83) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +208 -0
  3. package/esm/deps/deno.land/std@0.180.0/http/_negotiation/common.js +40 -0
  4. package/esm/deps/deno.land/std@0.180.0/http/_negotiation/encoding.js +121 -0
  5. package/esm/deps/deno.land/std@0.180.0/http/_negotiation/language.js +110 -0
  6. package/esm/deps/deno.land/std@0.180.0/http/_negotiation/media_type.js +174 -0
  7. package/esm/deps/deno.land/std@0.180.0/http/negotiation.js +36 -0
  8. package/esm/deps/deno.land/std@0.180.0/media_types/_db.js +33 -0
  9. package/esm/deps/deno.land/std@0.180.0/media_types/_util.js +122 -0
  10. package/esm/deps/deno.land/std@0.180.0/media_types/content_type.js +54 -0
  11. package/esm/deps/deno.land/std@0.180.0/media_types/extension.js +25 -0
  12. package/esm/deps/deno.land/std@0.180.0/media_types/extensions_by_type.js +30 -0
  13. package/esm/deps/deno.land/std@0.180.0/media_types/format_media_type.js +60 -0
  14. package/esm/deps/deno.land/std@0.180.0/media_types/get_charset.js +36 -0
  15. package/esm/deps/deno.land/std@0.180.0/media_types/mod.js +22 -0
  16. package/esm/deps/deno.land/std@0.180.0/media_types/parse_media_type.js +121 -0
  17. package/esm/deps/deno.land/std@0.180.0/media_types/type_by_extension.js +23 -0
  18. package/esm/deps/deno.land/std@0.180.0/media_types/vendor/mime-db.v1.52.0.js +8555 -0
  19. package/esm/deps/deno.land/x/vary@1.0.0/mod.js +108 -0
  20. package/esm/deps.js +8 -0
  21. package/esm/encoders/deflate.js +11 -0
  22. package/esm/encoders/gzip.js +11 -0
  23. package/esm/encoders/utils.js +7 -0
  24. package/esm/middleware.js +55 -0
  25. package/esm/mod.js +3 -0
  26. package/esm/package.json +3 -0
  27. package/esm/transform.js +23 -0
  28. package/esm/types.js +3 -0
  29. package/esm/utils.js +19 -0
  30. package/package.json +55 -0
  31. package/script/deps/deno.land/std@0.180.0/http/_negotiation/common.js +45 -0
  32. package/script/deps/deno.land/std@0.180.0/http/_negotiation/encoding.js +125 -0
  33. package/script/deps/deno.land/std@0.180.0/http/_negotiation/language.js +114 -0
  34. package/script/deps/deno.land/std@0.180.0/http/_negotiation/media_type.js +178 -0
  35. package/script/deps/deno.land/std@0.180.0/http/negotiation.js +42 -0
  36. package/script/deps/deno.land/std@0.180.0/media_types/_db.js +39 -0
  37. package/script/deps/deno.land/std@0.180.0/media_types/_util.js +132 -0
  38. package/script/deps/deno.land/std@0.180.0/media_types/content_type.js +58 -0
  39. package/script/deps/deno.land/std@0.180.0/media_types/extension.js +29 -0
  40. package/script/deps/deno.land/std@0.180.0/media_types/extensions_by_type.js +34 -0
  41. package/script/deps/deno.land/std@0.180.0/media_types/format_media_type.js +64 -0
  42. package/script/deps/deno.land/std@0.180.0/media_types/get_charset.js +40 -0
  43. package/script/deps/deno.land/std@0.180.0/media_types/mod.js +38 -0
  44. package/script/deps/deno.land/std@0.180.0/media_types/parse_media_type.js +125 -0
  45. package/script/deps/deno.land/std@0.180.0/media_types/type_by_extension.js +27 -0
  46. package/script/deps/deno.land/std@0.180.0/media_types/vendor/mime-db.v1.52.0.js +8557 -0
  47. package/script/deps/deno.land/x/vary@1.0.0/mod.js +113 -0
  48. package/script/deps.js +22 -0
  49. package/script/encoders/deflate.js +14 -0
  50. package/script/encoders/gzip.js +14 -0
  51. package/script/encoders/utils.js +10 -0
  52. package/script/middleware.js +61 -0
  53. package/script/mod.js +7 -0
  54. package/script/package.json +3 -0
  55. package/script/transform.js +27 -0
  56. package/script/types.js +4 -0
  57. package/script/utils.js +24 -0
  58. package/types/deps/deno.land/std@0.180.0/http/_negotiation/common.d.ts +37 -0
  59. package/types/deps/deno.land/std@0.180.0/http/_negotiation/encoding.d.ts +33 -0
  60. package/types/deps/deno.land/std@0.180.0/http/_negotiation/language.d.ts +30 -0
  61. package/types/deps/deno.land/std@0.180.0/http/_negotiation/media_type.d.ts +30 -0
  62. package/types/deps/deno.land/std@0.180.0/http/negotiation.d.ts +126 -0
  63. package/types/deps/deno.land/std@0.180.0/media_types/_db.d.ts +5 -0
  64. package/types/deps/deno.land/std@0.180.0/media_types/_util.d.ts +21 -0
  65. package/types/deps/deno.land/std@0.180.0/media_types/content_type.d.ts +38 -0
  66. package/types/deps/deno.land/std@0.180.0/media_types/extension.d.ts +17 -0
  67. package/types/deps/deno.land/std@0.180.0/media_types/extensions_by_type.d.ts +20 -0
  68. package/types/deps/deno.land/std@0.180.0/media_types/format_media_type.d.ts +16 -0
  69. package/types/deps/deno.land/std@0.180.0/media_types/get_charset.d.ts +15 -0
  70. package/types/deps/deno.land/std@0.180.0/media_types/mod.d.ts +20 -0
  71. package/types/deps/deno.land/std@0.180.0/media_types/parse_media_type.d.ts +37 -0
  72. package/types/deps/deno.land/std@0.180.0/media_types/type_by_extension.d.ts +17 -0
  73. package/types/deps/deno.land/std@0.180.0/media_types/vendor/mime-db.v1.52.0.d.ts +8518 -0
  74. package/types/deps/deno.land/x/vary@1.0.0/mod.d.ts +23 -0
  75. package/types/deps.d.ts +7 -0
  76. package/types/encoders/deflate.d.ts +3 -0
  77. package/types/encoders/gzip.d.ts +3 -0
  78. package/types/encoders/utils.d.ts +4 -0
  79. package/types/middleware.d.ts +28 -0
  80. package/types/mod.d.ts +2 -0
  81. package/types/transform.d.ts +3 -0
  82. package/types/types.d.ts +15 -0
  83. 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;
@@ -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,3 @@
1
+ import type { Encoder } from "../types.js";
2
+ /** Encoder for `deflate` */
3
+ export declare const Deflate: Encoder;
@@ -0,0 +1,3 @@
1
+ import type { Encoder } from "../types.js";
2
+ /** Encoder for `gzip` */
3
+ export declare const Gzip: Encoder;
@@ -0,0 +1,4 @@
1
+ export declare enum Format {
2
+ Gzip = "gzip",
3
+ Deflate = "deflate"
4
+ }
@@ -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
@@ -0,0 +1,2 @@
1
+ export { compression } from "./middleware.js";
2
+ export type { Encode, Encoder, EncodingMap } from "./types.js";
@@ -0,0 +1,3 @@
1
+ import type { Encoder } from "./types.js";
2
+ /** Response with `Content-Encoding` header. */
3
+ export declare function withContentEncoding(response: Response, context: Encoder): Promise<Response>;
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ export declare function isNoTransform(input: string): boolean;
2
+ export declare function reCalcContentLength(response: Response): Promise<Response>;