Skip to content

Commit

Permalink
Update http.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickJS authored May 10, 2024
1 parent 3e21478 commit 73f441e
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions packages/qwik-city/middleware/node/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ export async function fromNodeHttp(
const requestHeaders = new Headers();
const nodeRequestHeaders = req.headers;

for (const key in nodeRequestHeaders) {
if (invalidHeadersPattern.test(key)) {
continue;
}
const value = nodeRequestHeaders[key];
try {
try {
for (const key in nodeRequestHeaders) {
if (invalidHeadersPattern.test(key)) {
continue;
}
const value = nodeRequestHeaders[key];
if (typeof value === 'string') {
requestHeaders.set(key, value);
} else if (Array.isArray(value)) {
for (const v of value) {
requestHeaders.append(key, v);
}
}
} catch (err) {
console.error(err);
}
} catch (err) {
console.error(err);
}

const getRequestBody = async function* () {
Expand Down Expand Up @@ -107,19 +107,23 @@ export async function fromNodeHttp(
},
getWritableStream: (status, headers, cookies) => {
res.statusCode = status;
headers.forEach((value, key) => {
try {
if (!invalidHeadersPattern.test(key)) {
res.setHeader(key, value);

try {
for (const key in headers) {
if (invalidHeadersPattern.test(key)) {
continue;
}
} catch (err) {
console.error(err);
const value = headers[key];

Check failure on line 116 in packages/qwik-city/middleware/node/http.ts

View workflow job for this annotation

GitHub Actions / Build Package

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Headers'.

Check failure on line 116 in packages/qwik-city/middleware/node/http.ts

View workflow job for this annotation

GitHub Actions / Unit Tests

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Headers'.
res.setHeader(key, value);
}
});
const cookieHeaders = cookies.headers();
if (cookieHeaders.length > 0) {
res.setHeader('Set-Cookie', cookieHeaders);
const cookieHeaders = cookies.headers();
if (cookieHeaders.length > 0) {
res.setHeader('Set-Cookie', cookieHeaders);
}
} catch (err) {
console.error(err);
}

return new WritableStream<Uint8Array>({
write(chunk) {
if (res.closed || res.destroyed) {
Expand Down

0 comments on commit 73f441e

Please sign in to comment.