]> sjero.net Git - wget/commitdiff
[svn] Explicitly document all cases when generating the Host header.
authorhniksic <devnull@localhost>
Thu, 30 Jun 2005 15:09:39 +0000 (08:09 -0700)
committerhniksic <devnull@localhost>
Thu, 30 Jun 2005 15:09:39 +0000 (08:09 -0700)
src/ChangeLog
src/http.c

index 95c48edcff4f3bfdb8dda0cfa7ec1503a12c5af2..3087c2441de8ad64ed5fb4bb12438118ec43f05d 100644 (file)
@@ -1,3 +1,8 @@
+2005-06-30  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * http.c (gethttp): Explicitly document the different cases when
+       generating the Host header.
+
 2005-06-30  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * host.c (pretty_print_address): Handle error result from
index a5f5673c5f0cb935ec4570d916cd8f938004fa19..4d1c16ebc917f72dbb3f94876f4abe98b9d2dbc4 100644 (file)
@@ -1308,20 +1308,25 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
        request_set_header (req, "Proxy-Authorization", proxyauth, rel_value);
     }
 
+  /* Generate the Host header, HOST:PORT.  Take into account that:
+
+     - Broken server-side software often doesn't recognize the PORT
+       argument, so we must generate "Host: www.server.com" instead of
+       "Host: www.server.com:80" (and likewise for https port).
+
+     - IPv6 addresses contain ":", so "Host: 3ffe:8100:200:2::2:1234"
+       becomes ambiguous and needs to be rewritten as "Host:
+       [3ffe:8100:200:2::2]:1234".  */
   {
-    /* 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". */
-    bool squares = strchr (u->host, ':') != NULL;
-    if (u->port == scheme_default_port (u->scheme))
-      request_set_header (req, "Host",
-                         aprintf (squares ? "[%s]" : "%s", u->host),
-                         rel_value);
-    else
-      request_set_header (req, "Host",
-                         aprintf (squares ? "[%s]:%d" : "%s:%d",
-                                  u->host, u->port),
-                         rel_value);
+    /* Formats arranged for hfmt[add_port][add_squares].  */
+    static const char *hfmt[][2] = {
+      { "%s", "[%s]" }, { "%s:%d", "[%s]:%d" }
+    };
+    int add_port = u->port != scheme_default_port (u->scheme);
+    int add_squares = strchr (u->host, ':') != NULL;
+    request_set_header (req, "Host",
+                       aprintf (hfmt[add_port][add_squares], u->host, u->port),
+                       rel_value);
   }
 
   if (!inhibit_keep_alive)