From a038af7912121c1dbe8a6cb94b2a2de5087f6a8f Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Thu, 5 Aug 2021 13:05:55 +0200 Subject: [PATCH] http.h: Do not add port 80 to Host header --- http.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/http.h b/http.h index f6e001d..c51c1d6 100644 --- a/http.h +++ b/http.h @@ -420,7 +420,8 @@ http_t* http_get( char const* url, void* memctx ) internal->request_header_large = (char*) HTTP_MALLOC( memctx, request_header_len + 1 ); request_header = internal->request_header_large; } - sprintf( request_header, "GET %s HTTP/1.0\r\nHost: %s:%s\r\n\r\n", resource, address, port ); + int default_http_port = (strcmp(port, "80") == 0); + sprintf( request_header, "GET %s HTTP/1.0\r\nHost: %s%s%s\r\n\r\n", resource, address, default_http_port ? "" : ":", default_http_port ? "" : port ); return &internal->http; } @@ -458,7 +459,8 @@ http_t* http_post( char const* url, void const* data, size_t size, void* memctx internal->request_header_large = (char*) HTTP_MALLOC( memctx, request_header_len + 1 ); request_header = internal->request_header_large; } - sprintf( request_header, "POST %s HTTP/1.0\r\nHost: %s:%s\r\nContent-Length: %d\r\n\r\n", resource, address, port, + int default_http_port = (strcmp(port, "80") == 0); + sprintf( request_header, "POST %s HTTP/1.0\r\nHost: %s%s%s\r\nContent-Length: %d\r\n\r\n", resource, address, default_http_port ? "" : ":", default_http_port ? "" : port, (int) size ); internal->request_data_size = size;