IPv6 URLs are not parsed correctly
Hello there! I think I found one important issue you definitely need to fix + improve in source code of Nodepp. IPv6 URLs are not supported by client connection code and IPv6 addresses are not parsed inside URLs passed as parameters to fetch. Issue is easy to reproduce in simple client code like this:
string_t str_connect_host = "localhost"; // "[::1]"; // "::1"; // "localhost";
int n_connect_port = 8000;
string_t str_connect_url = std::format( "http://{}:{}", str_connect_host, n_connect_port );
// string_t str_connect_url = std::format( "http://[{}]:{}", str_connect_host, n_connect_port );
nodepp::agent_t agent;
agent.socket_family = AF_INET6;
nodepp::fetch_t args;
args.method = "GET";
args.url = str_connect_url
args.headers = nodepp::header_t( { ... ... ... ... ...
I can successfully use IPv6 with "localhost" DNS name like in code above. Unfortunately, I cannot use any IPv6 address inside URL. Even ::1 is not working.
Valid IPv6 URL must be http://[::1]:8000. It's parsed wrong inside Nodepp and host address inside url_t is [ single char.
Wrong variant http://::1:8000 also not working. But it should not. Because valid IPv6 URL must use [ ] square braces around IPv6 address.
Please notice: there are lot of various ways to detect string is IPv6 and this is just convenient to have. Examples discussed here.
Subject: IPv6 Support & URL Parsing Improvements in Nodepp
Hello Mr. Sergiy,
Thank you very much for your detailed feedback. You were absolutely right about using the [] notation for IPv6 detection. To be honest, I wasn't aware this was the standard approach, but I have integrated your suggestions, and the fix is now fully implemented in the Nodepp core. I must say, I love how clean the implementation turned out.
1. Native IPv6 URL Parsing
Nodepp now correctly handles square bracket notation ([::1], [localhost], [www.google.com]) within the url_t parser. It is now possible to make HTTP requests using IPv6 natively, without the need for manual agent configuration:
fetch_t args;
args.method = "GET";
args.url = "http://[www.google.com]/"; // <- [] IPv6
// args.url = "http://www.google.com/"; // <- [] IPv4
// args.url = "http://[localhost]:8000/"; // <- [] IPv6
args.headers = header_t({ { "Host", url::host(args.url) } });
2. Enhanced Intelligence in dns::lookup
I have extended this logic to the DNS layer. You can now hint the desired protocol directly through the hostname string:
auto list = dns::lookup( "www.google.com" ); // Detects IPv4 & IPv6 (Prioritizes IPv4)
auto list = dns::lookup( "[www.google.com]", AF_INET ); // IPv4 only
auto list = dns::lookup( "www.google.com" , AF_INET6 ); // IPv6 only
auto list = dns::lookup( "[www.google.com]" ); // IPv6 only via bracket hint
The same consistency applies to both clients and servers:
// WebSocket Client with IPv6
auto client = wss::client( "wss://[localhost]:8000/", &ssl );
// TCP/HTTP Server listening on IPv6
server.listen( "[localhost]", 8000, []( socket_t server ){
console::log("-> http://[::1]:8000");
});
3. agent_t Refinement & Auto-Detection
As you suggested, the AF_UNSPEC value now acts as a smart auto-detection trigger. The fetch engine will prioritize the protocol defined in the URL, while still allowing you to force a specific family manually if required:
fetch_t args;
args.method = "GET";
args.url = "http://[www.google.com]/"; // <- Detected as IPv6
args.headers = header_t({ { "Host", url::host(args.url) } });
agent_t agent;
agent.socket_family = AF_INET; // Forces IPv4 (Overrides [] in URL)
// agent.socket_family = AF_INET6; // Forces IPv6
// agent.socket_family = AF_UNSPEC; // Auto-detects via URL (Default behavior)
http::fetch( args, &agent );
Your idea of treating AF_UNSPEC as an auto-detection request was the key to making this integration feel truly Nodepp-style elegant and efficient. I am eager to hear your further thoughts and comments as you continue your work.
Best regards, Enmanuel D. Becerra C.
Mr Enmanuel, everything works like a charm now! Both client and server sides, both IP versions. Thanks.