erikdubbelboer / fasthttp

This fork has been deprecated!
MIT License
50 stars 12 forks source link

RequestHeader.Header() is unreliable #18

Closed illotum closed 6 years ago

illotum commented 6 years ago

I have a use case for dumping raw headers, exactly as they appear on the wire.

Seemingly appropriate h.Header() from the looks of it always returns a re-compiled slice.

There is a check in h.AppendBytes() (used by Header()) to return h.rawHeaders, but it apparently never fires, I could not simulate a case where h.rawHeadersParsed == false. Namely, it is always getting parsed before we access it in handlers because of "Content-Length" and "Expect" peeks.

(This also uncovered issue where if DisableHeaderNamesNormalizing server option is true, the synthesized headers have both capitalized default "User-Agent: fasthttp" and real "user-agent: string".)


This is all to say, I'm looking for suggestions about how I should better add this ability. An option to enable backup copy to be stored and new method to access it? Or have it hardcoded and let Header() be the one? Will you have any objections to this feature being added in general?

erikdubbelboer commented 6 years ago

I agree that header parsing and returning is a big mess. I'm not sure how to fix things without breaking backwards compatibility.

Seeing as rawHeaders is never changed, even if rawHeadersParsed == true I guess for your case it might work to add a RawHeaders() method that just returns this slice.