Skip to content

Commit

Permalink
Fixed #24: An exception nil value (local 'origin') is thrown when an …
Browse files Browse the repository at this point in the history
…OPTIONS request is sent that is not a CORS preflight request (which does not include an Options header).
  • Loading branch information
NickMRamirez committed Mar 21, 2021
1 parent f534376 commit acaa902
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions example/haproxy/cors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ function cors_request(txn, allowed_methods, allowed_origins, allowed_headers)
core.Debug("CORS: Got 'Origin' header: " .. headers["origin"][0])
origin = headers["origin"][0]
end

-- Bail if client did not send an Origin
-- for example, it may be a regular OPTIONS request that is not a CORS preflight request
if origin == nil or origin == '' then
return
end

transaction_data["origin"] = origin
transaction_data["allowed_methods"] = allowed_methods
Expand Down
6 changes: 6 additions & 0 deletions lib/cors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ function cors_request(txn, allowed_methods, allowed_origins, allowed_headers)
core.Debug("CORS: Got 'Origin' header: " .. headers["origin"][0])
origin = headers["origin"][0]
end

-- Bail if client did not send an Origin
-- for example, it may be a regular OPTIONS request that is not a CORS preflight request
if origin == nil or origin == '' then
return
end

transaction_data["origin"] = origin
transaction_data["allowed_methods"] = allowed_methods
Expand Down

0 comments on commit acaa902

Please sign in to comment.