@gjsify/fetch 0.0.2

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 (58) hide show
  1. package/README.md +9 -0
  2. package/lib/cjs/body.js +284 -0
  3. package/lib/cjs/errors/abort-error.js +28 -0
  4. package/lib/cjs/errors/base.js +36 -0
  5. package/lib/cjs/errors/fetch-error.js +40 -0
  6. package/lib/cjs/headers.js +231 -0
  7. package/lib/cjs/index.js +246 -0
  8. package/lib/cjs/request.js +306 -0
  9. package/lib/cjs/response.js +162 -0
  10. package/lib/cjs/types/index.js +17 -0
  11. package/lib/cjs/types/system-error.js +16 -0
  12. package/lib/cjs/utils/blob-from.js +124 -0
  13. package/lib/cjs/utils/get-search.js +30 -0
  14. package/lib/cjs/utils/is-redirect.js +26 -0
  15. package/lib/cjs/utils/is.js +47 -0
  16. package/lib/cjs/utils/multipart-parser.js +372 -0
  17. package/lib/cjs/utils/referrer.js +172 -0
  18. package/lib/esm/body.js +255 -0
  19. package/lib/esm/errors/abort-error.js +9 -0
  20. package/lib/esm/errors/base.js +17 -0
  21. package/lib/esm/errors/fetch-error.js +21 -0
  22. package/lib/esm/headers.js +202 -0
  23. package/lib/esm/index.js +224 -0
  24. package/lib/esm/request.js +281 -0
  25. package/lib/esm/response.js +133 -0
  26. package/lib/esm/types/index.js +1 -0
  27. package/lib/esm/types/system-error.js +1 -0
  28. package/lib/esm/utils/blob-from.js +101 -0
  29. package/lib/esm/utils/get-search.js +11 -0
  30. package/lib/esm/utils/is-redirect.js +7 -0
  31. package/lib/esm/utils/is.js +28 -0
  32. package/lib/esm/utils/multipart-parser.js +353 -0
  33. package/lib/esm/utils/referrer.js +153 -0
  34. package/package.json +53 -0
  35. package/src/body.ts +415 -0
  36. package/src/errors/abort-error.ts +10 -0
  37. package/src/errors/base.ts +20 -0
  38. package/src/errors/fetch-error.ts +26 -0
  39. package/src/headers.ts +279 -0
  40. package/src/index.spec.ts +13 -0
  41. package/src/index.ts +367 -0
  42. package/src/request.ts +396 -0
  43. package/src/response.ts +197 -0
  44. package/src/test.mts +6 -0
  45. package/src/types/index.ts +1 -0
  46. package/src/types/system-error.ts +11 -0
  47. package/src/utils/blob-from.ts +168 -0
  48. package/src/utils/get-search.ts +9 -0
  49. package/src/utils/is-redirect.ts +11 -0
  50. package/src/utils/is.ts +88 -0
  51. package/src/utils/multipart-parser.ts +448 -0
  52. package/src/utils/referrer.ts +350 -0
  53. package/test.gjs.js +34758 -0
  54. package/test.gjs.mjs +53177 -0
  55. package/test.node.js +1226 -0
  56. package/test.node.mjs +6294 -0
  57. package/tsconfig.json +19 -0
  58. package/tsconfig.types.json +8 -0
