@whatwg-node/node-fetch 0.4.4-alpha-20230613135956-bb8c0b1 → 0.4.4-alpha-20230613143059-7231b86

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/Response.js CHANGED
@@ -60,7 +60,7 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
60
60
  });
61
61
  }
62
62
  static json(data, init) {
63
- const jsonStr = JSON.stringify(data);
63
+ let bodyInit = JSON.stringify(data);
64
64
  if (init != null) {
65
65
  if (init.headers != null) {
66
66
  init.headers = new Headers_js_1.PonyfillHeaders(init.headers);
@@ -68,17 +68,19 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
68
68
  init.headers.set('content-type', JSON_CONTENT_TYPE);
69
69
  }
70
70
  if (!init.headers.has('content-length')) {
71
- init.headers.set('content-length', Buffer.byteLength(jsonStr).toString());
71
+ bodyInit = Buffer.from(bodyInit);
72
+ init.headers.set('content-length', bodyInit.byteLength.toString());
72
73
  }
73
74
  }
74
75
  else {
76
+ bodyInit = Buffer.from(bodyInit);
75
77
  init.headers = [
76
78
  ['content-type', JSON_CONTENT_TYPE],
77
- ['content-length', Buffer.byteLength(jsonStr).toString()],
79
+ ['content-length', bodyInit.byteLength.toString()],
78
80
  ];
79
81
  }
80
82
  }
81
- return new PonyfillResponse(JSON.stringify(data), init);
83
+ return new PonyfillResponse(bodyInit, init);
82
84
  }
83
85
  }
84
86
  exports.PonyfillResponse = PonyfillResponse;
package/esm/Response.js CHANGED
@@ -57,7 +57,7 @@ export class PonyfillResponse extends PonyfillBody {
57
57
  });
58
58
  }
59
59
  static json(data, init) {
60
- const jsonStr = JSON.stringify(data);
60
+ let bodyInit = JSON.stringify(data);
61
61
  if (init != null) {
62
62
  if (init.headers != null) {
63
63
  init.headers = new PonyfillHeaders(init.headers);
@@ -65,16 +65,18 @@ export class PonyfillResponse extends PonyfillBody {
65
65
  init.headers.set('content-type', JSON_CONTENT_TYPE);
66
66
  }
67
67
  if (!init.headers.has('content-length')) {
68
- init.headers.set('content-length', Buffer.byteLength(jsonStr).toString());
68
+ bodyInit = Buffer.from(bodyInit);
69
+ init.headers.set('content-length', bodyInit.byteLength.toString());
69
70
  }
70
71
  }
71
72
  else {
73
+ bodyInit = Buffer.from(bodyInit);
72
74
  init.headers = [
73
75
  ['content-type', JSON_CONTENT_TYPE],
74
- ['content-length', Buffer.byteLength(jsonStr).toString()],
76
+ ['content-length', bodyInit.byteLength.toString()],
75
77
  ];
76
78
  }
77
79
  }
78
- return new PonyfillResponse(JSON.stringify(data), init);
80
+ return new PonyfillResponse(bodyInit, init);
79
81
  }
80
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.4.4-alpha-20230613135956-bb8c0b1",
3
+ "version": "0.4.4-alpha-20230613143059-7231b86",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {