Code Monkey home page Code Monkey logo

Comments (6)

sferik avatar sferik commented on August 14, 2024

I'd support a backwards-incompatible change that makes env[:response_headers] always return headers with array values. It's crazy how inconsistent (and wrong) the behavior is in some of the existing adapters.

from faraday.

mislav avatar mislav commented on August 14, 2024

Inconsistent—yes. But headers as strings are definitely more convenient to use. Imagine having to type env[:response_headers][:content_type].first or env[:response_headers][:location][0] all the time.

I'm tempted to implement something like Net::HTTP headers, where you have to use a special method to access multivalues as arrays.

Also, from the spec:

Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.

from faraday.

myronmarston avatar myronmarston commented on August 14, 2024

@mislav: Interesting. Thanks for quoting the spec. I need to read the RFCs more.

I guess the encoding issue I mentioned for using a comma-separated values is a non-issue.

I'm tempted to implement something like Net::HTTP headers, where you have to use a special method to access multivalues as arrays.

That might be worthwhile.

from faraday.

technoweenie avatar technoweenie commented on August 14, 2024

I definitely don't want every header value to be an array. I hated that shit from ASP 3.0 :)

for i=1 to Request.QueryString("n").Count
  Response.Write(Request.QueryString("n")(i)
next

from faraday.

mislav avatar mislav commented on August 14, 2024

Seems like we agreed to keep comma-separated values as String. Closing…

from faraday.

heisters avatar heisters commented on August 14, 2024

For what it's worth, this is an issue when multiple Set-Cookie headers are sent, since Set-Cookie contains a comma in the expires clause, eg.:

foo=bar; expires=Sat, 03-Nov-2012 16:37:48 GMT; path=/; domain=.example.com; HttpOnly

I thought I would solve this by subclassing the Faraday NetHttp adapter or inserting a middleware, but unfortunately the fact that joining by comma is baked into Utils::Headers makes all of that impossible. At the very least it would be nice if those of us that want an array of values had an easy and maintainable way of getting it.

This appears to be a known issue with the RFC and many client implementations, eg. Google AppEngine: http://code.google.com/p/googleappengine/issues/detail?id=3379

At this point, the only possible solution seems to be to manually parse the concatenated header using a regex that avoids splitting in the middle of the expires clause.

response.headers["set-cookie"].split(/, (?=[^;]+=[^;]+;)/)

from faraday.

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.