Skip to content

Commit 7cc3b16

Browse files
authored
Merge pull request #160 from nulib/cors-header-fix
CORS: Add ETag to exposed headers and HEAD to allowed methods
2 parents 29e5534 + 9c3e481 commit 7cc3b16

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/helpers.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,29 @@ const AcceptableHeaders = [
3737
"X-Forwarded-Port",
3838
"X-Requested-With",
3939
];
40+
41+
const ExposedHeaders = [
42+
"Cache-Control",
43+
"Content-Language",
44+
"Content-Length",
45+
"Content-Type",
46+
"Date",
47+
"ETag",
48+
"Expires",
49+
"Last-Modified",
50+
"Pragma",
51+
];
52+
4053
const TextTypes = new RegExp(/^(application\/(json|(.+\+)?xml)$|text\/)/);
4154

4255
function addCorsHeaders(event, response) {
4356
const allowOrigin = event?.headers?.origin || "*";
4457
const corsHeaders = {
4558
"Access-Control-Allow-Origin": allowOrigin,
4659
"Access-Control-Allow-Headers": AcceptableHeaders.join(", "),
47-
"Access-Control-Allow-Methods": "POST, GET, OPTIONS",
60+
"Access-Control-Allow-Methods": "POST, GET, HEAD, OPTIONS",
4861
"Access-Control-Allow-Credentials": "true",
62+
"Access-Control-Expose-Headers": ExposedHeaders.join(", "),
4963
"Access-Control-Max-Age": "600",
5064
};
5165
if (!response.headers) response.headers = {};

0 commit comments

Comments
 (0)