Browse Source

[http] Include port in HTTP Host header as needed

According to section 14.23 of RFC2616, an HTTP Host header without
port implies the default port is used.  Thus, when fetching from
anywhere but port 80 for HTTP or 443 for HTTPS, the port ought to be
explicitly given in that header.  Otherwise, some servers might fail
to associate the request with the correct virtual host or generate
incorrect self-referencing URLs.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Malte Starostik 13 years ago
parent
commit
69b7d57265
1 changed files with 5 additions and 1 deletions
  1. 5
    1
      src/net/tcp/http.c

+ 5
- 1
src/net/tcp/http.c View File

662
 	if ( ( rc = xfer_printf ( &http->socket,
662
 	if ( ( rc = xfer_printf ( &http->socket,
663
 				  "%s %s%s HTTP/1.1\r\n"
663
 				  "%s %s%s HTTP/1.1\r\n"
664
 				  "User-Agent: iPXE/" VERSION "\r\n"
664
 				  "User-Agent: iPXE/" VERSION "\r\n"
665
-				  "Host: %s\r\n"
665
+				  "Host: %s%s%s\r\n"
666
 				  "%s%s%s%s%s%s%s"
666
 				  "%s%s%s%s%s%s%s"
667
 				  "\r\n",
667
 				  "\r\n",
668
 				  ( ( http->flags & HTTP_HEAD_ONLY ) ?
668
 				  ( ( http->flags & HTTP_HEAD_ONLY ) ?
669
 				    "HEAD" : "GET" ),
669
 				    "HEAD" : "GET" ),
670
 				  ( http->uri->path ? "" : "/" ),
670
 				  ( http->uri->path ? "" : "/" ),
671
 				  request, host,
671
 				  request, host,
672
+				  ( http->uri->port ?
673
+				    ":" : "" ),
674
+				  ( http->uri->port ?
675
+				    http->uri->port : "" ),
672
 				  ( ( http->flags & HTTP_KEEPALIVE ) ?
676
 				  ( ( http->flags & HTTP_KEEPALIVE ) ?
673
 				    "Connection: Keep-Alive\r\n" : "" ),
677
 				    "Connection: Keep-Alive\r\n" : "" ),
674
 				  ( partial ? "Range: bytes=" : "" ),
678
 				  ( partial ? "Range: bytes=" : "" ),

Loading…
Cancel
Save