Skip to content

Commit 7ce8cbc

Browse files
committed
Add set cookie
1 parent 4ca984c commit 7ce8cbc

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The following HAProxy configuration snippet shows this process:
9393
# a protected backend
9494
backend be_protected
9595
# set required headers
96-
http-request set-header X-Forward-For %[src]
96+
http-request set-header X-Forwarded-For %[src]
9797
http-request set-header X-Forwarded-Proto %[ssl_fc,iif(https,http)]
9898
http-request set-header X-Forwarded-Host %[req.hdr(Host)]
9999
http-request set-header X-Forwarded-Uri %[capture.req.uri]

cmd/haproxy-auth-request/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
)
1616

1717
func main() {
18-
// logging
1918
// command line flags
2019
pflag.String("listen", "127.0.0.1:3000", "Listen address")
2120
pflag.String("url", "http://127.0.0.1:9091/api/authz/forward-auth", "URL to perform verification against")

examples/haproxy.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ backend be_protected
5454
mode http
5555

5656
# set required headers
57-
http-request set-header X-Forward-For %[src]
57+
http-request set-header X-Forwarded-For %[src]
5858
http-request set-header X-Forwarded-Proto %[ssl_fc,iif(https,http)]
5959
http-request set-header X-Forwarded-Host %[req.hdr(Host)]
6060
http-request set-header X-Forwarded-Uri %[capture.req.uri]

pkg/auth/auth.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ func (auth *AuthHandler) Handler(req *request.Request) {
114114
}
115115
}
116116

117+
// set cookie if present
118+
if cookies := res.Cookies(); len(cookies) == 1 {
119+
if v := cookies[0].String(); v != "" {
120+
req.Actions.SetVar(action.ScopeRequest, "response_cookie.name", cookies[0].Name)
121+
req.Actions.SetVar(action.ScopeRequest, "response_cookie.value", v)
122+
}
123+
}
124+
117125
logger.Info("message handled")
118126
return
119127
}

0 commit comments

Comments
 (0)