Skip to content

Commit

Permalink
fix: incorrect header name for CORS preflight request (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisEGR authored Jul 26, 2021
1 parent 2e04fe1 commit 97049d2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions middleware/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function cors({
req,
);
if (isValidOrigin === false) return;
setAccessControlRequestMethods(methods, req);
setAccessControlRequestMethod(methods, req);
setAccessControlRequestHeaders(allowedHeaders, req);
setAcessControlExposeHeaders(exposedHeaders, req);

Expand Down Expand Up @@ -128,8 +128,8 @@ function setAccessControlAllowOrigin(
}
}

function setAccessControlRequestMethods(methods: string[], req: ServerRequest) {
const requestMethods = req.headers.get("access-control-request-methods");
function setAccessControlRequestMethod(methods: string[], req: ServerRequest) {
const requestMethods = req.headers.get("access-control-request-method");
if (requestMethods && methods.length > 0) {
const list = requestMethods.split(",").map((v) => v.trim());
const allowed = list.filter((v) => methods.includes(v));
Expand Down
4 changes: 2 additions & 2 deletions middleware/cors_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ group("cors", (t) => {
method: "OPTIONS",
headers: new Headers({
"origin": "https://servestjs.org",
"access-control-request-methods": "GET,HEAD,POST",
"access-control-request-method": "GET",
"access-control-request-headers": "x-servest-version",
}),
});
Expand All @@ -30,7 +30,7 @@ group("cors", (t) => {
);
assertEquals(
resp.headers.get("access-control-allow-methods"),
"GET, HEAD",
"GET",
);
assertEquals(
resp.headers.get("access-control-allow-headers"),
Expand Down

0 comments on commit 97049d2

Please sign in to comment.