@@ -381,6 +381,27 @@ describe("cookie module", function()
381381 assert .same (" foo=path; bar=path; bar=domain; bar=time; foo=time" , s :lookup (" sub.example.com" , " /path/longerpath" , true , true ))
382382 end )
383383 end )
384+ it (" can store cookies from a request+response" , function ()
385+ local s = http_cookie .new_store ()
386+ local req_headers = http_headers .new ()
387+ req_headers :append (" :scheme" , " http" )
388+ req_headers :append (" :method" , " GET" )
389+ req_headers :append (" :path" , " /" )
390+ local resp_headers = http_headers .new ()
391+ resp_headers :append (" :status" , " 200" )
392+ resp_headers :append (" set-cookie" , http_cookie .bake (" foo" , " FOO" ))
393+ resp_headers :append (" set-cookie" , http_cookie .bake (" bar" , " BAR" , 0 ))
394+ assert .truthy (s :store_from_request (req_headers , resp_headers , " my.host" , " my.host" ))
395+ assert .same (" FOO" , s :get (" my.host" , " /" , " foo" ))
396+ assert .same (nil , s :get (" my.host" , " /" , " bar" ))
397+ -- Now with an :authority header
398+ req_headers :append (" :authority" , " my.host" )
399+ resp_headers :append (" set-cookie" , http_cookie .bake (" baz" , " BAZ" ))
400+ assert .truthy (s :store_from_request (req_headers , resp_headers , " my.host" , " my.host" ))
401+ assert .same (" FOO" , s :get (" my.host" , " /" , " foo" ))
402+ assert .same (nil , s :get (" my.host" , " /" , " bar" ))
403+ assert .same (" BAZ" , s :get (" my.host" , " /" , " baz" ))
404+ end )
384405 it (" enforces store.max_cookie_length" , function ()
385406 local s = http_cookie .new_store ()
386407 s .max_cookie_length = 3
0 commit comments