]> sjero.net Git - wget/commitdiff
[svn] Wrap numeric IPv6 addresses in square brackets when sending out HTTP
authorhniksic <devnull@localhost>
Sat, 26 Jan 2002 23:19:10 +0000 (15:19 -0800)
committerhniksic <devnull@localhost>
Sat, 26 Jan 2002 23:19:10 +0000 (15:19 -0800)
`Host' header.
Published in <sxs7kq4vgzf.fsf@florida.arsdigita.de>.

src/ChangeLog
src/http.c

index 1d882c50f5a8263500fda7878e5b7b71898c3ba9..3b2d48a28d1c0de5a5dfa961212202827d63dab6 100644 (file)
@@ -1,3 +1,8 @@
+2002-01-26  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * http.c (gethttp): Wrap host name in square brackets if it
+       contains a colon.
+
 2002-01-26  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * url.c (url_parse): Allow all hex digits, not only decimal ones,
index b615df965ff21d0e8acc296ef4a7af515c626db5..ed2d486b9b41b583f82f9a58a176d90a7e1d7a72 100644 (file)
@@ -559,6 +559,11 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
   /* Whether keep-alive should be inhibited. */
   int inhibit_keep_alive;
 
+  /* Whether we need to print the host header with braces around host,
+     e.g. "Host: [3ffe:8100:200:2::2]:1234" instead of the usual
+     "Host: symbolic-name:1234". */
+  int squares_around_host = 0;
+
 #ifdef HAVE_SSL
   /* initialize ssl_ctx on first run */
   if (!ssl_ctx)
@@ -811,6 +816,9 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
        "param=value", full_path will be "/foo/bar?param=value".  */
     full_path = url_full_path (u);
 
+  if (strchr (u->host, ':'))
+    squares_around_host = 1;
+
   /* Allocate the memory for the request.  */
   request = (char *)alloca (strlen (command)
                            + strlen (full_path)
@@ -832,11 +840,12 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
   sprintf (request, "\
 %s %s HTTP/1.0\r\n\
 User-Agent: %s\r\n\
-Host: %s%s\r\n\
+Host: %s%s%s%s\r\n\
 Accept: %s\r\n\
 %s%s%s%s%s%s%s%s\r\n",
           command, full_path,
-          useragent, u->host,
+          useragent,
+          squares_around_host ? "[" : "", u->host, squares_around_host ? "]" : "",
           port_maybe ? port_maybe : "",
           HTTP_ACCEPT,
           request_keep_alive ? request_keep_alive : "",