Skip to content

Instantly share code, notes, and snippets.

@JohannesRudolph
Last active March 4, 2021 13:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohannesRudolph/5b6406e8607d26dc39907c13fc4af0cf to your computer and use it in GitHub Desktop.
Save JohannesRudolph/5b6406e8607d26dc39907c13fc4af0cf to your computer and use it in GitHub Desktop.
HAproxy Lua Script for answering CORS preflight requests (for OpenStack Swift)
core.register_service("cors-response", "http", function(applet)
applet:set_status(200)
applet:add_header("Content-Length", "0")
applet:add_header("Access-Control-Allow-Origin", applet.headers["origin"][0])
applet:add_header("Access-Control-Allow-Credentials", "true")
applet:add_header("Access-Control-Allow-Headers", "Origin, DNT, If-Match, If-Modified-Since, If-None-Match, If-Range, If-Unmodified-Since, X-Requested-With, Content-Type, X-Auth-Token, X-Service-Token, X-Newest, X-Trans-Id-Extra, X-Trans-Id, X-Account-Meta-Temp-URL-Key, X-Account-Meta-Temp-URL-Key-2, X-Timestamp, X-Openstack-Request-Id, X-Account-Bytes-Used, X-Account-Container-Count, X-Account-Object-Count, X-Account-Meta-Quota-Bytes, X-Account-Access-Control, X-Container-Meta-Temp-URL-Key, X-Container-Meta-Temp-URL-Key-2, X-Storage-Policy, X-Container-Object-Count, X-Container-Bytes-Used, X-Container-Meta-Quota-Count, X-Container-Meta-Quota-Bytes, X-Container-Read, X-Container-Write, X-Container-Sync-Key, X-Container-Sync-To, X-Versions-Location, X-History-Location, X-Container-Meta-Access-Control-Allow-Origin, X-Container-Meta-Access-Control-Max-Age, X-Container-Meta-Access-Control-Expose-Headers, X-Remove-Container-Read, X-Remove-Versions-Location, X-Remove-History-Location, X-Object-Manifest, X-Delete-At, X-Static-Large-Object, X-Detect-Content-Type, X-Copy-From, X-Copy-From-Account, X-Delete-After, X-Fresh-Metadata, X-Copied-From-Last-Modified, X-Copied-From, X-Copied-From-Account, X-Container-Meta-Web-Directory-Type")
applet:add_header("Access-Control-Expose-Headers", "Location, Www-Authenticate, ETag, Expires, Last-Modified, Cache-Control, Content-Type, X-Auth-Token, X-Service-Token, X-Newest, X-Trans-Id-Extra, X-Trans-Id, X-Account-Meta-Temp-URL-Key, X-Account-Meta-Temp-URL-Key-2, X-Timestamp, X-Openstack-Request-Id, X-Account-Bytes-Used, X-Account-Container-Count, X-Account-Object-Count, X-Account-Meta-Quota-Bytes, X-Account-Access-Control, X-Container-Meta-Temp-URL-Key, X-Container-Meta-Temp-URL-Key-2, X-Storage-Policy, X-Container-Object-Count, X-Container-Bytes-Used, X-Container-Meta-Quota-Count, X-Container-Meta-Quota-Bytes, X-Container-Read, X-Container-Write, X-Container-Sync-Key, X-Container-Sync-To, X-Versions-Location, X-History-Location, X-Container-Meta-Access-Control-Allow-Origin, X-Container-Meta-Access-Control-Max-Age, X-Container-Meta-Access-Control-Expose-Headers, X-Remove-Container-Read, X-Remove-Versions-Location, X-Remove-History-Location, X-Object-Manifest, X-Delete-At, X-Static-Large-Object, X-Detect-Content-Type, X-Copy-From, X-Copy-From-Account, X-Delete-After, X-Fresh-Metadata, X-Copied-From-Last-Modified, X-Copied-From, X-Copied-From-Account, X-Container-Meta-Web-Directory-Type")
applet:add_header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, HEAD")
applet:add_header("Access-Control-Max-Age", "31536000")
applet:start_response()
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment