Skip to content

Commit

Permalink
61605ec fix(http): ignore http2 headers (#6291)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickJS committed May 10, 2024
1 parent 50ec079 commit 24c9745
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 49 deletions.
40 changes: 28 additions & 12 deletions middleware/node/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,33 @@ function fallbackOrigin(req) {
function getUrl(req, origin) {
return normalizeUrl(req.originalUrl || req.url || "/", origin);
}
var DOUBLE_SLASH_REG = /\/\/|\\\\/g;
function isIgnoredError(message = "") {
const ignoredErrors = ["The stream has been destroyed", "write after end"];
return ignoredErrors.some((ignored) => message.includes(ignored));
}
var invalidHeadersPattern = /^:(method|scheme|authority|path)$/i;
function normalizeUrl(url, base) {
const DOUBLE_SLASH_REG = /\/\/|\\\\/g;
return new URL(url.replace(DOUBLE_SLASH_REG, "/"), base);
}
async function fromNodeHttp(url, req, res, mode, getClientConn) {
const requestHeaders = new Headers();
const nodeRequestHeaders = req.headers;
for (const key in nodeRequestHeaders) {
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);
try {
for (const [key, value] of Object.entries(nodeRequestHeaders)) {
if (invalidHeadersPattern.test(key)) {
continue;
}
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);
}
const getRequestBody = async function* () {
for await (const chunk of req) {
Expand Down Expand Up @@ -107,10 +114,19 @@ async function fromNodeHttp(url, req, res, mode, getClientConn) {
},
getWritableStream: (status, headers, cookies) => {
res.statusCode = status;
headers.forEach((value, key) => res.setHeader(key, value));
const cookieHeaders = cookies.headers();
if (cookieHeaders.length > 0) {
res.setHeader("Set-Cookie", cookieHeaders);
try {
for (const [key, value] of headers) {
if (invalidHeadersPattern.test(key)) {
continue;
}
res.setHeader(key, value);
}
const cookieHeaders = cookies.headers();
if (cookieHeaders.length > 0) {
res.setHeader("Set-Cookie", cookieHeaders);
}
} catch (err) {
console.error(err);
}
return new WritableStream({
write(chunk) {
Expand Down
40 changes: 28 additions & 12 deletions middleware/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,33 @@ function fallbackOrigin(req) {
function getUrl(req, origin) {
return normalizeUrl(req.originalUrl || req.url || "/", origin);
}
var DOUBLE_SLASH_REG = /\/\/|\\\\/g;
function isIgnoredError(message = "") {
const ignoredErrors = ["The stream has been destroyed", "write after end"];
return ignoredErrors.some((ignored) => message.includes(ignored));
}
var invalidHeadersPattern = /^:(method|scheme|authority|path)$/i;
function normalizeUrl(url, base) {
const DOUBLE_SLASH_REG = /\/\/|\\\\/g;
return new URL(url.replace(DOUBLE_SLASH_REG, "/"), base);
}
async function fromNodeHttp(url, req, res, mode, getClientConn) {
const requestHeaders = new Headers();
const nodeRequestHeaders = req.headers;
for (const key in nodeRequestHeaders) {
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);
try {
for (const [key, value] of Object.entries(nodeRequestHeaders)) {
if (invalidHeadersPattern.test(key)) {
continue;
}
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);
}
const getRequestBody = async function* () {
for await (const chunk of req) {
Expand Down Expand Up @@ -73,10 +80,19 @@ async function fromNodeHttp(url, req, res, mode, getClientConn) {
},
getWritableStream: (status, headers, cookies) => {
res.statusCode = status;
headers.forEach((value, key) => res.setHeader(key, value));
const cookieHeaders = cookies.headers();
if (cookieHeaders.length > 0) {
res.setHeader("Set-Cookie", cookieHeaders);
try {
for (const [key, value] of headers) {
if (invalidHeadersPattern.test(key)) {
continue;
}
res.setHeader(key, value);
}
const cookieHeaders = cookies.headers();
if (cookieHeaders.length > 0) {
res.setHeader("Set-Cookie", cookieHeaders);
}
} catch (err) {
console.error(err);
}
return new WritableStream({
write(chunk) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@builder.io/qwik-city",
"description": "The meta-framework for Qwik.",
"version": "1.5.4-dev20240510190535",
"version": "1.5.4-dev20240510212520",
"bugs": "https://github.com/QwikDev/qwik/issues",
"dependencies": {
"@mdx-js/mdx": "^3.0.1",
Expand Down
40 changes: 28 additions & 12 deletions vite/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25717,26 +25717,33 @@ function fallbackOrigin(req) {
function getUrl(req, origin) {
return normalizeUrl(req.originalUrl || req.url || "/", origin);
}
var DOUBLE_SLASH_REG = /\/\/|\\\\/g;
function isIgnoredError(message = "") {
const ignoredErrors = ["The stream has been destroyed", "write after end"];
return ignoredErrors.some((ignored) => message.includes(ignored));
}
var invalidHeadersPattern = /^:(method|scheme|authority|path)$/i;
function normalizeUrl(url, base) {
const DOUBLE_SLASH_REG = /\/\/|\\\\/g;
return new URL(url.replace(DOUBLE_SLASH_REG, "/"), base);
}
async function fromNodeHttp(url, req, res, mode, getClientConn) {
const requestHeaders = new Headers();
const nodeRequestHeaders = req.headers;
for (const key in nodeRequestHeaders) {
const value2 = nodeRequestHeaders[key];
if (typeof value2 === "string") {
requestHeaders.set(key, value2);
} else if (Array.isArray(value2)) {
for (const v of value2) {
requestHeaders.append(key, v);
try {
for (const [key, value2] of Object.entries(nodeRequestHeaders)) {
if (invalidHeadersPattern.test(key)) {
continue;
}
if (typeof value2 === "string") {
requestHeaders.set(key, value2);
} else if (Array.isArray(value2)) {
for (const v of value2) {
requestHeaders.append(key, v);
}
}
}
} catch (err) {
console.error(err);
}
const getRequestBody = async function* () {
for await (const chunk of req) {
Expand Down Expand Up @@ -25766,10 +25773,19 @@ async function fromNodeHttp(url, req, res, mode, getClientConn) {
},
getWritableStream: (status, headers, cookies) => {
res.statusCode = status;
headers.forEach((value2, key) => res.setHeader(key, value2));
const cookieHeaders = cookies.headers();
if (cookieHeaders.length > 0) {
res.setHeader("Set-Cookie", cookieHeaders);
try {
for (const [key, value2] of headers) {
if (invalidHeadersPattern.test(key)) {
continue;
}
res.setHeader(key, value2);
}
const cookieHeaders = cookies.headers();
if (cookieHeaders.length > 0) {
res.setHeader("Set-Cookie", cookieHeaders);
}
} catch (err) {
console.error(err);
}
return new WritableStream({
write(chunk) {
Expand Down
40 changes: 28 additions & 12 deletions vite/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25707,26 +25707,33 @@ function fallbackOrigin(req) {
function getUrl(req, origin) {
return normalizeUrl(req.originalUrl || req.url || "/", origin);
}
var DOUBLE_SLASH_REG = /\/\/|\\\\/g;
function isIgnoredError(message = "") {
const ignoredErrors = ["The stream has been destroyed", "write after end"];
return ignoredErrors.some((ignored) => message.includes(ignored));
}
var invalidHeadersPattern = /^:(method|scheme|authority|path)$/i;
function normalizeUrl(url, base) {
const DOUBLE_SLASH_REG = /\/\/|\\\\/g;
return new URL(url.replace(DOUBLE_SLASH_REG, "/"), base);
}
async function fromNodeHttp(url, req, res, mode, getClientConn) {
const requestHeaders = new Headers();
const nodeRequestHeaders = req.headers;
for (const key in nodeRequestHeaders) {
const value2 = nodeRequestHeaders[key];
if (typeof value2 === "string") {
requestHeaders.set(key, value2);
} else if (Array.isArray(value2)) {
for (const v of value2) {
requestHeaders.append(key, v);
try {
for (const [key, value2] of Object.entries(nodeRequestHeaders)) {
if (invalidHeadersPattern.test(key)) {
continue;
}
if (typeof value2 === "string") {
requestHeaders.set(key, value2);
} else if (Array.isArray(value2)) {
for (const v of value2) {
requestHeaders.append(key, v);
}
}
}
} catch (err) {
console.error(err);
}
const getRequestBody = async function* () {
for await (const chunk of req) {
Expand Down Expand Up @@ -25756,10 +25763,19 @@ async function fromNodeHttp(url, req, res, mode, getClientConn) {
},
getWritableStream: (status, headers, cookies) => {
res.statusCode = status;
headers.forEach((value2, key) => res.setHeader(key, value2));
const cookieHeaders = cookies.headers();
if (cookieHeaders.length > 0) {
res.setHeader("Set-Cookie", cookieHeaders);
try {
for (const [key, value2] of headers) {
if (invalidHeadersPattern.test(key)) {
continue;
}
res.setHeader(key, value2);
}
const cookieHeaders = cookies.headers();
if (cookieHeaders.length > 0) {
res.setHeader("Set-Cookie", cookieHeaders);
}
} catch (err) {
console.error(err);
}
return new WritableStream({
write(chunk) {
Expand Down

0 comments on commit 24c9745

Please sign in to comment.