You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes#16: Added a third parameter to http-request lua cors that accepts a comma-delimited list of custom headers, which sets the Access-Control-Allow-Headers response header.
Copy file name to clipboardExpand all lines: README.md
+19-9Lines changed: 19 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,9 @@ Lua library for enabling CORS in HAProxy.
6
6
7
7
Cross-origin Request Sharing allows you to permit client-side code running within a different domain to call your services. This module extends HAProxy so that it can:
8
8
9
-
* set an *Access-Control-Allow-Methods* and *Access-Control-Max-Age* header in response to CORS preflight requests.
9
+
* set an *Access-Control-Allow-Methods* header in response to a preflight request
10
+
* set an *Access-Control-Allow-Headers* header in response to a preflight request
11
+
* set an *Access-Control-Max-Age* header in response to a preflight request
10
12
* set an *Access-Control-Allow-Origin* header to whitelist a domain. Note that this header should only ever return either a single domain or an asterisk (*). Otherwise, it would have been possible to hardcode all permitted domains without the need for Lua scripting.
11
13
12
14
This library checks the incoming *Origin* header, which contains the calling code's domain, and tries to match it with the list of permitted domains. If there is a match, that domain is sent back in the *Access-Control-Allow-Origin* header.
@@ -31,22 +33,29 @@ global
31
33
lua-load /path/to/cors.lua
32
34
```
33
35
34
-
In your `frontend` or `listen` section, capture the client's *Origin* request header by adding `http-request lua.cors`The first parameter is a comma-delimited list of HTTP methods that can be used. The second parameter is comma-delimited list of origins that are permitted to call your service.
36
+
In your `frontend` or `listen` section, capture the client's *Origin* request header by adding `http-request lua.cors`Its parameters are:
* The first parameter is a comma-delimited list of HTTP methods that can be used. This is used to set the *Access-Control-Allow-Methods* header.
39
+
* The second parameter is comma-delimited list of origins that are permitted to call your service. This is used to set the *Access-Control-Allow-Origin* header.
40
+
* The third parameter is a comma-delimited list of custom headers that can be used. This is used to set the *Access-Control-Allow-Headers* header.
41
+
42
+
Each of these parameters can be set to an asterisk (*) to allow all values.
39
43
40
-
Within the same section, invoke the `http-response lua.cors` action to attach CORS headers to responses from backend servers.
44
+
Within the same `frontend` or `listen`section, add the `http-response lua.cors` action to attach CORS headers to responses from backend servers.
41
45
46
+
**Example 1: Allow specific methods, origins and headers**
0 commit comments