From f18674a32021a1f52d93667073ac4b86f74db15c Mon Sep 17 00:00:00 2001 From: Michael Scott Date: Thu, 10 Aug 2017 16:14:03 -0700 Subject: [PATCH] net: http: fix http client request "Host" header RFC-7230 "HTTP/1.1 Message Syntax and Routing" Section 5.4 describes the "Host" header formatting. If Zephyr user specifies a host string as a part of the HTTP client request structure, we end up sending an incorrect HTTP header due to a missing "Host :" text. Fix this by prepending "Host: " to the header data before the user supplied host string. Signed-off-by: Michael Scott --- subsys/net/lib/http/http_client.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subsys/net/lib/http/http_client.c b/subsys/net/lib/http/http_client.c index 1f2e80c2d6f..25f39e3bdf3 100644 --- a/subsys/net/lib/http/http_client.c +++ b/subsys/net/lib/http/http_client.c @@ -45,6 +45,7 @@ /* HTTP client defines */ #define HTTP_EOF "\r\n\r\n" +#define HTTP_HOST "Host: " #define HTTP_CONTENT_TYPE "Content-Type: " #define HTTP_CONT_LEN_SIZE 64 @@ -87,6 +88,11 @@ int http_request(struct http_client_ctx *ctx, } if (req->host) { + if (!net_pkt_append_all(pkt, strlen(HTTP_HOST), + (u8_t *)HTTP_HOST, timeout)) { + goto out; + } + if (!net_pkt_append_all(pkt, strlen(req->host), (u8_t *)req->host, timeout)) { goto out;