2

I want to read the following response headers.

Response-Header:

...
set-cookie: somecookie=7ABFBB3446C856779B59A837DE3946F7DB; Path=/; Secure;
set-cookie: wantedcookie=12414ASDFAFADFW2342342; Path=/; Secure;
...

The variable $sent_http_set_cookie contains the first header

$sent_http_set_cookie = somecookie=7ABFBB3446C856779B59A837DE3946F7DB; Path=/; Secure;

--

How to read the second header in order to get the value of the wantedcookie?

The nginx configuration looks like this:

location /api {
  add_header X-Debug "${sent_http_set_cookie}";
}

1 Answer 1

1

I have the same problem with you. I solved it by using the following code

local headers = ngx.resp.get_headers()
ngx.log(ngx.ERR, " set-cookie type is ", type(headers['set-cookie']))
ngx.log(ngx.ERR, "cookie headers are", require("cjson").encode(headers["set-cookie"]))

if there are multiple headers with the same, then headers[name] is a table.

ps: the code block show be placed in header_filter phase.

Sign up to request clarification or add additional context in comments.

1 Comment

This is lua code as I see. Please state it in your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.