Skip to content

app: http: Handle "Connection: close" header in HTTP response#303

Merged
juhaylinen merged 2 commits into
nrfconnect:mainfrom
juhaylinen:http_client_close_header
May 19, 2026
Merged

app: http: Handle "Connection: close" header in HTTP response#303
juhaylinen merged 2 commits into
nrfconnect:mainfrom
juhaylinen:http_client_close_header

Conversation

@juhaylinen
Copy link
Copy Markdown
Contributor

@juhaylinen juhaylinen commented May 15, 2026

Add <connection_close> field to #XHTTPCSTAT URC to indicate when the server signals connection closure via the "Connection: close" header.

XHTTPCSTAT: ,<status_code>,,<connection_close>

When <connection_close> is set, the host must close and reopen the socket before sending the next request.

Split HTTP_STATE_RECEIVING_HEADERS and HTTP_STATE_RECEIVING_BODY to separate switch cases.

@github-actions
Copy link
Copy Markdown

You can find the documentation preview for this PR here.

Copy link
Copy Markdown
Contributor

@MarkusLassila MarkusLassila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Some comments.

Comment thread doc/app/at_httpc.rst
Comment thread app/src/sm_at_httpc.c Outdated
Comment thread app/src/sm_at_httpc.c Outdated
@juhaylinen juhaylinen requested a review from divipillai May 18, 2026 08:11
@juhaylinen juhaylinen force-pushed the http_client_close_header branch from 880d74d to a0722f1 Compare May 18, 2026 08:21
Comment thread doc/app/at_httpc.rst Outdated
For chunked transfer encoding this includes the raw framing bytes (chunk-size lines, ``\r\n`` separators, and the final ``0\r\n\r\n`` terminator).
On cancel (``status_code=-1`` from ``AT#XHTTPCCANCEL``), it contains the number of response body bytes already delivered to the host.
* The ``<connection_close>`` parameter is an integer.
It is ``1`` when the server included a ``Connection: close`` header in its response, indicating that the TCP connection will be closed after this response.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It is ``1`` when the server included a ``Connection: close`` header in its response, indicating that the TCP connection will be closed after this response.
It is ``1`` when the server includes a ``Connection: close`` header in its response, indicating that the TCP connection will be closed after this response.

Add <connection_close> field to #XHTTPCSTAT URC to indicate when
the server signals connection closure via the "Connection: close"
header.

XHTTPCSTAT: <handle>,<status_code>,<bytes>,<connection_close>

When <connection_close> is set, the host must close and reopen the
socket before sending the next request.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
@juhaylinen juhaylinen force-pushed the http_client_close_header branch from a0722f1 to 7f499d9 Compare May 18, 2026 11:16
Comment thread app/src/sm_at_httpc.c Outdated
HTTP_RECV_BUF_SIZE - req->recv_buf_len - 1,
NRF_MSG_DONTWAIT);
if (!(events & NRF_POLLIN)) {
break;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
break;
return;

Comment thread app/src/sm_at_httpc.c Outdated
http_send_data(req, req->recv_buf, req->recv_buf_len);
req->recv_buf_len = 0;
if (!(events & NRF_POLLIN)) {
break;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
break;
return;

Split HTTP_STATE_RECEIVING_HEADERS and HTTP_STATE_RECEIVING_BODY to
separate switch cases.

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
@juhaylinen juhaylinen force-pushed the http_client_close_header branch from 7f499d9 to baf8da8 Compare May 18, 2026 15:10
@juhaylinen juhaylinen merged commit 5bb7c81 into nrfconnect:main May 19, 2026
3 checks passed
@juhaylinen juhaylinen deleted the http_client_close_header branch May 19, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants