diff --git a/include/net/http_client.h b/include/net/http_client.h index ed7850d23d0..7e29a415243 100644 --- a/include/net/http_client.h +++ b/include/net/http_client.h @@ -227,6 +227,9 @@ struct http_request { /** Hostname to be used in the request */ const char *host; + /** Port number to be used in the request */ + const char *port; + /** User supplied callback function to call when payload * needs to be sent. This can be NULL in which case the payload field * in http_request is used. The idea of this payload callback is to diff --git a/subsys/net/lib/http/http_client.c b/subsys/net/lib/http/http_client.c index 0a723505908..9db3478e7f3 100644 --- a/subsys/net/lib/http/http_client.c +++ b/subsys/net/lib/http/http_client.c @@ -504,13 +504,27 @@ int http_client_req(int sock, struct http_request *req, total_sent += ret; - ret = http_send_data(sock, send_buf, send_buf_max_len, &send_buf_pos, - "Host", ": ", req->host, HTTP_CRLF, NULL); - if (ret < 0) { - goto out; - } + if (req->port) { + ret = http_send_data(sock, send_buf, send_buf_max_len, + &send_buf_pos, "Host", ": ", req->host, + ":", req->port, HTTP_CRLF, NULL); - total_sent += ret; + if (ret < 0) { + goto out; + } + + total_sent += ret; + } else { + ret = http_send_data(sock, send_buf, send_buf_max_len, + &send_buf_pos, "Host", ": ", req->host, + HTTP_CRLF, NULL); + + if (ret < 0) { + goto out; + } + + total_sent += ret; + } if (req->optional_headers_cb) { ret = http_flush_data(sock, send_buf, send_buf_pos);