Conversation
|
@j3su5cr1st, thank you for the pull request, but I don't understand the necessity of this change. Could you explain why we need to set a different hostname to SSL_set_tlsext_host_name rather than the hostname set in the constructor? Thanks! |
|
@yhirose Hi and thx for pretty library! Short answer: "A more generic solution for running several HTTPS servers on a single IP address is the TLS Server Name Indication (SNI) extension (RFC 6066), which allows a browser (actually any client) to pass a requested server name during the SSL handshake". |
|
@j3su5cr1st, thanks for the info. I'll explain my question more clearly. Suppose we host two domains (aaa.com, bbb.com) with a single IP 192.168.1.1 on a server. In order to send a request to aaa.com, I think we have to set "aaa.com" Only case we need Please let me know if I misunderstand something. Thanks! |
|
Yes, you understand the case clearly, but as I understand, this can spread not only on ip addresses. |
What does it mean by that? Are there any other specific examples? |
|
That means you can use not only IP addresses in |
|
does it work if you use the existing |
|
@PixlRainbow, Doesn't matter how many domain names you set via Check out this article: https://daniel.haxx.se/blog/2018/04/05/curl-another-host/. |
|
httplib already calls |
|
@j3su5cr1st, @PixlRainbow, thank you for valuable inputs. After I read the article that @j3su5cr1st recommended and the curl documentation, I am now thinking of supporting curl-like methods void resolve(const std::string &host, int port, const std::string &ip);
void connect_to(const std::string &host1, int port1, const std::string &host2, int port2);They look a bit redundant though, I think users can understand them easily because their behaviors are the same as the corresponding curl options. Also it's easier for me to document it on README. Anyway, please let me know your thoughts before I start working on it. Thanks! |
|
@yhirose IMO they looks like methods which do they things immediately, but not set the properties to future communication, i.e. So, let me know about you opinion about this PR, maybe you see any fixes and changes should make this functionality more clear and comfortable in httplib. |
|
what about a helper function (not class method) that resolves the IP address of an external hostname immediately? For example: std::string httplib::hosted_at(const char* hostname);Which you would then use with the existing // resolve external hostname "eggsamplers.com" to an IP address
// use the external IP address to connect to internal SNI host "example.com"
std::map<std::string, std::string> host_map = {
{ "example.com", httplib::hosted_at("eggsamplers.com") }
};
httplib::SSLClient cli("example.com");
cli.set_hostname_addr_map(host_map);
auto res = cli.Get("/");Using the map would also allow you to handle the case of automatic redirects between multiple different SNI zones. |
|
@PixlRainbow Looks like overengineering :) Btw, in your example, if |
|
Thanks for your feedback, I think your simpler interface is better. |
|
Okay, thanks for answer! |
|
@j3su5cr1st, @PixlRainbow, I am still trying to understand a whole picture of this issue, and thanks for your insightful comments. According to this information, they always set the host name in the given URL to the SNI, and the actual connection IP address can be changed with On the other hand, So if we add @j3su5cr1st , for better understanding, could you show me a few specific examples and how you can handle them with both the curl option ( Thanks for your help! |
|
Simplest example is, as I wrote before, two servers with TLS on the same port and address. In this case just setting We have:
The first thing that client's application does at startup is checking license, it would connect to license server This example is a bit synthetic but has the right to life and around close to real life case. |
|
@j3su5cr1st, (and @PixlRainbow) thanks for showing the above example. Since there is no specific code example, I just came up with 3 ways to handle your example as below. curl# Find a IP address for the host name
dig foo.com # or `nslookup foo.com`
# Use the '[IP]' as IP address to connect resolved with dig or nslookup, and use 'https://foo-license.com' as SNI
curl --resolve foo-license.com:443:[IP] https://foo-license.com/barhttplib::Client with
|
Thi feature can't be implemented for HTTP client, it's only for TSL connection.
Yes, whole cases above is right.
Don't think that here's a problem because if you use SNI you're perfectly understand what you do. I know no one cases when you are setting up SNI that differs from original host name and using not own (or not documented) backed. By the way, in you example with redirection the issue seems like currently exists too, isn't it? |
Lines 1157 to 1171 in 9fa426d
I feel your example isn't a common case to me. (Please let me know if I am wrong.)
Then we suppose all the requests to 'example_my_domain.com' redirect to 'example_other_service.com'. I think it's a pretty common situation, and it works with the following: As you can see, the current cpp-httplib implementation supports at least the above common situation even now. @PixlRainbow, do you have any thoughts? |
Got you, okay. |
|
yhirose means that |
|
Okay, @PixlRainbow @yhirose, can someone provide the vision of |
|
@j3su5cr1st, thanks for your efforts. But not only the issue with |
|
Okay, not problem. The main goal is functionality, but the interface defines the majority, thanks! |
|
@j3su5cr1st, but I really appreciate you raised this issue, and it made me understand SNI much better than before. I'll ponder over the actual interface more, then I'll get back here. Thanks a lot! |


No description provided.