@whatwg-node/node-fetch 0.5.20 → 0.5.21-alpha-20240805010752-0091eb73bd34a7b9e242a22352afacb8ac728cb7

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/Body.js CHANGED
@@ -49,6 +49,30 @@ class PonyfillBody {
49
49
  this._generatedBody = body;
50
50
  return body;
51
51
  }
52
+ handleContentLengthHeader(forceSet = false) {
53
+ const contentTypeInHeaders = this.headers.get('content-type');
54
+ if (!contentTypeInHeaders) {
55
+ if (this.contentType) {
56
+ this.headers.set('content-type', this.contentType);
57
+ }
58
+ }
59
+ else {
60
+ this.contentType = contentTypeInHeaders;
61
+ }
62
+ const contentLengthInHeaders = this.headers.get('content-length');
63
+ if (forceSet && this.bodyInit == null && !contentLengthInHeaders) {
64
+ this.contentLength = 0;
65
+ this.headers.set('content-length', '0');
66
+ }
67
+ if (!contentLengthInHeaders) {
68
+ if (this.contentLength) {
69
+ this.headers.set('content-length', this.contentLength.toString());
70
+ }
71
+ }
72
+ else {
73
+ this.contentLength = parseInt(contentLengthInHeaders, 10);
74
+ }
75
+ }
52
76
  get body() {
53
77
  const _body = this.generateBody();
54
78
  if (_body != null) {
package/cjs/Request.js CHANGED
@@ -52,28 +52,7 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
52
52
  this.destination = 'document';
53
53
  this.priority = 'auto';
54
54
  if (this.method !== 'GET' && this.method !== 'HEAD') {
55
- const contentTypeInHeaders = this.headers.get('content-type');
56
- if (!contentTypeInHeaders) {
57
- if (this.contentType) {
58
- this.headers.set('content-type', this.contentType);
59
- }
60
- }
61
- else {
62
- this.contentType = contentTypeInHeaders;
63
- }
64
- const contentLengthInHeaders = this.headers.get('content-length');
65
- if (bodyInit == null && !contentLengthInHeaders) {
66
- this.contentLength = 0;
67
- this.headers.set('content-length', '0');
68
- }
69
- if (!contentLengthInHeaders) {
70
- if (this.contentLength) {
71
- this.headers.set('content-length', this.contentLength.toString());
72
- }
73
- }
74
- else {
75
- this.contentLength = parseInt(contentLengthInHeaders, 10);
76
- }
55
+ this.handleContentLengthHeader(true);
77
56
  }
78
57
  if (requestInit?.agent != null) {
79
58
  if (requestInit.agent === false) {
package/cjs/Response.js CHANGED
@@ -18,24 +18,7 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
18
18
  this.url = init?.url || '';
19
19
  this.redirected = init?.redirected || false;
20
20
  this.type = init?.type || 'default';
21
- const contentTypeInHeaders = this.headers.get('content-type');
22
- if (!contentTypeInHeaders) {
23
- if (this.contentType) {
24
- this.headers.set('content-type', this.contentType);
25
- }
26
- }
27
- else {
28
- this.contentType = contentTypeInHeaders;
29
- }
30
- const contentLengthInHeaders = this.headers.get('content-length');
31
- if (!contentLengthInHeaders) {
32
- if (this.contentLength) {
33
- this.headers.set('content-length', this.contentLength.toString());
34
- }
35
- }
36
- else {
37
- this.contentLength = parseInt(contentLengthInHeaders, 10);
38
- }
21
+ this.handleContentLengthHeader();
39
22
  }
40
23
  get ok() {
41
24
  return this.status >= 200 && this.status < 300;
package/esm/Body.js CHANGED
@@ -45,6 +45,30 @@ export class PonyfillBody {
45
45
  this._generatedBody = body;
46
46
  return body;
47
47
  }
48
+ handleContentLengthHeader(forceSet = false) {
49
+ const contentTypeInHeaders = this.headers.get('content-type');
50
+ if (!contentTypeInHeaders) {
51
+ if (this.contentType) {
52
+ this.headers.set('content-type', this.contentType);
53
+ }
54
+ }
55
+ else {
56
+ this.contentType = contentTypeInHeaders;
57
+ }
58
+ const contentLengthInHeaders = this.headers.get('content-length');
59
+ if (forceSet && this.bodyInit == null && !contentLengthInHeaders) {
60
+ this.contentLength = 0;
61
+ this.headers.set('content-length', '0');
62
+ }
63
+ if (!contentLengthInHeaders) {
64
+ if (this.contentLength) {
65
+ this.headers.set('content-length', this.contentLength.toString());
66
+ }
67
+ }
68
+ else {
69
+ this.contentLength = parseInt(contentLengthInHeaders, 10);
70
+ }
71
+ }
48
72
  get body() {
49
73
  const _body = this.generateBody();
50
74
  if (_body != null) {
package/esm/Request.js CHANGED
@@ -49,28 +49,7 @@ export class PonyfillRequest extends PonyfillBody {
49
49
  this.destination = 'document';
50
50
  this.priority = 'auto';
51
51
  if (this.method !== 'GET' && this.method !== 'HEAD') {
52
- const contentTypeInHeaders = this.headers.get('content-type');
53
- if (!contentTypeInHeaders) {
54
- if (this.contentType) {
55
- this.headers.set('content-type', this.contentType);
56
- }
57
- }
58
- else {
59
- this.contentType = contentTypeInHeaders;
60
- }
61
- const contentLengthInHeaders = this.headers.get('content-length');
62
- if (bodyInit == null && !contentLengthInHeaders) {
63
- this.contentLength = 0;
64
- this.headers.set('content-length', '0');
65
- }
66
- if (!contentLengthInHeaders) {
67
- if (this.contentLength) {
68
- this.headers.set('content-length', this.contentLength.toString());
69
- }
70
- }
71
- else {
72
- this.contentLength = parseInt(contentLengthInHeaders, 10);
73
- }
52
+ this.handleContentLengthHeader(true);
74
53
  }
75
54
  if (requestInit?.agent != null) {
76
55
  if (requestInit.agent === false) {
package/esm/Response.js CHANGED
@@ -15,24 +15,7 @@ export class PonyfillResponse extends PonyfillBody {
15
15
  this.url = init?.url || '';
16
16
  this.redirected = init?.redirected || false;
17
17
  this.type = init?.type || 'default';
18
- const contentTypeInHeaders = this.headers.get('content-type');
19
- if (!contentTypeInHeaders) {
20
- if (this.contentType) {
21
- this.headers.set('content-type', this.contentType);
22
- }
23
- }
24
- else {
25
- this.contentType = contentTypeInHeaders;
26
- }
27
- const contentLengthInHeaders = this.headers.get('content-length');
28
- if (!contentLengthInHeaders) {
29
- if (this.contentLength) {
30
- this.headers.set('content-length', this.contentLength.toString());
31
- }
32
- }
33
- else {
34
- this.contentLength = parseInt(contentLengthInHeaders, 10);
35
- }
18
+ this.handleContentLengthHeader();
36
19
  }
37
20
  get ok() {
38
21
  return this.status >= 200 && this.status < 300;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.5.20",
3
+ "version": "0.5.21-alpha-20240805010752-0091eb73bd34a7b9e242a22352afacb8ac728cb7",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -27,6 +27,9 @@ export declare class PonyfillBody<TJSON = any> implements Body {
27
27
  private _generatedBody;
28
28
  private _buffer?;
29
29
  private generateBody;
30
+ protected handleContentLengthHeader(this: PonyfillBody & {
31
+ headers: Headers;
32
+ }, forceSet?: boolean): void;
30
33
  get body(): PonyfillReadableStream<Uint8Array> | null;
31
34
  _chunks: Uint8Array[] | null;
32
35
  _collectChunksFromReadable(): Promise<Uint8Array[]>;
package/typings/Body.d.ts CHANGED
@@ -27,6 +27,9 @@ export declare class PonyfillBody<TJSON = any> implements Body {
27
27
  private _generatedBody;
28
28
  private _buffer?;
29
29
  private generateBody;
30
+ protected handleContentLengthHeader(this: PonyfillBody & {
31
+ headers: Headers;
32
+ }, forceSet?: boolean): void;
30
33
  get body(): PonyfillReadableStream<Uint8Array> | null;
31
34
  _chunks: Uint8Array[] | null;
32
35
  _collectChunksFromReadable(): Promise<Uint8Array[]>;