From 7ff8326cc9ed430abcc215be651ab6b8588dc57b Mon Sep 17 00:00:00 2001 From: Jonathan Karras Date: Wed, 15 Jun 2016 04:45:39 -0600 Subject: [PATCH] Skip passing port in Host header if standard port. (#1362) Some virtual hosts break if the port is added in the headers. --- app/http/httpclient.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/app/http/httpclient.c b/app/http/httpclient.c index b4c1a7ed..75d0e4a8 100644 --- a/app/http/httpclient.c +++ b/app/http/httpclient.c @@ -181,7 +181,7 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg ) HTTPCLIENT_DEBUG( "Connected\n" ); struct espconn * conn = (struct espconn *) arg; request_args_t * req = (request_args_t *) conn->reverse; - + int len; espconn_regist_recvcb( conn, http_receive_callback ); espconn_regist_sentcb( conn, http_send_callback ); @@ -200,16 +200,29 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg ) char buf[69 + strlen( req->method ) + strlen( req->path ) + strlen( req->hostname ) + strlen( req->headers ) + strlen( post_headers )]; - int len = os_sprintf( buf, - "%s %s HTTP/1.1\r\n" - "Host: %s:%d\r\n" - "Connection: close\r\n" - "User-Agent: ESP8266\r\n" - "%s" - "%s" - "\r\n", - req->method, req->path, req->hostname, req->port, req->headers, post_headers ); + if ((req->port == 80) || ((req->port == 443) && ( req->secure ))) + { + len = os_sprintf( buf, + "%s %s HTTP/1.1\r\n" + "Host: %s\r\n" + "Connection: close\r\n" + "User-Agent: ESP8266\r\n" + "%s" + "%s" + "\r\n", + req->method, req->path, req->hostname, req->headers, post_headers ); + } else { + len = os_sprintf( buf, + "%s %s HTTP/1.1\r\n" + "Host: %s:%d\r\n" + "Connection: close\r\n" + "User-Agent: ESP8266\r\n" + "%s" + "%s" + "\r\n", + req->method, req->path, req->hostname, req->port, req->headers, post_headers ); + } if ( req->secure ) espconn_secure_send( conn, (uint8_t *) buf, len ); else