Skip to content

Commit

Permalink
Skip passing port in Host header if standard port. (#1362)
Browse files Browse the repository at this point in the history
Some virtual hosts break if the port is added in the headers.
  • Loading branch information
karrots authored and marcelstoer committed Jun 15, 2016
1 parent 0d3e0bb commit 7ff8326
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions app/http/httpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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
Expand Down

0 comments on commit 7ff8326

Please sign in to comment.