@whatwg-node/server 0.9.4 → 0.9.5

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.
@@ -75,32 +75,29 @@ async function sendResponseToUwsOpts({ res, response }) {
75
75
  res.onAborted(function () {
76
76
  resAborted = true;
77
77
  });
78
+ const isStringOrBuffer = response.bodyType === 'String' || response.bodyType === 'Uint8Array';
78
79
  res.cork(() => {
79
80
  res.writeStatus(`${response.status} ${response.statusText}`);
80
- });
81
- response.headers.forEach((value, key) => {
82
- // content-length causes an error with Node.js's fetch
83
- if (key !== 'content-length') {
84
- if (key === 'set-cookie') {
85
- const setCookies = response.headers.getSetCookie?.();
86
- if (setCookies) {
87
- setCookies.forEach(setCookie => {
88
- res.cork(() => {
81
+ for (const [key, value] of response.headers) {
82
+ // content-length causes an error with Node.js's fetch
83
+ if (key !== 'content-length') {
84
+ if (key === 'set-cookie') {
85
+ const setCookies = response.headers.getSetCookie?.();
86
+ if (setCookies) {
87
+ for (const setCookie of setCookies) {
89
88
  res.writeHeader(key, setCookie);
90
- });
91
- });
92
- return;
89
+ }
90
+ continue;
91
+ }
93
92
  }
94
- }
95
- res.cork(() => {
96
93
  res.writeHeader(key, value);
97
- });
94
+ }
98
95
  }
99
- });
100
- if (response.bodyType === 'String' || response.bodyType === 'Uint8Array') {
101
- res.cork(() => {
96
+ if (isStringOrBuffer) {
102
97
  res.end(response.bodyInit);
103
- });
98
+ }
99
+ });
100
+ if (isStringOrBuffer) {
104
101
  return;
105
102
  }
106
103
  if (!response.body) {
@@ -70,32 +70,29 @@ export async function sendResponseToUwsOpts({ res, response }) {
70
70
  res.onAborted(function () {
71
71
  resAborted = true;
72
72
  });
73
+ const isStringOrBuffer = response.bodyType === 'String' || response.bodyType === 'Uint8Array';
73
74
  res.cork(() => {
74
75
  res.writeStatus(`${response.status} ${response.statusText}`);
75
- });
76
- response.headers.forEach((value, key) => {
77
- // content-length causes an error with Node.js's fetch
78
- if (key !== 'content-length') {
79
- if (key === 'set-cookie') {
80
- const setCookies = response.headers.getSetCookie?.();
81
- if (setCookies) {
82
- setCookies.forEach(setCookie => {
83
- res.cork(() => {
76
+ for (const [key, value] of response.headers) {
77
+ // content-length causes an error with Node.js's fetch
78
+ if (key !== 'content-length') {
79
+ if (key === 'set-cookie') {
80
+ const setCookies = response.headers.getSetCookie?.();
81
+ if (setCookies) {
82
+ for (const setCookie of setCookies) {
84
83
  res.writeHeader(key, setCookie);
85
- });
86
- });
87
- return;
84
+ }
85
+ continue;
86
+ }
88
87
  }
89
- }
90
- res.cork(() => {
91
88
  res.writeHeader(key, value);
92
- });
89
+ }
93
90
  }
94
- });
95
- if (response.bodyType === 'String' || response.bodyType === 'Uint8Array') {
96
- res.cork(() => {
91
+ if (isStringOrBuffer) {
97
92
  res.end(response.bodyInit);
98
- });
93
+ }
94
+ });
95
+ if (isStringOrBuffer) {
99
96
  return;
100
97
  }
101
98
  if (!response.body) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/server",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "Fetch API compliant HTTP Server adapter",
5
5
  "sideEffects": false,
6
6
  "dependencies": {