Browse Source

net: http: client: Add port number to HTTP Header

Add port number to HTTP Header.

Signed-off-by: NavinSankar Velliangiri <navin@linumiz.com>
pull/26159/head
NavinSankar Velliangiri 5 years ago committed by Carles Cufí
parent
commit
820bfb46bc
  1. 3
      include/net/http_client.h
  2. 26
      subsys/net/lib/http/http_client.c

3
include/net/http_client.h

@ -227,6 +227,9 @@ struct http_request { @@ -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

26
subsys/net/lib/http/http_client.c

@ -504,13 +504,27 @@ int http_client_req(int sock, struct http_request *req, @@ -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);

Loading…
Cancel
Save