socketry / protocol-http1

MIT License
6 stars 14 forks source link

Make host header configurable #8

Closed ninoseki closed 4 years ago

ninoseki commented 4 years ago

I know it's an edge case but sometimes I need to set host header manually for a debugging purpose.

The current implementation forces to use the default host header (= authority). So it is not possible to set the host header manually.

This PR will make possible to configure host header manually if it is given via headers.

ioquatix commented 4 years ago

Why can’t you just set the authority to whatever you want?

ninoseki commented 4 years ago

I'm using protocol-http1 through async-http. Then I cannot set the authority when using Async::HTTP::Internet. I know that I can use Async::HTTP::Client instead of Async::HTTP::Internet but I think it's good to manipulate the host header in Async::HTTP::Internet.

ioquatix commented 4 years ago

Can you explain your use case?

ninoseki commented 4 years ago

Sometimes I need to check an access control based on Virtual Host. (e.g. prohibiting a direct IP access, etc.) Then I have to manipulate the host header.

ioquatix commented 4 years ago

It should already be possible to do this by providing the hostname to the endpoint.

    endpoint = Async::HTTP::Endpoint.parse("http://theserver.com")
    authority = "my-hostname" # The hostname to use.
    client = Async::HTTP::Client.new(endpoint, endpoint.protocol, endpoint.scheme, authority)

That being said, I think we should use kwargs for this... because it's kind of a mess specifying them all as positional arguments when you only want to override one.

ioquatix commented 4 years ago

I know that I can use Async::HTTP::Client instead of Async::HTTP::Internet but I think it's good to manipulate the host header in Async::HTTP::Internet.

This is not a good use case. Async::HTTP::Internet is for most users and follows the principle of least surprise. If you want to specify a custom authority, it shouldn't be by the header. Authority is very special field, and it's treated differently in HTTP/1 and HTTP/2.

ninoseki commented 4 years ago

Noted, thank you for reviewing my PR.