소스 검색

[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 년 전
부모
커밋
69b7d57265
1개의 변경된 파일5개의 추가작업 그리고 1개의 파일을 삭제
  1. 5
    1
      src/net/tcp/http.c

+ 5
- 1
src/net/tcp/http.c 파일 보기

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

Loading…
취소
저장