1

I'm writing a Lua script for lighttpd (which run with mod_magnet). I want to set multiple cookie in my script but I don't know how should I do this.

I can set one cookie with this:

lighty.header['Set-Cookie'] = 'Foo=bar'

I've tried this for setting multiple cookie:

lighty.header['Set-Cookie'] = {'Foo=bar', 'bar=Foo'}

but it did not work

I also tried this but there is no success:

lighty.header['set-Cookie'] = {}

lighty.header['set-Cookie']['Foo'] = "bar"

lighty.header['set-Cookie']['bar'] = "Foo"
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Shahryar
  • 1,454
  • 2
  • 15
  • 32
  • Yes I did, but it did not work. it was deprecated in [rfc6265](http://tools.ietf.org/html/rfc6265) to set multiple cookie in this way. Each cookie must have separate "Set-Cookie" – Shahryar Sep 12 '13 at 11:24
  • It seems like you need multiple `Set-Cookie` fields but I am not sure how that would work with Lua tables. See http://stackoverflow.com/a/4843598/887805 – luastoned Sep 12 '13 at 11:32
  • `"Foo=bar;bar=Foo"` wouldn't work regardless; the spec says that multiple values are to be joined with commas. So `"Foo=bar,bar=Foo"`, while deprecated, might work as long as you don't use RFC 1126 expiration dates (which also contain commas). This isn't RFC 6265 compliant, but most browsers should support it (along with `asctime`-format expiration dates, which do not contain commas) - so it might make a usable stopgap if it turns out lighttpd doesn't support multiple set-cookie headers. – ToxicFrog Sep 12 '13 at 13:06
  • @ToxicFrog: I used `"Set-Cookie: Foo=bar,bar=Foo"` but it didn't work also! – Shahryar Sep 13 '13 at 10:32

2 Answers2

0

It looks like you're out of luck: https://github.com/lighttpd/lighttpd1.4/blob/master/src/mod_magnet.c#L711

mod_magnet treats the key and value as strings, and overwrites anything you previously had set for that header so you only get one header of for each key.

If you look here, you'll see that Set-Cookie headers must be one per line. However, the server should respond with a single Cookie header.

Ideally, mod_magnet would allow you to use a table for the header's value (such as in node.js). It doesn't look like it wouldn't be too difficult to implement this so maybe submit a bug report. Other than that, I don't think there's any workaround for setting multiple cookies.

r2jitu
  • 177
  • 1
  • 4
0

With lighttpd 1.4.60 and later the lighttpd mod_magnet documentation say:

To repeat header names, such as Set-Cookie or Link, join with "\r\nNAME:"
e.g. lighty.r.resp_header["Link"] = "http://a.com/a.css\r\nLink: http:/b.com/b.js"
gstrauss
  • 2,091
  • 1
  • 12
  • 16