Skip to content

Commit 0a72144

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 0cd6747 commit 0a72144

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

example/haproxy/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

example/web/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ app.get('/', function (req, res) {
1515

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

0 commit comments

Comments
 (0)