@whatwg-node/node-fetch 0.4.4-alpha-20230613122807-eff9007 → 0.4.4-alpha-20230613124545-3a09f74
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/Headers.js +1 -4
- package/cjs/Response.js +19 -4
- package/esm/Headers.js +1 -4
- package/esm/Response.js +20 -5
- package/package.json +1 -1
- package/typings/Headers.d.cts +2 -2
- package/typings/Headers.d.ts +2 -2
package/cjs/Headers.js
CHANGED
@@ -7,14 +7,11 @@ function isHeadersLike(headers) {
|
|
7
7
|
exports.isHeadersLike = isHeadersLike;
|
8
8
|
class PonyfillHeaders {
|
9
9
|
constructor(headersInit) {
|
10
|
+
this.headersInit = headersInit;
|
10
11
|
this.map = new Map();
|
11
12
|
this.mapIsBuilt = false;
|
12
13
|
this.objectNormalizedKeysOfHeadersInit = [];
|
13
14
|
this.objectOriginalKeysOfHeadersInit = [];
|
14
|
-
if (isHeadersLike(headersInit)) {
|
15
|
-
return headersInit;
|
16
|
-
}
|
17
|
-
this.headersInit = headersInit;
|
18
15
|
}
|
19
16
|
// perf: we don't need to build `this.map` for Requests, as we can access the headers directly
|
20
17
|
_get(key) {
|
package/cjs/Response.js
CHANGED
@@ -4,6 +4,14 @@ exports.PonyfillResponse = void 0;
|
|
4
4
|
const http_1 = require("http");
|
5
5
|
const Body_js_1 = require("./Body.js");
|
6
6
|
const Headers_js_1 = require("./Headers.js");
|
7
|
+
const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
|
8
|
+
const DEFAULT_JSON_HEADERS_INIT = {
|
9
|
+
'content-type': JSON_CONTENT_TYPE,
|
10
|
+
};
|
11
|
+
const DEFAULT_JSON_HEADERS = new Headers_js_1.PonyfillHeaders(DEFAULT_JSON_HEADERS_INIT);
|
12
|
+
const DEFAULT_JSON_INIT = {
|
13
|
+
headers: DEFAULT_JSON_HEADERS_INIT,
|
14
|
+
};
|
7
15
|
class PonyfillResponse extends Body_js_1.PonyfillBody {
|
8
16
|
constructor(body, init) {
|
9
17
|
super(body || null, init);
|
@@ -14,7 +22,7 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
|
|
14
22
|
this.redirected = false;
|
15
23
|
this.type = 'default';
|
16
24
|
if (init) {
|
17
|
-
this.headers = new Headers_js_1.PonyfillHeaders(init.headers);
|
25
|
+
this.headers = (0, Headers_js_1.isHeadersLike)(init.headers) ? init.headers : new Headers_js_1.PonyfillHeaders(init.headers);
|
18
26
|
this.status = init.status || 200;
|
19
27
|
this.statusText = init.statusText || http_1.STATUS_CODES[this.status] || 'OK';
|
20
28
|
this.url = init.url || '';
|
@@ -63,9 +71,16 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
|
|
63
71
|
status,
|
64
72
|
});
|
65
73
|
}
|
66
|
-
static json(data, init =
|
67
|
-
init.headers
|
68
|
-
|
74
|
+
static json(data, init = DEFAULT_JSON_INIT) {
|
75
|
+
if (init.headers != null) {
|
76
|
+
init.headers = new Headers_js_1.PonyfillHeaders(init.headers);
|
77
|
+
if (!init.headers.has('content-type')) {
|
78
|
+
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
else {
|
82
|
+
init.headers = DEFAULT_JSON_HEADERS;
|
83
|
+
}
|
69
84
|
return new PonyfillResponse(JSON.stringify(data), init);
|
70
85
|
}
|
71
86
|
}
|
package/esm/Headers.js
CHANGED
@@ -3,14 +3,11 @@ export function isHeadersLike(headers) {
|
|
3
3
|
}
|
4
4
|
export class PonyfillHeaders {
|
5
5
|
constructor(headersInit) {
|
6
|
+
this.headersInit = headersInit;
|
6
7
|
this.map = new Map();
|
7
8
|
this.mapIsBuilt = false;
|
8
9
|
this.objectNormalizedKeysOfHeadersInit = [];
|
9
10
|
this.objectOriginalKeysOfHeadersInit = [];
|
10
|
-
if (isHeadersLike(headersInit)) {
|
11
|
-
return headersInit;
|
12
|
-
}
|
13
|
-
this.headersInit = headersInit;
|
14
11
|
}
|
15
12
|
// perf: we don't need to build `this.map` for Requests, as we can access the headers directly
|
16
13
|
_get(key) {
|
package/esm/Response.js
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
import { STATUS_CODES } from 'http';
|
2
2
|
import { PonyfillBody } from './Body.js';
|
3
|
-
import { PonyfillHeaders } from './Headers.js';
|
3
|
+
import { isHeadersLike, PonyfillHeaders } from './Headers.js';
|
4
|
+
const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
|
5
|
+
const DEFAULT_JSON_HEADERS_INIT = {
|
6
|
+
'content-type': JSON_CONTENT_TYPE,
|
7
|
+
};
|
8
|
+
const DEFAULT_JSON_HEADERS = new PonyfillHeaders(DEFAULT_JSON_HEADERS_INIT);
|
9
|
+
const DEFAULT_JSON_INIT = {
|
10
|
+
headers: DEFAULT_JSON_HEADERS_INIT,
|
11
|
+
};
|
4
12
|
export class PonyfillResponse extends PonyfillBody {
|
5
13
|
constructor(body, init) {
|
6
14
|
super(body || null, init);
|
@@ -11,7 +19,7 @@ export class PonyfillResponse extends PonyfillBody {
|
|
11
19
|
this.redirected = false;
|
12
20
|
this.type = 'default';
|
13
21
|
if (init) {
|
14
|
-
this.headers = new PonyfillHeaders(init.headers);
|
22
|
+
this.headers = isHeadersLike(init.headers) ? init.headers : new PonyfillHeaders(init.headers);
|
15
23
|
this.status = init.status || 200;
|
16
24
|
this.statusText = init.statusText || STATUS_CODES[this.status] || 'OK';
|
17
25
|
this.url = init.url || '';
|
@@ -60,9 +68,16 @@ export class PonyfillResponse extends PonyfillBody {
|
|
60
68
|
status,
|
61
69
|
});
|
62
70
|
}
|
63
|
-
static json(data, init =
|
64
|
-
init.headers
|
65
|
-
|
71
|
+
static json(data, init = DEFAULT_JSON_INIT) {
|
72
|
+
if (init.headers != null) {
|
73
|
+
init.headers = new PonyfillHeaders(init.headers);
|
74
|
+
if (!init.headers.has('content-type')) {
|
75
|
+
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
init.headers = DEFAULT_JSON_HEADERS;
|
80
|
+
}
|
66
81
|
return new PonyfillResponse(JSON.stringify(data), init);
|
67
82
|
}
|
68
83
|
}
|
package/package.json
CHANGED
package/typings/Headers.d.cts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
export type PonyfillHeadersInit = [string, string][] | Record<string, string | string[] | undefined> | Headers;
|
2
2
|
export declare function isHeadersLike(headers: any): headers is Headers;
|
3
3
|
export declare class PonyfillHeaders implements Headers {
|
4
|
+
private headersInit?;
|
4
5
|
private map;
|
5
6
|
private mapIsBuilt;
|
6
7
|
private objectNormalizedKeysOfHeadersInit;
|
7
8
|
private objectOriginalKeysOfHeadersInit;
|
8
|
-
|
9
|
-
constructor(headersInit?: PonyfillHeadersInit);
|
9
|
+
constructor(headersInit?: PonyfillHeadersInit | undefined);
|
10
10
|
private _get;
|
11
11
|
private getMap;
|
12
12
|
append(name: string, value: string): void;
|
package/typings/Headers.d.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
export type PonyfillHeadersInit = [string, string][] | Record<string, string | string[] | undefined> | Headers;
|
2
2
|
export declare function isHeadersLike(headers: any): headers is Headers;
|
3
3
|
export declare class PonyfillHeaders implements Headers {
|
4
|
+
private headersInit?;
|
4
5
|
private map;
|
5
6
|
private mapIsBuilt;
|
6
7
|
private objectNormalizedKeysOfHeadersInit;
|
7
8
|
private objectOriginalKeysOfHeadersInit;
|
8
|
-
|
9
|
-
constructor(headersInit?: PonyfillHeadersInit);
|
9
|
+
constructor(headersInit?: PonyfillHeadersInit | undefined);
|
10
10
|
private _get;
|
11
11
|
private getMap;
|
12
12
|
append(name: string, value: string): void;
|