async-http-client icon indicating copy to clipboard operation
async-http-client copied to clipboard

Connect to IP but send a user-specified hostname in the SNI field [was: Do we have feature like curl's `--resolve` option?]

Open nixzhu opened this issue 5 years ago • 10 comments

With curl's --resolve option, it should supports IP based SNI. Ref https://curl.haxx.se/docs/manpage.html#--resolve

nixzhu avatar Oct 10 '19 07:10 nixzhu

By "IP-based SNI" I assume what you mean is "I want to connect to a specific IP address but send a hostname in the SNI field". In which case: yes, we could plausibly support that use-case.

Lukasa avatar Oct 10 '19 08:10 Lukasa

However, I should stress that we don't support it today so far as I know. All the building blocks are there in NIO though.

Lukasa avatar Oct 10 '19 08:10 Lukasa

Thanks!

nixzhu avatar Oct 10 '19 08:10 nixzhu

@nixzhu sure you want to close this issue? We could keep at as a feature request for async-http-client. If you'd like to give it a shot you might even want to try writing a patch? We're here to help :)

weissi avatar Oct 10 '19 08:10 weissi

@weissi I like it becomes a feature request, but I'm not capable for the implementation for now.

nixzhu avatar Oct 10 '19 08:10 nixzhu

This shouldn't be too hard to implement. The line that needs changing is this one:

try NIOSSLClientHandler(context: context, serverHostname: key.host.isIPAddress ? nil : key.host),

in HTTPClient.swift. Currently, this does:

If key.host is a hostname, then use it, if it's an IP address, don't send any SNI hostname.

In the future, this should check if we have an SNI hostname override in our configuration, if yes: use the override, if no: do the old logic.

If you feel like giving the implementation a go and have any questions, please reach out :)

weissi avatar Feb 26 '20 16:02 weissi

I want to work on this issue.

if we have an SNI hostname override in our configuration,

So we should have SNI hostname attribute in HTTPClient.configuration or in tlsConfiguration ?

shekhar-rajak avatar Feb 27 '20 17:02 shekhar-rajak

@shekhar-rajak probably HTTPClient.configuration because one tlsConfiguration can be used for multiple clients. Possibly even on Request because I'd assume you don't want to override all SNI hostnames for all requests. I'd expect this to be a per-request thing

weissi avatar Feb 27 '20 17:02 weissi

this would be extremely useful for us also

dellgreen avatar Dec 16 '21 10:12 dellgreen

@dellgreen would you be up to taking a stab at the implementation?

weissi avatar Dec 16 '21 11:12 weissi