Skip to content

Commit

Permalink
Issue #12 (Do not send Vary if Allowed-origin is *) had been reverted…
Browse files Browse the repository at this point in the history
… accidentally. This puts it back in place and also adds it for preflight requests.
  • Loading branch information
NickMRamirez committed Dec 12, 2020
1 parent 0a72144 commit 958f4d4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/cors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ function preflight_request_ver2(txn, origin, allowed_methods, allowed_origins, a
else
core.Debug("CORS: " .. origin .. " allowed")
reply:add_header("Access-Control-Allow-Origin", allowed_origin)

if allowed_origin ~= "*" then
reply:add_header("Vary", "Accept-Encoding,Origin")
end
end

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

-- Always vary on the Origin
txn.http:res_add_header("Vary", "Accept-Encoding,Origin")

-- Bail if client did not send an Origin
if origin == nil or origin == '' then
return
Expand All @@ -154,6 +155,10 @@ function cors_response(txn)

core.Debug("CORS: " .. origin .. " allowed")
txn.http:res_set_header("Access-Control-Allow-Origin", allowed_origin)

if allowed_origin ~= "*" then
txn.http:res_add_header("Vary", "Accept-Encoding,Origin")
end
end
end

Expand Down

0 comments on commit 958f4d4

Please sign in to comment.