erlyaws / yaws

Yaws webserver
https://erlyaws.github.io
BSD 3-Clause "New" or "Revised" License
1.29k stars 267 forks source link

yaws_api:reformat_header/1 doesn't always return [ Header1, Header2 .....] #348

Closed leoliu closed 6 years ago

leoliu commented 6 years ago

If a header has multiple values {multi, Values} the return value is no longer a simple [ Header1, Header2 .....] but a list that is a nightmare to join with \r\n before sending back to the client.

vinoski commented 6 years ago

Do you have an example?

leoliu commented 6 years ago

For example to send two Link headers to clisock:

Link: </main.css>; rel=preload; as=style
Link: </main.js>; rel=preload; as=script
test() ->
    H = yaws_api:set_header(#headers{}, "Link", {multi, ["</main.css>; rel=preload; as=style", "</main.js>; rel=preload; as=script"]}),
    yaws_api:reformat_header(H).
;; returns
[["Link: </main.css>; rel=preload; as=style",
  "Link: </main.js>; rel=preload; as=script"]]