vapor / http

🚀 Non-blocking, event-driven HTTP built on Swift NIO.
MIT License
240 stars 65 forks source link

Stop overriding Host and User-Agent headers #365

Closed OnlyForF1 closed 5 years ago

OnlyForF1 commented 5 years ago

Vapor's HTTPClient implementation would previously always override the Host and User-Agent headers when sending a request to the server. At best this was undesired behaviour, at worst it would result in HTTP 400 Bad Request responses.

Now, default values will only be provided if Host or User-Agent headers were not already set.

0xTim commented 5 years ago

Nice! Could you add some tests?

tanner0101 commented 5 years ago

We use https://github.com/swift-server/swift-nio-http-client now on master. I'm not sure if that package has the same problem, but it's worth checking.

This repo will likely be deprecated soon.

OnlyForF1 commented 5 years ago

@tanner0101 I am aware of this and I'll fix it there too. For now I am using Vapor 3 so I prioritised fixing that. On first glance it looks like that repo is not affected, I might write some unit tests to ensure there are no regressions in the future. (The behaviour in this repo was a regression)

@0xTim I've added unit tests, I had to change the visibility of some sections from private to internal. Let me know what you think.

tanner0101 commented 5 years ago

@OnlyForF1 ah, sorry, I didn't see that this was merging into 3.

OnlyForF1 commented 5 years ago

I've refactored the tests to use httpbin, and reverted the visibility changes.

penny-coin commented 5 years ago

Hey @OnlyForF1, you just merged a pull request, have a coin!

You now have 1 coins.