Skip to content

Instantly share code, notes, and snippets.

@pintsized
Created September 17, 2014 09:10
Show Gist options
  • Save pintsized/7b488c5c97eaa48feb33 to your computer and use it in GitHub Desktop.
Save pintsized/7b488c5c97eaa48feb33 to your computer and use it in GitHub Desktop.
proxy cookie
location /setcookie {
content_by_lua '
ngx.header.set_cookie = { "login=test%2Ftest", "cookie2" }
ngx.say("OK")
';
}
location /getcookie {
content_by_lua '
local resty_http = require "resty.http"
local httpc = resty_http.new()
local ok, err = httpc:connect("127.0.0.1", 80)
local res, err = httpc:request{
method = "POST",
headers = {
Host = "dev.local",
},
path = "/setcookie",
}
local body = res:read_body()
for k,v in pairs(res.headers) do
ngx.say(k, ": ", v)
end
ngx.say(body)
httpc:close()
';
}
$> curl -v -H "Host: dev.local" http://127.0.0.1/getcookie
Transfer-Encoding: chunked
Connection: keep-alive
Date: Wed, 17 Sep 2014 09:09:14 GMT
Content-Type: text/plain
set-cookie: login=test%2Ftest, cookie2
Server: openresty/1.5.8.1
OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment