@gjsify/fetch 0.0.2 → 0.0.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/lib/cjs/body.js +65 -94
- package/lib/cjs/errors/abort-error.js +5 -24
- package/lib/cjs/errors/base.js +3 -22
- package/lib/cjs/errors/fetch-error.js +5 -24
- package/lib/cjs/headers.js +19 -48
- package/lib/cjs/index.js +70 -92
- package/lib/cjs/request.js +38 -63
- package/lib/cjs/response.js +18 -47
- package/lib/cjs/types/index.js +1 -17
- package/lib/cjs/types/system-error.js +0 -15
- package/lib/cjs/utils/blob-from.js +38 -61
- package/lib/cjs/utils/get-search.js +3 -22
- package/lib/cjs/utils/is-redirect.js +3 -22
- package/lib/cjs/utils/is.js +12 -31
- package/lib/cjs/utils/multipart-parser.js +7 -26
- package/lib/cjs/utils/referrer.js +17 -36
- package/package.json +7 -7
package/lib/cjs/body.js
CHANGED
|
@@ -1,50 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var body_exports = {};
|
|
29
|
-
__export(body_exports, {
|
|
30
|
-
clone: () => clone,
|
|
31
|
-
default: () => Body,
|
|
32
|
-
extractContentType: () => extractContentType,
|
|
33
|
-
getTotalBytes: () => getTotalBytes,
|
|
34
|
-
writeToStream: () => writeToStream
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(body_exports);
|
|
37
|
-
var import_url = require("@gjsify/deno-runtime/ext/url/00_url");
|
|
38
|
-
var import_file = require("@gjsify/deno-runtime/ext/web/09_file");
|
|
39
|
-
var import_stream = require("stream");
|
|
40
|
-
var import_web = require("stream/web");
|
|
41
|
-
var import_util = require("util");
|
|
42
|
-
var import_buffer = require("buffer");
|
|
43
|
-
var import_esm_min = require("formdata-polyfill/esm.min.js");
|
|
44
|
-
var import_fetch_error = require("./errors/fetch-error.js");
|
|
45
|
-
var import_base = require("./errors/base.js");
|
|
46
|
-
var import_is = require("./utils/is.js");
|
|
47
|
-
const pipeline = (0, import_util.promisify)(import_stream.pipeline);
|
|
1
|
+
import { URLSearchParams } from "@gjsify/deno-runtime/ext/url/00_url";
|
|
2
|
+
import { Blob } from "@gjsify/deno-runtime/ext/web/09_file";
|
|
3
|
+
import { PassThrough, pipeline as pipelineCb, Readable, Stream } from "stream";
|
|
4
|
+
import { ReadableStream as StreamWebReadableStream } from "stream/web";
|
|
5
|
+
import { types, deprecate, promisify } from "util";
|
|
6
|
+
import { Buffer } from "buffer";
|
|
7
|
+
import { FormData, formDataToBlob } from "formdata-polyfill/esm.min.js";
|
|
8
|
+
import { FetchError } from "./errors/fetch-error.js";
|
|
9
|
+
import { FetchBaseError } from "./errors/base.js";
|
|
10
|
+
import { isBlob, isURLSearchParameters } from "./utils/is.js";
|
|
11
|
+
const pipeline = promisify(pipelineCb);
|
|
48
12
|
const INTERNALS = Symbol("Body internals");
|
|
49
13
|
class Body {
|
|
50
14
|
[INTERNALS] = {
|
|
@@ -59,45 +23,45 @@ class Body {
|
|
|
59
23
|
this.size = options.size || 0;
|
|
60
24
|
if (body === null) {
|
|
61
25
|
this[INTERNALS].body = null;
|
|
62
|
-
} else if (
|
|
63
|
-
this[INTERNALS].body =
|
|
64
|
-
} else if (
|
|
65
|
-
} else if (
|
|
66
|
-
} else if (
|
|
67
|
-
this[INTERNALS].body =
|
|
26
|
+
} else if (isURLSearchParameters(body)) {
|
|
27
|
+
this[INTERNALS].body = Buffer.from(body.toString());
|
|
28
|
+
} else if (isBlob(body)) {
|
|
29
|
+
} else if (Buffer.isBuffer(body)) {
|
|
30
|
+
} else if (types.isAnyArrayBuffer(body)) {
|
|
31
|
+
this[INTERNALS].body = Buffer.from(body);
|
|
68
32
|
} else if (ArrayBuffer.isView(body)) {
|
|
69
|
-
this[INTERNALS].body =
|
|
70
|
-
} else if (body instanceof
|
|
33
|
+
this[INTERNALS].body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
34
|
+
} else if (body instanceof Readable) {
|
|
71
35
|
this[INTERNALS].body = body;
|
|
72
|
-
} else if (body instanceof ReadableStream || body instanceof
|
|
73
|
-
this[INTERNALS].body =
|
|
74
|
-
} else if (body instanceof
|
|
75
|
-
this[INTERNALS].body =
|
|
36
|
+
} else if (body instanceof ReadableStream || body instanceof StreamWebReadableStream) {
|
|
37
|
+
this[INTERNALS].body = Readable.fromWeb(body);
|
|
38
|
+
} else if (body instanceof FormData) {
|
|
39
|
+
this[INTERNALS].body = formDataToBlob(body);
|
|
76
40
|
this[INTERNALS].boundary = this[INTERNALS].body.type.split("=")[1];
|
|
77
41
|
} else if (typeof body === "string") {
|
|
78
|
-
this[INTERNALS].body =
|
|
79
|
-
} else if (body instanceof
|
|
80
|
-
this[INTERNALS].body =
|
|
42
|
+
this[INTERNALS].body = Buffer.from(body);
|
|
43
|
+
} else if (body instanceof URLSearchParams) {
|
|
44
|
+
this[INTERNALS].body = Buffer.from(body.toString());
|
|
81
45
|
} else {
|
|
82
46
|
console.warn(`Unknown body type "${typeof body}", try to parse the body to string!`);
|
|
83
|
-
this[INTERNALS].body =
|
|
47
|
+
this[INTERNALS].body = Readable.from(typeof body.toString === "function" ? body.toString() : body);
|
|
84
48
|
}
|
|
85
|
-
if (
|
|
86
|
-
this[INTERNALS].stream =
|
|
87
|
-
} else if (
|
|
88
|
-
this[INTERNALS].stream =
|
|
89
|
-
} else if (body instanceof
|
|
49
|
+
if (Buffer.isBuffer(body)) {
|
|
50
|
+
this[INTERNALS].stream = Readable.from(body);
|
|
51
|
+
} else if (isBlob(body)) {
|
|
52
|
+
this[INTERNALS].stream = Readable.from(body.stream());
|
|
53
|
+
} else if (body instanceof Readable) {
|
|
90
54
|
this[INTERNALS].stream = body;
|
|
91
55
|
}
|
|
92
|
-
if (body instanceof
|
|
56
|
+
if (body instanceof Stream) {
|
|
93
57
|
body.on("error", (error_) => {
|
|
94
|
-
const error = error_ instanceof
|
|
58
|
+
const error = error_ instanceof FetchBaseError ? error_ : new FetchError(`Invalid response body while trying to fetch ${this.url}: ${error_.message}`, "system", error_);
|
|
95
59
|
this[INTERNALS].error = error;
|
|
96
60
|
});
|
|
97
61
|
}
|
|
98
62
|
}
|
|
99
63
|
get body() {
|
|
100
|
-
return
|
|
64
|
+
return Readable.toWeb(this[INTERNALS].stream);
|
|
101
65
|
}
|
|
102
66
|
get _stream() {
|
|
103
67
|
return this[INTERNALS].stream;
|
|
@@ -117,8 +81,8 @@ class Body {
|
|
|
117
81
|
async formData() {
|
|
118
82
|
const ct = this.headers?.get("content-type");
|
|
119
83
|
if (ct.startsWith("application/x-www-form-urlencoded")) {
|
|
120
|
-
const formData = new
|
|
121
|
-
const parameters = new
|
|
84
|
+
const formData = new FormData();
|
|
85
|
+
const parameters = new URLSearchParams(await this.text());
|
|
122
86
|
for (const [name, value] of parameters) {
|
|
123
87
|
formData.append(name, value);
|
|
124
88
|
}
|
|
@@ -136,7 +100,7 @@ class Body {
|
|
|
136
100
|
async blob() {
|
|
137
101
|
const ct = this.headers?.get("content-type") || this[INTERNALS].body && this[INTERNALS].body.type || "";
|
|
138
102
|
const buf = await this.arrayBuffer();
|
|
139
|
-
return new
|
|
103
|
+
return new Blob([buf], {
|
|
140
104
|
type: ct
|
|
141
105
|
});
|
|
142
106
|
}
|
|
@@ -166,7 +130,7 @@ Object.defineProperties(Body.prototype, {
|
|
|
166
130
|
blob: { enumerable: true },
|
|
167
131
|
json: { enumerable: true },
|
|
168
132
|
text: { enumerable: true },
|
|
169
|
-
data: { get:
|
|
133
|
+
data: { get: deprecate(
|
|
170
134
|
() => {
|
|
171
135
|
},
|
|
172
136
|
"data doesn't exist, use json(), text(), arrayBuffer(), or body instead",
|
|
@@ -183,17 +147,17 @@ async function consumeBody(data) {
|
|
|
183
147
|
}
|
|
184
148
|
const { _stream: body } = data;
|
|
185
149
|
if (body === null) {
|
|
186
|
-
return
|
|
150
|
+
return Buffer.alloc(0);
|
|
187
151
|
}
|
|
188
|
-
if (!(body instanceof
|
|
189
|
-
return
|
|
152
|
+
if (!(body instanceof Stream)) {
|
|
153
|
+
return Buffer.alloc(0);
|
|
190
154
|
}
|
|
191
155
|
const accum = [];
|
|
192
156
|
let accumBytes = 0;
|
|
193
157
|
try {
|
|
194
158
|
for await (const chunk of body) {
|
|
195
159
|
if (data.size > 0 && accumBytes + chunk.length > data.size) {
|
|
196
|
-
const error = new
|
|
160
|
+
const error = new FetchError(`content size at ${data.url} over limit: ${data.size}`, "max-size");
|
|
197
161
|
body.destroy(error);
|
|
198
162
|
throw error;
|
|
199
163
|
}
|
|
@@ -201,20 +165,20 @@ async function consumeBody(data) {
|
|
|
201
165
|
accum.push(chunk);
|
|
202
166
|
}
|
|
203
167
|
} catch (error) {
|
|
204
|
-
const error_ = error instanceof
|
|
168
|
+
const error_ = error instanceof FetchBaseError ? error : new FetchError(`Invalid response body while trying to fetch ${data.url}: ${error.message}`, "system", error);
|
|
205
169
|
throw error_;
|
|
206
170
|
}
|
|
207
171
|
if (body.readableEnded === true || body._readableState.ended === true) {
|
|
208
172
|
try {
|
|
209
173
|
if (accum.every((c) => typeof c === "string")) {
|
|
210
|
-
return
|
|
174
|
+
return Buffer.from(accum.join(""));
|
|
211
175
|
}
|
|
212
|
-
return
|
|
176
|
+
return Buffer.concat(accum, accumBytes);
|
|
213
177
|
} catch (error) {
|
|
214
|
-
throw new
|
|
178
|
+
throw new FetchError(`Could not create Buffer from response body for ${data.url}: ${error.message}`, "system", error);
|
|
215
179
|
}
|
|
216
180
|
} else {
|
|
217
|
-
throw new
|
|
181
|
+
throw new FetchError(`Premature close of server response while trying to fetch ${data.url}`);
|
|
218
182
|
}
|
|
219
183
|
}
|
|
220
184
|
const clone = (instance, highWaterMark) => {
|
|
@@ -224,9 +188,9 @@ const clone = (instance, highWaterMark) => {
|
|
|
224
188
|
if (instance.bodyUsed) {
|
|
225
189
|
throw new Error("cannot clone body after it is used");
|
|
226
190
|
}
|
|
227
|
-
if (body instanceof
|
|
228
|
-
p1 = new
|
|
229
|
-
p2 = new
|
|
191
|
+
if (body instanceof Stream && typeof body.getBoundary !== "function") {
|
|
192
|
+
p1 = new PassThrough({ highWaterMark });
|
|
193
|
+
p2 = new PassThrough({ highWaterMark });
|
|
230
194
|
body.pipe(p1);
|
|
231
195
|
body.pipe(p2);
|
|
232
196
|
instance[INTERNALS].stream = p1;
|
|
@@ -241,19 +205,19 @@ const extractContentType = (body, request) => {
|
|
|
241
205
|
if (typeof body === "string") {
|
|
242
206
|
return "text/plain;charset=UTF-8";
|
|
243
207
|
}
|
|
244
|
-
if (
|
|
208
|
+
if (isURLSearchParameters(body)) {
|
|
245
209
|
return "application/x-www-form-urlencoded;charset=UTF-8";
|
|
246
210
|
}
|
|
247
|
-
if (
|
|
211
|
+
if (isBlob(body)) {
|
|
248
212
|
return body.type || null;
|
|
249
213
|
}
|
|
250
|
-
if (
|
|
214
|
+
if (Buffer.isBuffer(body) || types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) {
|
|
251
215
|
return null;
|
|
252
216
|
}
|
|
253
|
-
if (body instanceof
|
|
217
|
+
if (body instanceof FormData) {
|
|
254
218
|
return `multipart/form-data; boundary=${request[INTERNALS].boundary}`;
|
|
255
219
|
}
|
|
256
|
-
if (body instanceof
|
|
220
|
+
if (body instanceof Stream) {
|
|
257
221
|
return null;
|
|
258
222
|
}
|
|
259
223
|
return "text/plain;charset=UTF-8";
|
|
@@ -263,10 +227,10 @@ const getTotalBytes = (request) => {
|
|
|
263
227
|
if (body === null) {
|
|
264
228
|
return 0;
|
|
265
229
|
}
|
|
266
|
-
if (
|
|
230
|
+
if (isBlob(body)) {
|
|
267
231
|
return body.size;
|
|
268
232
|
}
|
|
269
|
-
if (
|
|
233
|
+
if (Buffer.isBuffer(body)) {
|
|
270
234
|
return body.length;
|
|
271
235
|
}
|
|
272
236
|
if (body && typeof body.getLengthSync === "function") {
|
|
@@ -282,3 +246,10 @@ const writeToStream = async (dest, { body }) => {
|
|
|
282
246
|
await pipeline(body, dest);
|
|
283
247
|
}
|
|
284
248
|
};
|
|
249
|
+
export {
|
|
250
|
+
clone,
|
|
251
|
+
Body as default,
|
|
252
|
+
extractContentType,
|
|
253
|
+
getTotalBytes,
|
|
254
|
+
writeToStream
|
|
255
|
+
};
|
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var abort_error_exports = {};
|
|
19
|
-
__export(abort_error_exports, {
|
|
20
|
-
AbortError: () => AbortError
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(abort_error_exports);
|
|
23
|
-
var import_base = require("./base.js");
|
|
24
|
-
class AbortError extends import_base.FetchBaseError {
|
|
1
|
+
import { FetchBaseError } from "./base.js";
|
|
2
|
+
class AbortError extends FetchBaseError {
|
|
25
3
|
constructor(message, type = "aborted") {
|
|
26
4
|
super(message, type);
|
|
27
5
|
}
|
|
28
6
|
}
|
|
7
|
+
export {
|
|
8
|
+
AbortError
|
|
9
|
+
};
|
package/lib/cjs/errors/base.js
CHANGED
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var base_exports = {};
|
|
19
|
-
__export(base_exports, {
|
|
20
|
-
FetchBaseError: () => FetchBaseError
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(base_exports);
|
|
23
1
|
class FetchBaseError extends Error {
|
|
24
2
|
type;
|
|
25
3
|
constructor(message, type) {
|
|
@@ -34,3 +12,6 @@ class FetchBaseError extends Error {
|
|
|
34
12
|
return this.constructor.name;
|
|
35
13
|
}
|
|
36
14
|
}
|
|
15
|
+
export {
|
|
16
|
+
FetchBaseError
|
|
17
|
+
};
|
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var fetch_error_exports = {};
|
|
19
|
-
__export(fetch_error_exports, {
|
|
20
|
-
FetchError: () => FetchError
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(fetch_error_exports);
|
|
23
|
-
var import_base = require("./base.js");
|
|
24
|
-
class FetchError extends import_base.FetchBaseError {
|
|
1
|
+
import { FetchBaseError } from "./base.js";
|
|
2
|
+
class FetchError extends FetchBaseError {
|
|
25
3
|
code;
|
|
26
4
|
errno;
|
|
27
5
|
erroredSysCall;
|
|
@@ -38,3 +16,6 @@ class FetchError extends import_base.FetchBaseError {
|
|
|
38
16
|
}
|
|
39
17
|
}
|
|
40
18
|
}
|
|
19
|
+
export {
|
|
20
|
+
FetchError
|
|
21
|
+
};
|
package/lib/cjs/headers.js
CHANGED
|
@@ -1,43 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var headers_exports = {};
|
|
29
|
-
__export(headers_exports, {
|
|
30
|
-
default: () => Headers,
|
|
31
|
-
fromRawHeaders: () => fromRawHeaders
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(headers_exports);
|
|
34
|
-
var import_soup_3 = __toESM(require("@girs/soup-3.0"), 1);
|
|
35
|
-
var import_url = require("@gjsify/deno-runtime/ext/url/00_url");
|
|
36
|
-
var import_util = require("util");
|
|
37
|
-
var http = __toESM(require("http"), 1);
|
|
1
|
+
import Soup from "@girs/soup-3.0";
|
|
2
|
+
import { URLSearchParams } from "@gjsify/deno-runtime/ext/url/00_url";
|
|
3
|
+
import { types } from "util";
|
|
4
|
+
import * as http from "http";
|
|
38
5
|
const validateHeaderName = http.validateHeaderName;
|
|
39
6
|
const validateHeaderValue = http.validateHeaderValue;
|
|
40
|
-
class Headers extends
|
|
7
|
+
class Headers extends URLSearchParams {
|
|
41
8
|
/**
|
|
42
9
|
* Headers class
|
|
43
10
|
*
|
|
@@ -52,7 +19,7 @@ class Headers extends import_url.URLSearchParams {
|
|
|
52
19
|
result.push(...values.map((value) => [name, value]));
|
|
53
20
|
}
|
|
54
21
|
} else if (init == null) {
|
|
55
|
-
} else if (typeof init === "object" && !
|
|
22
|
+
} else if (typeof init === "object" && !types.isBoxedPrimitive(init)) {
|
|
56
23
|
const method = init[Symbol.iterator];
|
|
57
24
|
if (method == null) {
|
|
58
25
|
result.push(...Object.entries(init));
|
|
@@ -61,7 +28,7 @@ class Headers extends import_url.URLSearchParams {
|
|
|
61
28
|
throw new TypeError("Header pairs must be iterable");
|
|
62
29
|
}
|
|
63
30
|
result = [...init].map((pair) => {
|
|
64
|
-
if (typeof pair !== "object" ||
|
|
31
|
+
if (typeof pair !== "object" || types.isBoxedPrimitive(pair)) {
|
|
65
32
|
throw new TypeError("Each header pair must be an iterable object");
|
|
66
33
|
}
|
|
67
34
|
return [...pair];
|
|
@@ -89,7 +56,7 @@ class Headers extends import_url.URLSearchParams {
|
|
|
89
56
|
return (name, value) => {
|
|
90
57
|
validateHeaderName(name);
|
|
91
58
|
validateHeaderValue(name, String(value));
|
|
92
|
-
return
|
|
59
|
+
return URLSearchParams.prototype[p].call(
|
|
93
60
|
target,
|
|
94
61
|
String(name).toLowerCase(),
|
|
95
62
|
String(value)
|
|
@@ -100,7 +67,7 @@ class Headers extends import_url.URLSearchParams {
|
|
|
100
67
|
case "getAll":
|
|
101
68
|
return (name) => {
|
|
102
69
|
validateHeaderName(name);
|
|
103
|
-
return
|
|
70
|
+
return URLSearchParams.prototype[p].call(
|
|
104
71
|
target,
|
|
105
72
|
String(name).toLowerCase()
|
|
106
73
|
);
|
|
@@ -108,7 +75,7 @@ class Headers extends import_url.URLSearchParams {
|
|
|
108
75
|
case "keys":
|
|
109
76
|
return () => {
|
|
110
77
|
target.sort();
|
|
111
|
-
return new Set(
|
|
78
|
+
return new Set(URLSearchParams.prototype.keys.call(target)).keys();
|
|
112
79
|
};
|
|
113
80
|
default:
|
|
114
81
|
return Reflect.get(target, p, receiver);
|
|
@@ -122,19 +89,19 @@ class Headers extends import_url.URLSearchParams {
|
|
|
122
89
|
toString() {
|
|
123
90
|
return Object.prototype.toString.call(this);
|
|
124
91
|
}
|
|
125
|
-
_appendToSoupMessage(message, type =
|
|
126
|
-
const soupHeaders = message ? message.get_request_headers() : new
|
|
92
|
+
_appendToSoupMessage(message, type = Soup.MessageHeadersType.REQUEST) {
|
|
93
|
+
const soupHeaders = message ? message.get_request_headers() : new Soup.MessageHeaders(type);
|
|
127
94
|
for (const header in this.entries()) {
|
|
128
95
|
soupHeaders.append(header, this.get(header));
|
|
129
96
|
}
|
|
130
97
|
return soupHeaders;
|
|
131
98
|
}
|
|
132
|
-
static _newFromSoupMessage(message, type =
|
|
99
|
+
static _newFromSoupMessage(message, type = Soup.MessageHeadersType.RESPONSE) {
|
|
133
100
|
let soupHeaders;
|
|
134
101
|
const headers = new Headers();
|
|
135
|
-
if (type ===
|
|
102
|
+
if (type === Soup.MessageHeadersType.RESPONSE) {
|
|
136
103
|
soupHeaders = message.get_response_headers();
|
|
137
|
-
} else if (type ===
|
|
104
|
+
} else if (type === Soup.MessageHeadersType.REQUEST) {
|
|
138
105
|
soupHeaders = message.get_request_headers();
|
|
139
106
|
} else {
|
|
140
107
|
for (const header in message.get_request_headers()) {
|
|
@@ -229,3 +196,7 @@ function fromRawHeaders(headers = []) {
|
|
|
229
196
|
})
|
|
230
197
|
);
|
|
231
198
|
}
|
|
199
|
+
export {
|
|
200
|
+
Headers as default,
|
|
201
|
+
fromRawHeaders
|
|
202
|
+
};
|