Fork of SandBox's original mbed-http (https://os.mbed.com/teams/sandbox/code/mbed-http/) and update for MbedOS6+ Content of TESTS folder was replaced with basic examples form original SandBox's HelloWorld
Diff: source/http_request_builder.h
- Revision:
- 21:fcd2bfd31a39
- Parent:
- 10:b017c7d2cf23
- Child:
- 23:15fa2726f793
diff -r 0e63d6a93c02 -r fcd2bfd31a39 source/http_request_builder.h --- 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); } /**