rawhat / mist

gleam HTTP server. because it glistens on a web
Apache License 2.0
333 stars 12 forks source link

Set multiple cookies in one response #39

Closed krystofrezac closed 5 months ago

krystofrezac commented 8 months ago

Hi. I was struggling with setting multiple cookies in one response. I think the root cause is add_default_headers function from mist/internal/http module. In the process of converting list to to dict you lose the same keys (in my case set-cookie).

This updated version seems to work, but I am not sure if it doesn't have any other consequences

pub fn add_default_headers(
  resp: Response(BytesBuilder),
) -> Response(BytesBuilder) {
  let body_size = bytes_builder.byte_size(resp.body)

  let headers = [
    #("content-length", int.to_string(body_size)),
    #("connection", "keep-alive"),
    ..resp.headers
  ]

  Response(..resp, headers: headers)
}

version: 0.17.0

rawhat commented 8 months ago

I obviously had some misconceptions about valid headers, and honestly after reading the RFC... I'm not particularly more confident 😅

It seems like maybe there are some headers where it's valid to send multiple with the same name? But I can't really find information about which exactly those are... it does almost seem like most things just allow you to specify multiple.

I'm gonna try to do some more digging to find concrete answers, but at the very least only allowing one in all cases definitely seems wrong.

So thank you! I'll address this one way or the other.