sandbox / mbed-http

Dependents:   MQTTGateway2 MQTTGatewayK64 http-example-wnc GuardRoom ... more

Files at this revision

API Documentation at this revision

Comitter:
Jan Jongboom
Date:
Thu Dec 14 16:19:22 2017 +0700
Parent:
20:0e63d6a93c02
Child:
22:71fc1b1894f8
Commit message:
Add port Host header if not 80/443

Changed in this revision

source/http_request_builder.h Show annotated file Show diff for this revision Revisions of this file
--- a/source/http_request_builder.h	Sat Nov 18 14:03:26 2017 +0100
+++ b/source/http_request_builder.h	Thu Dec 14 16:19:22 2017 +0700
@@ -28,7 +28,19 @@
     HttpRequestBuilder(http_method a_method, ParsedUrl* a_parsed_url)
         : method(a_method), parsed_url(a_parsed_url)
     {
-        set_header("Host", string(parsed_url->host()));
+        string host(parsed_url->host());
+
+        char port_str[10];
+        sprintf(port_str, ":%d", parsed_url->port());
+
+        if (strcmp(parsed_url->schema(), "http") == 0 && parsed_url->port() != 80) {
+            host += string(port_str);
+        }
+        else if (strcmp(parsed_url->schema(), "https") == 0 && parsed_url->port() != 443) {
+            host += string(port_str);
+        }
+
+        set_header("Host", host);
     }
 
     /**