Skip to content

Commit

Permalink
net: lib: http_server: Place HTTP parser init to separate function
Browse files Browse the repository at this point in the history
Initialize HTTP parser during state transition so that we do it
only once / request and not for every packet received.

Signed-off-by: Jukka Rissanen <[email protected]>
  • Loading branch information
jukkar authored and rlubos committed Apr 17, 2024
1 parent ba1ecb5 commit 7f9f511
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions subsys/net/lib/http/http_server_http1.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ int enter_http1_request(struct http_client_ctx *client)
{
client->server_state = HTTP_SERVER_REQUEST_STATE;

http_parser_init(&client->parser, HTTP_REQUEST);
http_parser_settings_init(&client->parser_settings);

client->parser_settings.on_header_field = on_header_field;
client->parser_settings.on_url = on_url;

return 0;
}

Expand All @@ -324,11 +330,6 @@ int handle_http1_request(struct http_server_ctx *server, struct http_client_ctx

LOG_DBG("HTTP_SERVER_REQUEST");

http_parser_init(&client->parser, HTTP_REQUEST);
http_parser_settings_init(&client->parser_settings);

client->parser_settings.on_header_field = on_header_field;
client->parser_settings.on_url = on_url;

http_parser_execute(&client->parser, &client->parser_settings,
client->cursor, client->data_len);
Expand Down

0 comments on commit 7f9f511

Please sign in to comment.