@@ -0,0 +1,246 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
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 src_exports = {};
29
+ __export(src_exports, {
30
+ AbortError: () => import_abort_error.AbortError,
31
+ Blob: () => import_blob_from.Blob,
32
+ FetchError: () => import_fetch_error.FetchError,
33
+ File: () => import_blob_from.File,
34
+ FormData: () => import_esm_min.FormData,
35
+ Headers: () => import_headers.default,
36
+ Request: () => import_request.default,
37
+ Response: () => import_response.default,
38
+ blobFrom: () => import_blob_from.blobFrom,
39
+ blobFromSync: () => import_blob_from.blobFromSync,
40
+ default: () => fetch,
41
+ fileFrom: () => import_blob_from.fileFrom,
42
+ fileFromSync: () => import_blob_from.fileFromSync,
43
+ isRedirect: () => import_is_redirect.isRedirect
44
+ });
45
+ module.exports = __toCommonJS(src_exports);
46
+ var import_soup_3 = __toESM(require("@girs/soup-3.0"), 1);
47
+ var import_request = __toESM(require("./request.js"), 1);
48
+ var import_zlib = __toESM(require("zlib"), 1);
49
+ var import_stream = __toESM(require("stream"), 1);
50
+ var import_data_uri_to_buffer = __toESM(require("data-uri-to-buffer"), 1);
51
+ var import_body = require("./body.js");
52
+ var import_response = __toESM(require("./response.js"), 1);
53
+ var import_headers = __toESM(require("./headers.js"), 1);
54
+ var import_request2 = require("./request.js");
55
+ var import_fetch_error = require("./errors/fetch-error.js");
56
+ var import_abort_error = require("./errors/abort-error.js");
57
+ var import_is_redirect = require("./utils/is-redirect.js");
58
+ var import_esm_min = require("formdata-polyfill/esm.min.js");
59
+ var import_is = require("./utils/is.js");
60
+ var import_referrer = require("./utils/referrer.js");
61
+ var import_blob_from = require("./utils/blob-from.js");
62
+ var import_url = require("@gjsify/deno-runtime/ext/url/00_url");
63
+ const supportedSchemas = /* @__PURE__ */ new Set(["data:", "http:", "https:"]);
64
+ async function fetch(url, init = {}) {
65
+ return new Promise(async (resolve, reject) => {
66
+ const request = new import_request.default(url, init);
67
+ const { parsedURL, options } = (0, import_request2.getSoupRequestOptions)(request);
68
+ if (!supportedSchemas.has(parsedURL.protocol)) {
69
+ throw new TypeError(`@gjsify/fetch cannot load ${url}. URL scheme "${parsedURL.protocol.replace(/:$/, "")}" is not supported.`);
70
+ }
71
+ if (parsedURL.protocol === "data:") {
72
+ const data = (0, import_data_uri_to_buffer.default)(request.url);
73
+ const response2 = new import_response.default(data, { headers: { "Content-Type": data.typeFull } });
74
+ resolve(response2);
75
+ return;
76
+ }
77
+ const { signal } = request;
78
+ let response = null;
79
+ const abort = () => {
80
+ const error = new import_abort_error.AbortError("The operation was aborted.");
81
+ reject(error);
82
+ if (request.body && request.body instanceof import_stream.default.Readable) {
83
+ request.body.destroy(error);
84
+ }
85
+ if (!response || !response.body) {
86
+ return;
87
+ }
88
+ response.body.emit("error", error);
89
+ };
90
+ if (signal && signal.aborted) {
91
+ abort();
92
+ return;
93
+ }
94
+ const abortAndFinalize = () => {
95
+ abort();
96
+ finalize();
97
+ };
98
+ let readable;
99
+ let cancellable;
100
+ try {
101
+ const sendRes = await request._send(options);
102
+ readable = sendRes.readable;
103
+ cancellable = sendRes.cancellable;
104
+ } catch (error) {
105
+ reject(error);
106
+ }
107
+ if (signal) {
108
+ signal.addEventListener("abort", abortAndFinalize);
109
+ }
110
+ const cancelledSignalId = cancellable.connect("cancelled", () => {
111
+ abortAndFinalize();
112
+ });
113
+ const finalize = () => {
114
+ cancellable.cancel();
115
+ if (signal) {
116
+ signal.removeEventListener("abort", abortAndFinalize);
117
+ }
118
+ cancellable.disconnect(cancelledSignalId);
119
+ };
120
+ const message = request._message;
121
+ readable.on("error", (error) => {
122
+ reject(new import_fetch_error.FetchError(`request to ${request.url} failed, reason: ${error.message}`, "system", error));
123
+ finalize();
124
+ });
125
+ message.connect("finished", (message2) => {
126
+ const headers = import_headers.default._newFromSoupMessage(request._message, import_soup_3.default.MessageHeadersType.RESPONSE);
127
+ const statusCode = message2.status_code;
128
+ const statusMessage = message2.get_reason_phrase();
129
+ if ((0, import_is_redirect.isRedirect)(statusCode)) {
130
+ const location = headers.get("Location");
131
+ let locationURL = null;
132
+ try {
133
+ locationURL = location === null ? null : new import_url.URL(location, request.url);
134
+ } catch {
135
+ if (request.redirect !== "manual") {
136
+ reject(new import_fetch_error.FetchError(`uri requested responds with an invalid redirect URL: ${location}`, "invalid-redirect"));
137
+ finalize();
138
+ return;
139
+ }
140
+ }
141
+ switch (request.redirect) {
142
+ case "error":
143
+ reject(new import_fetch_error.FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, "no-redirect"));
144
+ finalize();
145
+ return;
146
+ case "manual":
147
+ break;
148
+ case "follow": {
149
+ if (locationURL === null) {
150
+ break;
151
+ }
152
+ if (request.counter >= request.follow) {
153
+ reject(new import_fetch_error.FetchError(`maximum redirect reached at: ${request.url}`, "max-redirect"));
154
+ finalize();
155
+ return;
156
+ }
157
+ const requestOptions = {
158
+ headers: new import_headers.default(request.headers),
159
+ follow: request.follow,
160
+ counter: request.counter + 1,
161
+ agent: request.agent,
162
+ compress: request.compress,
163
+ method: request.method,
164
+ body: (0, import_body.clone)(request),
165
+ signal: request.signal,
166
+ size: request.size,
167
+ referrer: request.referrer,
168
+ referrerPolicy: request.referrerPolicy
169
+ };
170
+ if (!(0, import_is.isDomainOrSubdomain)(request.url, locationURL) || !(0, import_is.isSameProtocol)(request.url, locationURL)) {
171
+ for (const name of ["authorization", "www-authenticate", "cookie", "cookie2"]) {
172
+ requestOptions.headers.delete(name);
173
+ }
174
+ }
175
+ if (statusCode !== 303 && request.body && init.body instanceof import_stream.default.Readable) {
176
+ reject(new import_fetch_error.FetchError("Cannot follow redirect with body being a readable stream", "unsupported-redirect"));
177
+ finalize();
178
+ return;
179
+ }
180
+ if (statusCode === 303 || (statusCode === 301 || statusCode === 302) && request.method === "POST") {
181
+ requestOptions.method = "GET";
182
+ requestOptions.body = void 0;
183
+ requestOptions.headers.delete("content-length");
184
+ }
185
+ const responseReferrerPolicy = (0, import_referrer.parseReferrerPolicyFromHeader)(headers);
186
+ if (responseReferrerPolicy) {
187
+ requestOptions.referrerPolicy = responseReferrerPolicy;
188
+ }
189
+ resolve(fetch(new import_request.default(locationURL, requestOptions)));
190
+ finalize();
191
+ return;
192
+ }
193
+ default:
194
+ return reject(new TypeError(`Redirect option '${request.redirect}' is not a valid value of RequestRedirect`));
195
+ }
196
+ }
197
+ let body = (0, import_stream.pipeline)(response_, new import_stream.PassThrough(), (error) => {
198
+ if (error) {
199
+ reject(error);
200
+ }
201
+ });
202
+ const responseOptions = {
203
+ url: request.url,
204
+ status: statusCode,
205
+ statusText: statusMessage,
206
+ headers,
207
+ size: request.size,
208
+ counter: request.counter,
209
+ highWaterMark: request.highWaterMark
210
+ };
211
+ const codings = headers.get("Content-Encoding");
212
+ if (!request.compress || request.method === "HEAD" || codings === null || statusCode === 204 || statusCode === 304) {
213
+ response = new import_response.default(body, responseOptions);
214
+ resolve(response);
215
+ return;
216
+ }
217
+ const zlibOptions = {
218
+ flush: import_zlib.default.Z_SYNC_FLUSH,
219
+ finishFlush: import_zlib.default.Z_SYNC_FLUSH
220
+ };
221
+ if (codings === "gzip" || codings === "x-gzip") {
222
+ body = (0, import_stream.pipeline)(body, import_zlib.default.createGunzip(zlibOptions), (error) => {
223
+ if (error) {
224
+ reject(error);
225
+ }
226
+ });
227
+ response = new import_response.default(body, responseOptions);
228
+ resolve(response);
229
+ return;
230
+ }
231
+ if (codings === "br") {
232
+ body = (0, import_stream.pipeline)(body, import_zlib.default.createBrotliDecompress(), (error) => {
233
+ if (error) {
234
+ reject(error);
235
+ }
236
+ });
237
+ response = new import_response.default(body, responseOptions);
238
+ resolve(response);
239
+ return;
240
+ }
241
+ response = new import_response.default(body, responseOptions);
242
+ resolve(response);
243
+ });
244
+ (0, import_body.writeToStream)(inputStream, request).catch(reject);
245
+ });
246
+ }
@@ -0,0 +1,306 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
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 request_exports = {};
29
+ __export(request_exports, {
30
+ Request: () => Request,
31
+ default: () => request_default,
32
+ getSoupRequestOptions: () => getSoupRequestOptions
33
+ });
34
+ module.exports = __toCommonJS(request_exports);
35
+ var import_gjs = require("@girs/gjs");
36
+ var import_gio_2 = require("@girs/gio-2.0");
37
+ var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
38
+ var import_soup_3 = __toESM(require("@girs/soup-3.0"), 1);
39
+ var import_gio_22 = __toESM(require("@girs/gio-2.0"), 1);
40
+ var SoupExt = __toESM(require("@gjsify/soup-3.0"), 1);
41
+ var import_url = require("@gjsify/deno-runtime/ext/url/00_url");
42
+ var import_headers = __toESM(require("./headers.js"), 1);
43
+ var import_body = __toESM(require("./body.js"), 1);
44
+ var import_is = require("./utils/is.js");
45
+ var import_referrer = require("./utils/referrer.js");
46
+ const INTERNALS = Symbol("Request internals");
47
+ const isRequest = (obj) => {
48
+ return typeof obj === "object" && typeof obj.url === "string";
49
+ };
50
+ class Request extends import_body.default {
51
+ /** Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching. */
52
+ cache;
53
+ /** Returns the credentials mode associated with request, which is a string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. */
54
+ credentials;
55
+ /** Returns the kind of resource requested by request, e.g., "document" or "script". */
56
+ destination;
57
+ /** Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header. */
58
+ get headers() {
59
+ return this[INTERNALS].headers;
60
+ }
61
+ /** Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI] */
62
+ integrity;
63
+ /** Returns a boolean indicating whether or not request can outlive the global in which it was created. */
64
+ keepalive;
65
+ /** Returns request's HTTP method, which is "GET" by default. */
66
+ get method() {
67
+ return this[INTERNALS].method;
68
+ }
69
+ /** Returns the mode associated with request, which is a string indicating whether the request will use CORS, or will be restricted to same-origin URLs. */
70
+ mode;
71
+ /** Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default. */
72
+ get redirect() {
73
+ return this[INTERNALS].redirect;
74
+ }
75
+ /**
76
+ * Returns the referrer of request.
77
+ * Its value can be a same-origin URL if explicitly set in init, the empty string to indicate no referrer, and "about:client" when defaulting to the global's default.
78
+ * This is used during fetching to determine the value of the `Referer` header of the request being made.
79
+ * @see https://fetch.spec.whatwg.org/#dom-request-referrer
80
+ **/
81
+ get referrer() {
82
+ if (this[INTERNALS].referrer === "no-referrer") {
83
+ return "";
84
+ }
85
+ if (this[INTERNALS].referrer === "client") {
86
+ return "about:client";
87
+ }
88
+ if (this[INTERNALS].referrer) {
89
+ return this[INTERNALS].referrer.toString();
90
+ }
91
+ return void 0;
92
+ }
93
+ /** Returns the referrer policy associated with request. This is used during fetching to compute the value of the request's referrer. */
94
+ get referrerPolicy() {
95
+ return this[INTERNALS].referrerPolicy;
96
+ }
97
+ set referrerPolicy(referrerPolicy) {
98
+ this[INTERNALS].referrerPolicy = (0, import_referrer.validateReferrerPolicy)(referrerPolicy);
99
+ }
100
+ /** Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler. */
101
+ get signal() {
102
+ return this[INTERNALS].signal;
103
+ }
104
+ /** Returns the URL of request as a string. */
105
+ get url() {
106
+ return this[INTERNALS].parsedURL.toString();
107
+ }
108
+ get _uri() {
109
+ return import_glib_2.default.Uri.parse(this.url, import_glib_2.default.UriFlags.NONE);
110
+ }
111
+ get _session() {
112
+ return this[INTERNALS].session;
113
+ }
114
+ get _message() {
115
+ return this[INTERNALS].message;
116
+ }
117
+ get _inputStream() {
118
+ return this[INTERNALS].inputStream;
119
+ }
120
+ get [Symbol.toStringTag]() {
121
+ return "Request";
122
+ }
123
+ [INTERNALS];
124
+ // Node-fetch-only options
125
+ follow;
126
+ compress = false;
127
+ counter = 0;
128
+ agent = "";
129
+ highWaterMark = 16384;
130
+ insecureHTTPParser = false;
131
+ constructor(input, init) {
132
+ let parsedURL;
133
+ let requestObj = {};
134
+ if (isRequest(input)) {
135
+ parsedURL = new import_url.URL(input.url);
136
+ requestObj = input;
137
+ } else {
138
+ parsedURL = new import_url.URL(input);
139
+ }
140
+ if (parsedURL.username !== "" || parsedURL.password !== "") {
141
+ throw new TypeError(`${parsedURL} is an url with embedded credentials.`);
142
+ }
143
+ let method = init.method || requestObj.method || "GET";
144
+ if (/^(delete|get|head|options|post|put)$/i.test(method)) {
145
+ method = method.toUpperCase();
146
+ }
147
+ if ((init.body != null || isRequest(input) && input.body !== null) && (method === "GET" || method === "HEAD")) {
148
+ throw new TypeError("Request with GET/HEAD method cannot have body");
149
+ }
150
+ const inputBody = init.body ? init.body : isRequest(input) && input.body !== null ? (0, import_body.clone)(input) : null;
151
+ super(inputBody, {
152
+ size: init.size || init.size || 0
153
+ });
154
+ const headers = new import_headers.default(init.headers || input.headers || {});
155
+ if (inputBody !== null && !headers.has("Content-Type")) {
156
+ const contentType = (0, import_body.extractContentType)(inputBody, this);
157
+ if (contentType) {
158
+ headers.set("Content-Type", contentType);
159
+ }
160
+ }
161
+ let signal = isRequest(input) ? input.signal : null;
162
+ if ("signal" in init) {
163
+ signal = init.signal;
164
+ }
165
+ if (signal != null && !(0, import_is.isAbortSignal)(signal)) {
166
+ throw new TypeError("Expected signal to be an instanceof AbortSignal or EventTarget");
167
+ }
168
+ let referrer = init.referrer == null ? input.referrer : init.referrer;
169
+ if (referrer === "") {
170
+ referrer = "no-referrer";
171
+ } else if (referrer) {
172
+ const parsedReferrer = new import_url.URL(referrer);
173
+ referrer = /^about:(\/\/)?client$/.test(parsedReferrer.toString()) ? "client" : parsedReferrer;
174
+ } else {
175
+ referrer = void 0;
176
+ }
177
+ const session = SoupExt.ExtSession.new();
178
+ const message = new import_soup_3.default.Message({
179
+ method,
180
+ uri: this._uri
181
+ });
182
+ this[INTERNALS] = {
183
+ method,
184
+ redirect: init.redirect || input.redirect || "follow",
185
+ headers,
186
+ parsedURL,
187
+ signal,
188
+ referrer,
189
+ referrerPolicy: "",
190
+ session,
191
+ message
192
+ };
193
+ this.follow = init.follow === void 0 ? input.follow === void 0 ? 20 : input.follow : init.follow;
194
+ this.compress = init.compress === void 0 ? input.compress === void 0 ? true : input.compress : init.compress;
195
+ this.counter = init.counter || input.counter || 0;
196
+ this.agent = init.agent || input.agent;
197
+ this.highWaterMark = init.highWaterMark || input.highWaterMark || 16384;
198
+ this.insecureHTTPParser = init.insecureHTTPParser || input.insecureHTTPParser || false;
199
+ this.referrerPolicy = init.referrerPolicy || input.referrerPolicy || "";
200
+ }
201
+ /**
202
+ * Custom send method using Soup, used in fetch to send the request
203
+ * @param options
204
+ * @returns
205
+ */
206
+ async _send(options) {
207
+ options.headers._appendToSoupMessage(this._message);
208
+ const cancellable = new import_gio_22.default.Cancellable();
209
+ this[INTERNALS].inputStream = await this._session.sendAsync(this._message, import_glib_2.default.PRIORITY_DEFAULT, cancellable);
210
+ this[INTERNALS].readable = this[INTERNALS].inputStream.toReadable({});
211
+ return {
212
+ inputStream: this[INTERNALS].inputStream,
213
+ readable: this[INTERNALS].readable,
214
+ cancellable
215
+ };
216
+ }
217
+ /**
218
+ * Clone this request
219
+ */
220
+ clone() {
221
+ return new Request(this);
222
+ }
223
+ async arrayBuffer() {
224
+ return super.arrayBuffer();
225
+ }
226
+ async blob() {
227
+ return super.blob();
228
+ }
229
+ async formData() {
230
+ return super.formData();
231
+ }
232
+ async json() {
233
+ return super.json();
234
+ }
235
+ async text() {
236
+ return super.text();
237
+ }
238
+ }
239
+ Object.defineProperties(Request.prototype, {
240
+ method: { enumerable: true },
241
+ url: { enumerable: true },
242
+ headers: { enumerable: true },
243
+ redirect: { enumerable: true },
244
+ clone: { enumerable: true },
245
+ signal: { enumerable: true },
246
+ referrer: { enumerable: true },
247
+ referrerPolicy: { enumerable: true }
248
+ });
249
+ var request_default = Request;
250
+ const getSoupRequestOptions = (request) => {
251
+ const { parsedURL } = request[INTERNALS];
252
+ const headers = new import_headers.default(request[INTERNALS].headers);
253
+ if (!headers.has("Accept")) {
254
+ headers.set("Accept", "*/*");
255
+ }
256
+ let contentLengthValue = null;
257
+ if (request.body === null && /^(post|put)$/i.test(request.method)) {
258
+ contentLengthValue = "0";
259
+ }
260
+ if (request.body !== null) {
261
+ const totalBytes = (0, import_body.getTotalBytes)(request);
262
+ if (typeof totalBytes === "number" && !Number.isNaN(totalBytes)) {
263
+ contentLengthValue = String(totalBytes);
264
+ }
265
+ }
266
+ if (contentLengthValue) {
267
+ headers.set("Content-Length", contentLengthValue);
268
+ }
269
+ if (request.referrerPolicy === "") {
270
+ request.referrerPolicy = import_referrer.DEFAULT_REFERRER_POLICY;
271
+ }
272
+ if (request.referrer && request.referrer !== "no-referrer") {
273
+ request[INTERNALS].referrer = (0, import_referrer.determineRequestsReferrer)(request);
274
+ } else {
275
+ request[INTERNALS].referrer = "no-referrer";
276
+ }
277
+ if (request[INTERNALS].referrer instanceof import_url.URL) {
278
+ headers.set("Referer", request.referrer);
279
+ }
280
+ if (!headers.has("User-Agent")) {
281
+ headers.set("User-Agent", "node-fetch");
282
+ }
283
+ if (request.compress && !headers.has("Accept-Encoding")) {
284
+ headers.set("Accept-Encoding", "gzip, deflate, br");
285
+ }
286
+ let { agent } = request;
287
+ if (typeof agent === "function") {
288
+ agent = agent(parsedURL);
289
+ }
290
+ if (!headers.has("Connection") && !agent) {
291
+ headers.set("Connection", "close");
292
+ }
293
+ const options = {
294
+ // Overwrite search to retain trailing ? (issue #776)
295
+ // path: parsedURL.pathname + search,
296
+ // The following options are not expressed in the URL
297
+ // method: request.method,
298
+ headers
299
+ // insecureHTTPParser: request.insecureHTTPParser,
300
+ // agent
301
+ };
302
+ return {
303
+ parsedURL,
304
+ options
305
+ };
306
+ };