async-http-client
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?]
With curl's --resolve
option, it should supports IP based SNI.
Ref https://curl.haxx.se/docs/manpage.html#--resolve
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.
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.
Thanks!
@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 I like it becomes a feature request, but I'm not capable for the implementation for now.
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 :)
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 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
this would be extremely useful for us also
@dellgreen would you be up to taking a stab at the implementation?