You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/app/at_httpc.rst
+37-4Lines changed: 37 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -109,7 +109,7 @@ Unsolicited notification
109
109
* The ``<status_code>`` parameter is an integer.
110
110
It contains the HTTP status code returned by the server.
111
111
* The ``<content_length>`` parameter is an integer.
112
-
It contains the value of the ``Content-Length`` response header, or ``-1`` when no such header is present.
112
+
It contains the value of the ``Content-Length`` response header, or ``-1`` when the server uses chunked transfer encoding or does not provide a content length.
113
113
114
114
``#XHTTPCDATA`` is emitted in automatic mode for each received body chunk::
115
115
@@ -124,6 +124,12 @@ The notification line is terminated with ``\r\n`` and the raw body bytes follow
124
124
* The ``<length>`` parameter is an integer.
125
125
It contains the number of body bytes in this chunk.
126
126
127
+
.. note::
128
+
129
+
When the server uses ``Transfer-Encoding: chunked``, the body bytes delivered via ``#XHTTPCDATA`` include the raw chunked framing: each chunk is preceded by its size in hexadecimal followed by ``\r\n``, and followed by ``\r\n``.
130
+
The final zero-length chunk ``0\r\n\r\n`` is also forwarded. The host is responsible for stripping this framing to recover the original body content.
131
+
The ``<total_bytes>`` field in ``#XHTTPCSTAT`` reflects the raw wire byte count including chunked framing, not the decoded body length.
132
+
127
133
``#XHTTPCSTAT`` is emitted when the request completes, fails, or is cancelled::
128
134
129
135
#XHTTPCSTAT: <handle>,<status_code>,<total_bytes>
@@ -134,6 +140,7 @@ The notification line is terminated with ``\r\n`` and the raw body bytes follow
134
140
It contains the HTTP status code on success, or ``-1`` on failure, cancel, or timeout.
135
141
* The ``<total_bytes>`` parameter is an integer.
136
142
On successful completion, failure, or timeout, it contains the total number of response body bytes received by the HTTP client.
143
+
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).
137
144
On cancel (``status_code=-1`` from ``AT#XHTTPCCANCEL``), it contains the number of response body bytes already delivered to the host.
138
145
139
146
.. note::
@@ -235,6 +242,28 @@ HTTP HEAD (no body — ``#XHTTPCSTAT`` follows immediately after ``#XHTTPCHEAD``
235
242
236
243
#XHTTPCSTAT: 0,200,0
237
244
245
+
HTTP POST with chunked response (``content_length=-1``):
The 1132 raw bytes break down as chunked framing: ``460\r\n`` (chunk-size 1120 decimal in hex, 5 bytes), 1120 bytes of JSON body, ``\r\n`` (chunk trailer, 2 bytes), and ``0\r\n\r\n`` (final zero-length chunk, 5 bytes).
265
+
Strip this framing to recover the 1120-byte JSON body.
266
+
238
267
Test command
239
268
------------
240
269
@@ -313,9 +342,13 @@ When the socket buffer is temporarily empty (EAGAIN)::
313
342
It contains the number of body bytes delivered in this pull.
314
343
A value of ``0`` means the socket buffer is currently empty.
315
344
316
-
When all body bytes have been delivered, ``#XHTTPCSTAT`` is sent as a URC after
317
-
the final ``OK``. This happens either when the server closes the connection, or
318
-
when the ``Content-Length`` bytes have all been forwarded.
345
+
When all body bytes have been delivered, ``#XHTTPCSTAT`` is sent as a URC after the final ``OK``.
346
+
This happens either when the server closes the connection, when the ``Content-Length`` bytes have all been forwarded, or when the chunked transfer ``0\r\n\r\n`` terminator is received.
347
+
348
+
.. note::
349
+
350
+
When the server uses ``Transfer-Encoding: chunked`` (``content_length=-1`` in ``#XHTTPCHEAD``), the bytes returned by ``#XHTTPCDATA`` include raw chunked framing.
351
+
See the note under ``#XHTTPCDATA`` in the ``AT#XHTTPCREQ`` section.
0 commit comments