From f2bb99d102a7e78bf60e6485d6fe81d0657d0f9b Mon Sep 17 00:00:00 2001 From: hniksic Date: Sat, 26 Jan 2002 15:19:10 -0800 Subject: [PATCH] [svn] Wrap numeric IPv6 addresses in square brackets when sending out HTTP `Host' header. Published in . --- src/ChangeLog | 5 +++++ src/http.c | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 1d882c50..3b2d48a2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2002-01-26 Hrvoje Niksic + + * http.c (gethttp): Wrap host name in square brackets if it + contains a colon. + 2002-01-26 Hrvoje Niksic * url.c (url_parse): Allow all hex digits, not only decimal ones, diff --git a/src/http.c b/src/http.c index b615df96..ed2d486b 100644 --- a/src/http.c +++ b/src/http.c @@ -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 : "",