net: http: update status if no status text is provided

Call on_status if the Reason-Phrase is not provided.
This allows for the numeric status code to be set.
Also, ensure the numeric status code is always set
in on_status, not just if the specific callback is set.

Signed-off-by: Justin Morton <justin.morton@nordicsemi.no>
This commit is contained in:
Justin Morton 2021-05-13 11:00:09 -07:00 committed by Kumar Gala
commit e3517e5080
2 changed files with 27 additions and 2 deletions

View file

@ -169,6 +169,8 @@ static int on_status(struct http_parser *parser, const char *at, size_t length)
len = MIN(length, sizeof(req->internal.response.http_status) - 1);
memcpy(req->internal.response.http_status, at, len);
req->internal.response.http_status[len] = 0;
req->internal.response.http_status_code =
(uint16_t)parser->status_code;
NET_DBG("HTTP response status %d %s", parser->status_code,
log_strdup(req->internal.response.http_status));
@ -176,8 +178,6 @@ static int on_status(struct http_parser *parser, const char *at, size_t length)
if (req->internal.response.http_cb &&
req->internal.response.http_cb->on_status) {
req->internal.response.http_cb->on_status(parser, at, length);
req->internal.response.http_status_code =
(uint16_t)parser->status_code;
}
return 0;