Git Product home page Git Product logo

Comments (5)

josevalim avatar josevalim commented on July 24, 2024

How do we add multiple response headers? I believe it is merge_response_headers? Whatever API we have there we should mirror here.

from plug.

halostatue avatar halostatue commented on July 24, 2024

Plug.Conn.merge_resp_headers/2 has a similar issue to put_resp_header, as it collapses headers down to a single instance value:

conn
|> put_resp_header("test", "123")
|> merge_resp_headers([{"test", "456"}, {"test", "789"}])
|> Map.get(:resp_headers)

# => [{"cache-control", "max-age=0, private, must-revalidate"}, {"test", "789"}]

On the other hand, prepend_resp_headers/2 seems to do the trick, but does them in a different order than I would personally expect:

conn
|> put_resp_header("test", "123")
|> prepend_resp_headers([{"test", "456"}, {"test", "789"}])
|> Map.get(:resp_headers)

# => [
  {"test", "456"},
  {"test", "789"},
  {"cache-control", "max-age=0, private, must-revalidate"},
  {"test", "123"}
]

At the same time, my add_req_header/3 implementation does the same thing (for the order that would be expected, it would need to be headers ++ [{key, value}]β€”which would have performance issues.

from plug.

josevalim avatar josevalim commented on July 24, 2024

So we can have prepend_req_headers and merge_req_headers with the same semantics. I don't think we should introduce a new verb. :) PRs welcome!

from plug.

halostatue avatar halostatue commented on July 24, 2024

Working on it.

The implementation of prepend_resp_headers does this: %{conn | resp_headers: headers ++ resp_headers}. Would it be worthwhile adding append_resp_headers and append_req_headers that does the opposite?

from plug.

josevalim avatar josevalim commented on July 24, 2024

No plans for new verbs for now, unless it is strongly needed.

from plug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.