@whatwg-node/node-fetch 0.5.0-alpha-20230531142055-c567621 → 0.5.0-alpha-20230531143520-481e7fa
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/cjs/Request.js +1 -1
- package/cjs/fetch.js +11 -13
- package/cjs/utils.js +12 -1
- package/esm/Request.js +2 -2
- package/esm/fetch.js +11 -13
- package/esm/utils.js +10 -0
- package/package.json +1 -1
- package/typings/Request.d.cts +1 -1
- package/typings/Request.d.ts +1 -1
- package/typings/utils.d.cts +1 -0
- package/typings/utils.d.ts +1 -0
package/cjs/Request.js
CHANGED
@@ -41,7 +41,7 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
41
41
|
this.referrer = requestInit?.referrer || 'about:client';
|
42
42
|
this.referrerPolicy = requestInit?.referrerPolicy || 'no-referrer';
|
43
43
|
this.signal = requestInit?.signal || new AbortController().signal;
|
44
|
-
this.headersSerializer = requestInit?.headersSerializer || utils_js_1.
|
44
|
+
this.headersSerializer = requestInit?.headersSerializer || utils_js_1.defaultHeadersSerializer;
|
45
45
|
this.url = url || '';
|
46
46
|
const contentTypeInHeaders = this.headers.get('content-type');
|
47
47
|
if (!contentTypeInHeaders) {
|
package/cjs/fetch.js
CHANGED
@@ -24,15 +24,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
24
24
|
};
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
26
|
exports.fetchPonyfill = void 0;
|
27
|
+
/* eslint-disable @typescript-eslint/no-this-alias */
|
27
28
|
const fs_1 = require("fs");
|
28
29
|
const stream_1 = require("stream");
|
29
30
|
const url_1 = require("url");
|
30
|
-
const node_libcurl_1 = require("node-libcurl");
|
31
31
|
const Blob_js_1 = require("./Blob.js");
|
32
32
|
const Headers_js_1 = require("./Headers.js");
|
33
33
|
const Request_js_1 = require("./Request.js");
|
34
34
|
const Response_js_1 = require("./Response.js");
|
35
35
|
const URL_js_1 = require("./URL.js");
|
36
|
+
const utils_js_1 = require("./utils.js");
|
36
37
|
function getResponseForFile(url) {
|
37
38
|
const path = (0, url_1.fileURLToPath)(url);
|
38
39
|
const readable = (0, fs_1.createReadStream)(path);
|
@@ -79,20 +80,12 @@ async function fetchPonyfill(info, init) {
|
|
79
80
|
? fetchRequest.body
|
80
81
|
: stream_1.Readable.from(fetchRequest.body)
|
81
82
|
: null);
|
82
|
-
const
|
83
|
+
const headersSerializer = fetchRequest.headersSerializer || utils_js_1.defaultHeadersSerializer;
|
83
84
|
let size;
|
84
|
-
fetchRequest.headers
|
85
|
-
|
86
|
-
if (key === 'content-length') {
|
87
|
-
size = Number(value);
|
88
|
-
}
|
85
|
+
const curlyHeaders = headersSerializer(fetchRequest.headers, value => {
|
86
|
+
size = Number(value);
|
89
87
|
});
|
90
88
|
let easyNativeBinding;
|
91
|
-
fetchRequest.signal.onabort = () => {
|
92
|
-
if (easyNativeBinding != null) {
|
93
|
-
easyNativeBinding.pause(node_libcurl_1.CurlPause.Recv);
|
94
|
-
}
|
95
|
-
};
|
96
89
|
const curlyOptions = {
|
97
90
|
// we want the unparsed binary response to be returned as a stream to us
|
98
91
|
curlyStreamResponse: true,
|
@@ -119,7 +112,12 @@ async function fetchPonyfill(info, init) {
|
|
119
112
|
if (size != null) {
|
120
113
|
curlyOptions.inFileSize = size;
|
121
114
|
}
|
122
|
-
const { curly, CurlCode } = await Promise.resolve().then(() => __importStar(require('node-libcurl')));
|
115
|
+
const { curly, CurlCode, CurlPause } = await Promise.resolve().then(() => __importStar(require('node-libcurl')));
|
116
|
+
fetchRequest.signal.onabort = () => {
|
117
|
+
if (easyNativeBinding != null) {
|
118
|
+
easyNativeBinding.pause(CurlPause.Recv);
|
119
|
+
}
|
120
|
+
};
|
123
121
|
const curlyResult = await curly(fetchRequest.url, curlyOptions);
|
124
122
|
const responseHeaders = new Headers_js_1.PonyfillHeaders();
|
125
123
|
curlyResult.headers.forEach(headerInfo => {
|
package/cjs/utils.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.uint8ArrayToArrayBuffer = exports.getHeadersObj = void 0;
|
3
|
+
exports.defaultHeadersSerializer = exports.uint8ArrayToArrayBuffer = exports.getHeadersObj = void 0;
|
4
4
|
function getHeadersObj(headers) {
|
5
5
|
if (headers == null || !('forEach' in headers)) {
|
6
6
|
return headers;
|
@@ -16,3 +16,14 @@ function uint8ArrayToArrayBuffer(uint8array) {
|
|
16
16
|
return uint8array.buffer.slice(uint8array.byteOffset, uint8array.byteOffset + uint8array.byteLength);
|
17
17
|
}
|
18
18
|
exports.uint8ArrayToArrayBuffer = uint8ArrayToArrayBuffer;
|
19
|
+
function defaultHeadersSerializer(headers, onContentLength) {
|
20
|
+
const headerArray = [];
|
21
|
+
headers.forEach((value, key) => {
|
22
|
+
if (onContentLength && key === 'content-length') {
|
23
|
+
onContentLength(value);
|
24
|
+
}
|
25
|
+
headerArray.push(`${key}: ${value}`);
|
26
|
+
});
|
27
|
+
return headerArray;
|
28
|
+
}
|
29
|
+
exports.defaultHeadersSerializer = defaultHeadersSerializer;
|
package/esm/Request.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { PonyfillBody } from './Body.js';
|
2
2
|
import { PonyfillHeaders } from './Headers.js';
|
3
|
-
import {
|
3
|
+
import { defaultHeadersSerializer } from './utils.js';
|
4
4
|
function isRequest(input) {
|
5
5
|
return input[Symbol.toStringTag] === 'Request';
|
6
6
|
}
|
@@ -38,7 +38,7 @@ export class PonyfillRequest extends PonyfillBody {
|
|
38
38
|
this.referrer = requestInit?.referrer || 'about:client';
|
39
39
|
this.referrerPolicy = requestInit?.referrerPolicy || 'no-referrer';
|
40
40
|
this.signal = requestInit?.signal || new AbortController().signal;
|
41
|
-
this.headersSerializer = requestInit?.headersSerializer ||
|
41
|
+
this.headersSerializer = requestInit?.headersSerializer || defaultHeadersSerializer;
|
42
42
|
this.url = url || '';
|
43
43
|
const contentTypeInHeaders = this.headers.get('content-type');
|
44
44
|
if (!contentTypeInHeaders) {
|
package/esm/fetch.js
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-this-alias */
|
1
2
|
import { createReadStream } from 'fs';
|
2
3
|
import { Readable } from 'stream';
|
3
4
|
import { fileURLToPath } from 'url';
|
4
|
-
import { CurlPause } from 'node-libcurl';
|
5
5
|
import { PonyfillBlob } from './Blob.js';
|
6
6
|
import { PonyfillHeaders } from './Headers.js';
|
7
7
|
import { PonyfillRequest } from './Request.js';
|
8
8
|
import { PonyfillResponse } from './Response.js';
|
9
9
|
import { PonyfillURL } from './URL.js';
|
10
|
+
import { defaultHeadersSerializer } from './utils.js';
|
10
11
|
function getResponseForFile(url) {
|
11
12
|
const path = fileURLToPath(url);
|
12
13
|
const readable = createReadStream(path);
|
@@ -53,20 +54,12 @@ export async function fetchPonyfill(info, init) {
|
|
53
54
|
? fetchRequest.body
|
54
55
|
: Readable.from(fetchRequest.body)
|
55
56
|
: null);
|
56
|
-
const
|
57
|
+
const headersSerializer = fetchRequest.headersSerializer || defaultHeadersSerializer;
|
57
58
|
let size;
|
58
|
-
fetchRequest.headers
|
59
|
-
|
60
|
-
if (key === 'content-length') {
|
61
|
-
size = Number(value);
|
62
|
-
}
|
59
|
+
const curlyHeaders = headersSerializer(fetchRequest.headers, value => {
|
60
|
+
size = Number(value);
|
63
61
|
});
|
64
62
|
let easyNativeBinding;
|
65
|
-
fetchRequest.signal.onabort = () => {
|
66
|
-
if (easyNativeBinding != null) {
|
67
|
-
easyNativeBinding.pause(CurlPause.Recv);
|
68
|
-
}
|
69
|
-
};
|
70
63
|
const curlyOptions = {
|
71
64
|
// we want the unparsed binary response to be returned as a stream to us
|
72
65
|
curlyStreamResponse: true,
|
@@ -93,7 +86,12 @@ export async function fetchPonyfill(info, init) {
|
|
93
86
|
if (size != null) {
|
94
87
|
curlyOptions.inFileSize = size;
|
95
88
|
}
|
96
|
-
const { curly, CurlCode } = await import('node-libcurl');
|
89
|
+
const { curly, CurlCode, CurlPause } = await import('node-libcurl');
|
90
|
+
fetchRequest.signal.onabort = () => {
|
91
|
+
if (easyNativeBinding != null) {
|
92
|
+
easyNativeBinding.pause(CurlPause.Recv);
|
93
|
+
}
|
94
|
+
};
|
97
95
|
const curlyResult = await curly(fetchRequest.url, curlyOptions);
|
98
96
|
const responseHeaders = new PonyfillHeaders();
|
99
97
|
curlyResult.headers.forEach(headerInfo => {
|
package/esm/utils.js
CHANGED
@@ -11,3 +11,13 @@ export function getHeadersObj(headers) {
|
|
11
11
|
export function uint8ArrayToArrayBuffer(uint8array) {
|
12
12
|
return uint8array.buffer.slice(uint8array.byteOffset, uint8array.byteOffset + uint8array.byteLength);
|
13
13
|
}
|
14
|
+
export function defaultHeadersSerializer(headers, onContentLength) {
|
15
|
+
const headerArray = [];
|
16
|
+
headers.forEach((value, key) => {
|
17
|
+
if (onContentLength && key === 'content-length') {
|
18
|
+
onContentLength(value);
|
19
|
+
}
|
20
|
+
headerArray.push(`${key}: ${value}`);
|
21
|
+
});
|
22
|
+
return headerArray;
|
23
|
+
}
|
package/package.json
CHANGED
package/typings/Request.d.cts
CHANGED
@@ -5,7 +5,7 @@ export type RequestPonyfillInit = PonyfillBodyOptions & Omit<RequestInit, 'body'
|
|
5
5
|
headers?: PonyfillHeadersInit;
|
6
6
|
headersSerializer?: HeadersSerializer;
|
7
7
|
};
|
8
|
-
type HeadersSerializer = (headers: Headers) =>
|
8
|
+
type HeadersSerializer = (headers: Headers, onContentLength?: (contentLength: string) => void) => string[];
|
9
9
|
export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> implements Request {
|
10
10
|
constructor(input: RequestInfo | URL, options?: RequestPonyfillInit);
|
11
11
|
headersSerializer: HeadersSerializer;
|
package/typings/Request.d.ts
CHANGED
@@ -5,7 +5,7 @@ export type RequestPonyfillInit = PonyfillBodyOptions & Omit<RequestInit, 'body'
|
|
5
5
|
headers?: PonyfillHeadersInit;
|
6
6
|
headersSerializer?: HeadersSerializer;
|
7
7
|
};
|
8
|
-
type HeadersSerializer = (headers: Headers) =>
|
8
|
+
type HeadersSerializer = (headers: Headers, onContentLength?: (contentLength: string) => void) => string[];
|
9
9
|
export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> implements Request {
|
10
10
|
constructor(input: RequestInfo | URL, options?: RequestPonyfillInit);
|
11
11
|
headersSerializer: HeadersSerializer;
|
package/typings/utils.d.cts
CHANGED
@@ -1,2 +1,3 @@
|
|
1
1
|
export declare function getHeadersObj(headers: Headers): Record<string, string>;
|
2
2
|
export declare function uint8ArrayToArrayBuffer(uint8array: Uint8Array): ArrayBuffer;
|
3
|
+
export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[];
|
package/typings/utils.d.ts
CHANGED
@@ -1,2 +1,3 @@
|
|
1
1
|
export declare function getHeadersObj(headers: Headers): Record<string, string>;
|
2
2
|
export declare function uint8ArrayToArrayBuffer(uint8array: Uint8Array): ArrayBuffer;
|
3
|
+
export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[];
|