net: http_client: Add official null response behavior

Adds an official behavior in response to null response from HTTP
endpoint.

Fixes #42988

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
This commit is contained in:
Georges Oates_Larsen 2022-03-04 11:19:25 -08:00 committed by Maureen Helm
commit 303c42e70a
2 changed files with 25 additions and 5 deletions

View file

@ -124,15 +124,19 @@ struct http_response {
* did not set the response callback. If the callback * did not set the response callback. If the callback
* is set, then the HTTP client API will call response * is set, then the HTTP client API will call response
* callback many times so that all the data is * callback many times so that all the data is
* delivered to the user. * delivered to the user. Will be zero in the event of
* a null response.
*/ */
size_t data_len; size_t data_len;
/** HTTP Content-Length field value */ /** HTTP Content-Length field value. Will be set to zero
* in the event of a null response.
*/
size_t content_length; size_t content_length;
/** Content length parsed. This should be the same as /** Content length parsed. This should be the same as
* the content_length field if parsing was ok. * the content_length field if parsing was ok. Will be
* zero if a null response is given.
*/ */
size_t processed; size_t processed;
@ -143,11 +147,15 @@ struct http_response {
* purpose of providing a textual description * purpose of providing a textual description
* associated with the numeric status code. A client * associated with the numeric status code. A client
* SHOULD ignore the reason-phrase content. * SHOULD ignore the reason-phrase content.
*
* Will be blank if a null HTTP response is given.
*/ */
char http_status[HTTP_STATUS_STR_SIZE]; char http_status[HTTP_STATUS_STR_SIZE];
/** Numeric HTTP status code which corresponds to the /** Numeric HTTP status code which corresponds to the
* textual description. * textual description. Set to zero if null response is
* given. Otherwise, will be a 3-digit integer code if
* valid HTTP response is given.
*/ */
uint16_t http_status_code; uint16_t http_status_code;

View file

@ -396,7 +396,19 @@ static int http_wait_data(int sock, struct http_request *req)
ret = total_received; ret = total_received;
if (req->internal.response.cb) { if (req->internal.response.cb) {
NET_DBG("Calling callback for closed connection"); NET_DBG("Calling callback for closed connection "
"(NULL HTTP response)");
/* Status code 0 representing a null response */
req->internal.response.http_status_code = 0;
/* Zero out related response metrics */
req->internal.response.processed = 0;
req->internal.response.data_len = 0;
req->internal.response.content_length = 0;
req->internal.response.body_start = NULL;
memset(req->internal.response.http_status, 0,
HTTP_STATUS_STR_SIZE);
req->internal.response.cb(&req->internal.response, req->internal.response.cb(&req->internal.response,
HTTP_DATA_FINAL, HTTP_DATA_FINAL,