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 0cd6747 commit 0a72144
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 8 additions & 3 deletions example/haproxy/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
1 change: 0 additions & 1 deletion example/web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ app.get('/', function (req, res) {

// the API
app.get('/getdata', function(req, res) {
res.set("Access-Control-Allow-Origin", "blah.com") // this should be overwritten by HAProxy
res.send('Message from the server!')
})

Expand Down

0 comments on commit 0a72144

Please sign in to comment.