Skip to content

Commit 958f4d4

Browse files
committed
Issue #12 (Do not send Vary if Allowed-origin is *) had been reverted accidentally. This puts it back in place and also adds it for preflight requests.
1 parent 0a72144 commit 958f4d4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/cors.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ function preflight_request_ver2(txn, origin, allowed_methods, allowed_origins, a
8282
else
8383
core.Debug("CORS: " .. origin .. " allowed")
8484
reply:add_header("Access-Control-Allow-Origin", allowed_origin)
85+
86+
if allowed_origin ~= "*" then
87+
reply:add_header("Vary", "Accept-Encoding,Origin")
88+
end
8589
end
8690

8791
core.Debug("CORS: Returning reply to preflight request")
@@ -135,9 +139,6 @@ function cors_response(txn)
135139
local allowed_headers = transaction_data["allowed_headers"]
136140
local method = transaction_data["method"]
137141

138-
-- Always vary on the Origin
139-
txn.http:res_add_header("Vary", "Accept-Encoding,Origin")
140-
141142
-- Bail if client did not send an Origin
142143
if origin == nil or origin == '' then
143144
return
@@ -154,6 +155,10 @@ function cors_response(txn)
154155

155156
core.Debug("CORS: " .. origin .. " allowed")
156157
txn.http:res_set_header("Access-Control-Allow-Origin", allowed_origin)
158+
159+
if allowed_origin ~= "*" then
160+
txn.http:res_add_header("Vary", "Accept-Encoding,Origin")
161+
end
157162
end
158163
end
159164

0 commit comments

Comments
 (0)