]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
YaHTTP: Parse addresses with IPv6 literals
authorPieter Lexis <pieter.lexis@powerdns.com>
Wed, 12 Feb 2020 14:27:18 +0000 (15:27 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Wed, 12 Feb 2020 14:27:18 +0000 (15:27 +0100)
A URL like http://[::1]:81 are parsed correctly now.

ext/yahttp/yahttp/url.hpp

index 0002c29339bc0b3702366d8be2f38b6643f4559a..fbdd48de86509e5595c51a094189e422c27d5879 100644 (file)
@@ -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);