mist icon indicating copy to clipboard operation
mist copied to clipboard

Set multiple cookies in one response

Open krystofrezac opened this issue 1 year ago • 1 comments
trafficstars

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

krystofrezac avatar Mar 11 '24 18:03 krystofrezac

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.

rawhat avatar Mar 14 '24 03:03 rawhat