net: http: add numeric http status code to response struct

Add numeric http status code to the response struct to allow for
easier processing by the caller.   Textual status already exists.

Signed-off-by: Justin Morton <justin.morton@nordicsemi.no>
This commit is contained in:
Justin Morton 2021-04-13 14:00:12 -07:00 committed by Jukka Rissanen
commit 35f598ba93
2 changed files with 7 additions and 0 deletions

View file

@ -146,6 +146,11 @@ struct http_response {
*/ */
char http_status[HTTP_STATUS_STR_SIZE]; char http_status[HTTP_STATUS_STR_SIZE];
/** Numeric HTTP status code which corresponds to the
* textual description.
*/
uint16_t http_status_code;
uint8_t cl_present : 1; uint8_t cl_present : 1;
uint8_t body_found : 1; uint8_t body_found : 1;
uint8_t message_complete : 1; uint8_t message_complete : 1;

View file

@ -176,6 +176,8 @@ static int on_status(struct http_parser *parser, const char *at, size_t length)
if (req->internal.response.http_cb && if (req->internal.response.http_cb &&
req->internal.response.http_cb->on_status) { req->internal.response.http_cb->on_status) {
req->internal.response.http_cb->on_status(parser, at, length); req->internal.response.http_cb->on_status(parser, at, length);
req->internal.response.http_status_code =
(uint16_t)parser->status_code;
} }
return 0; return 0;