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

Add port number to HTTP Header.

Signed-off-by: NavinSankar Velliangiri <navin@linumiz.com>
This commit is contained in:
NavinSankar Velliangiri 2020-06-15 16:19:22 +05:30 committed by Carles Cufí
commit 820bfb46bc
2 changed files with 23 additions and 6 deletions

View file

@ -227,6 +227,9 @@ struct http_request {
/** Hostname to be used in the request */ /** Hostname to be used in the request */
const char *host; const char *host;
/** Port number to be used in the request */
const char *port;
/** User supplied callback function to call when payload /** User supplied callback function to call when payload
* needs to be sent. This can be NULL in which case the payload field * 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 * in http_request is used. The idea of this payload callback is to

View file

@ -504,13 +504,27 @@ int http_client_req(int sock, struct http_request *req,
total_sent += ret; total_sent += ret;
ret = http_send_data(sock, send_buf, send_buf_max_len, &send_buf_pos, if (req->port) {
"Host", ": ", req->host, HTTP_CRLF, NULL); ret = http_send_data(sock, send_buf, send_buf_max_len,
&send_buf_pos, "Host", ": ", req->host,
":", req->port, HTTP_CRLF, NULL);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }
total_sent += ret; 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) { if (req->optional_headers_cb) {
ret = http_flush_data(sock, send_buf, send_buf_pos); ret = http_flush_data(sock, send_buf, send_buf_pos);