From efcfeb3301589ff25c585580d046d8199d5c1511 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Wed, 12 Feb 2020 15:27:18 +0100 Subject: [PATCH] YaHTTP: Parse addresses with IPv6 literals A URL like http://[::1]:81 are parsed correctly now. --- ext/yahttp/yahttp/url.hpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ext/yahttp/yahttp/url.hpp b/ext/yahttp/yahttp/url.hpp index 0002c29339..fbdd48de86 100644 --- a/ext/yahttp/yahttp/url.hpp +++ b/ext/yahttp/yahttp/url.hpp @@ -38,7 +38,18 @@ namespace YaHTTP { host = url.substr(pos, pos1-pos); pos = pos1; } - if ( (pos1 = host.find_first_of(":")) != std::string::npos ) { + if (host.at(0) == '[') { // IPv6 + if ((pos1 = host.find_first_of("]")) == std::string::npos) { + // incomplete address + return false; + } + size_t pos2; + if ((pos2 = host.find_first_of(":", pos1)) != std::string::npos) { + std::istringstream tmp(host.substr(pos2 + 1)); + tmp >> port; + } + host = host.substr(1, pos1 - 1); + } else if ( (pos1 = host.find_first_of(":")) != std::string::npos ) { std::istringstream tmp(host.substr(pos1+1)); tmp >> port; host = host.substr(0, pos1); -- 2.47.2