@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,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseMediaType = void 0;
4
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
5
+ const _util_js_1 = require("./_util.js");
6
+ /**
7
+ * Parses the media type and any optional parameters, per
8
+ * [RFC 1521](https://datatracker.ietf.org/doc/html/rfc1521). Media types are
9
+ * the values in `Content-Type` and `Content-Disposition` headers. On success
10
+ * the function returns a tuple where the first element is the media type and
11
+ * the second element is the optional parameters or `undefined` if there are
12
+ * none.
13
+ *
14
+ * The function will throw if the parsed value is invalid.
15
+ *
16
+ * The returned media type will be normalized to be lower case, and returned
17
+ * params keys will be normalized to lower case, but preserves the casing of
18
+ * the value.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { parseMediaType } from "https://deno.land/std@$STD_VERSION/media_types/parse_media_type.ts";
23
+ * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
24
+ *
25
+ * assertEquals(
26
+ * parseMediaType("application/JSON"),
27
+ * [
28
+ * "application/json",
29
+ * undefined
30
+ * ]
31
+ * );
32
+ *
33
+ * assertEquals(
34
+ * parseMediaType("text/html; charset=UTF-8"),
35
+ * [
36
+ * "application/json",
37
+ * { charset: "UTF-8" },
38
+ * ]
39
+ * );
40
+ * ```
41
+ */
42
+ function parseMediaType(v) {
43
+ const [base] = v.split(";");
44
+ const mediaType = base.toLowerCase().trim();
45
+ const params = {};
46
+ // Map of base parameter name -> parameter name -> value
47
+ // for parameters containing a '*' character.
48
+ const continuation = new Map();
49
+ v = v.slice(base.length);
50
+ while (v.length) {
51
+ v = v.trimStart();
52
+ if (v.length === 0) {
53
+ break;
54
+ }
55
+ const [key, value, rest] = (0, _util_js_1.consumeMediaParam)(v);
56
+ if (!key) {
57
+ if (rest.trim() === ";") {
58
+ // ignore trailing semicolons
59
+ break;
60
+ }
61
+ throw new TypeError("Invalid media parameter.");
62
+ }
63
+ let pmap = params;
64
+ const [baseName, rest2] = key.split("*");
65
+ if (baseName && rest2 != null) {
66
+ if (!continuation.has(baseName)) {
67
+ continuation.set(baseName, {});
68
+ }
69
+ pmap = continuation.get(baseName);
70
+ }
71
+ if (key in pmap) {
72
+ throw new TypeError("Duplicate key parsed.");
73
+ }
74
+ pmap[key] = value;
75
+ v = rest;
76
+ }
77
+ // Stitch together any continuations or things with stars
78
+ // (i.e. RFC 2231 things with stars: "foo*0" or "foo*")
79
+ let str = "";
80
+ for (const [key, pieceMap] of continuation) {
81
+ const singlePartKey = `${key}*`;
82
+ const v = pieceMap[singlePartKey];
83
+ if (v) {
84
+ const decv = (0, _util_js_1.decode2331Encoding)(v);
85
+ if (decv) {
86
+ params[key] = decv;
87
+ }
88
+ continue;
89
+ }
90
+ str = "";
91
+ let valid = false;
92
+ for (let n = 0;; n++) {
93
+ const simplePart = `${key}*${n}`;
94
+ let v = pieceMap[simplePart];
95
+ if (v) {
96
+ valid = true;
97
+ str += v;
98
+ continue;
99
+ }
100
+ const encodedPart = `${simplePart}*`;
101
+ v = pieceMap[encodedPart];
102
+ if (!v) {
103
+ break;
104
+ }
105
+ valid = true;
106
+ if (n === 0) {
107
+ const decv = (0, _util_js_1.decode2331Encoding)(v);
108
+ if (decv) {
109
+ str += decv;
110
+ }
111
+ }
112
+ else {
113
+ const decv = decodeURI(v);
114
+ str += decv;
115
+ }
116
+ }
117
+ if (valid) {
118
+ params[key] = str;
119
+ }
120
+ }
121
+ return Object.keys(params).length
122
+ ? [mediaType, params]
123
+ : [mediaType, undefined];
124
+ }
125
+ exports.parseMediaType = parseMediaType;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.typeByExtension = void 0;
4
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
5
+ const _db_js_1 = require("./_db.js");
6
+ /**
7
+ * Returns the media type associated with the file extension. Values are
8
+ * normalized to lower case and matched irrespective of a leading `.`.
9
+ *
10
+ * When `extension` has no associated type, the function returns `undefined`.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { typeByExtension } from "https://deno.land/std@$STD_VERSION/media_types/type_by_extension.ts";
15
+ *
16
+ * typeByExtension("js"); // `application/json`
17
+ * typeByExtension(".HTML"); // `text/html`
18
+ * typeByExtension("foo"); // undefined
19
+ * typeByExtension("file.json"); // undefined
20
+ * ```
21
+ */
22
+ function typeByExtension(extension) {
23
+ extension = extension.startsWith(".") ? extension.slice(1) : extension;
24
+ // @ts-ignore workaround around denoland/dnt#148
25
+ return _db_js_1.types.get(extension.toLowerCase());
26
+ }
27
+ exports.typeByExtension = typeByExtension;