Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ You can also whitelist all domains by setting the second parameter to an asteris

```
http-response lua.cors "GET,PUT,POST" "*"
```
```

To terminate OPTIONS request without sending it to the backend and return an empty response to the client add the following to the same section:

```
acl is_options method OPTIONS
http-request use-service lua.empty-response if is_options
```
13 changes: 12 additions & 1 deletion lib/cors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,15 @@ end

-- Register the actions with HAProxy
core.register_action("cors", {"http-req"}, cors_request, 0)
core.register_action("cors", {"http-res"}, cors_response, 2)
core.register_action("cors", {"http-res"}, cors_response, 2)

-- Returns an empty response to the client
function empty_response(applet)
applet:add_header("content-length", 0)
applet:set_status(204)
applet:start_response("")
applet:send(response)
end

-- Register the empty-response service with HAProxy
core.register_service("empty-response", "http", empty_response)