aesiniath / http-streams

Haskell HTTP client library for use with io-streams
https://hackage.haskell.org/package/http-streams
BSD 3-Clause "New" or "Revised" License
50 stars 48 forks source link

Duplicate headers not concatonated #14

Closed emmanueltouzery closed 11 years ago

emmanueltouzery commented 11 years ago

adds a (failing) test for properly parsing multi-line response headers

istathar commented 11 years ago

So interestingly this is not multi-line headers, this is "what do you do if the same header is repeated". Which we shall indeed need to handle (the accepted convention is to concatoante the values into a single one).

Thanks for the test case. I'll see about fixing it from here.

AfC

emmanueltouzery commented 11 years ago

I otherwise modified Types.hs to make it work like so:

addHeader :: HashMap (CI ByteString) ByteString -> (ByteString,ByteString) -> HashMap (CI ByteString) ByteString addHeader m (k,v) = insertWith mergeHeaders (mk k) v m

mergeHeaders :: ByteString -> ByteString -> ByteString mergeHeaders a b = S.concat [a, "\n", b]

However if done like that the values get concatenated in the reverse way, because of the foldl:

Parsing responses multiline response headers are properly parsed FAILED Invalid response headers expected: Just "line1\nline2" but got: Just "line2\nline1"

Because I see you are very performance conscious and I don't have much experience on performance, I'll let you finish this off, maybe this helps you (although I don't doubt you know your own code very well ;-) ).

istathar commented 11 years ago

This is merged to one of my branches locally. I'll close this then, and open an issue for the bug itself.