http-parser.c

Small C library to parse HTTP requests
Log | Files | Refs | README | LICENSE

commit e3191cac06b18b182d6fdd0b5fe198f4ffa7d048
parent 09967fcb2f0d7f82f6a4d388746f178dff84fb3b
Author: finwo <finwo@pm.me>
Date:   Wed,  4 Nov 2020 20:01:41 +0100

Added automatic statusMessage for sprint_response

Diffstat:
M.github/FUNDING.yml | 4----
Msrc/http-parser.c | 12+++++++++++-
Msrc/http-parser.h | 2++
3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml @@ -1,6 +1,2 @@ # f4d2ed80-57b6-46e6-b245-5049428a931d -# These are supported funding model platforms -# src: https://github.com/finwo/funding/blob/master/.github/FUNDING.yml - github: finwo -patreon: finwo diff --git a/src/http-parser.c b/src/http-parser.c @@ -278,6 +278,16 @@ static int http_parser_message_read_chunked(struct http_parser_message *message) return 2; } +char * http_parser_status_message(int status) { + int i; + for(i=0; http_parser_statuses[i].status; i++) { + if (http_parser_statuses[i].status == status) { + return http_parser_statuses[i].message; + } + } + return NULL; +} + char * http_parser_sprint_pair_response(struct http_parser_pair *pair) { return http_parser_sprint_response(pair->response); } @@ -296,7 +306,7 @@ char * http_parser_sprint_response(struct http_parser_message *response) { "HTTP/%s %d %s\r\n" , response->version , response->status - , response->statusMessage + , response->statusMessage ? response->statusMessage : http_parser_status_message(response->status) ); // Headers diff --git a/src/http-parser.h b/src/http-parser.h @@ -60,6 +60,7 @@ struct http_parser_pair * http_parser_pair_init(void *udata); struct http_parser_message * http_parser_request_init(); struct http_parser_message * http_parser_response_init(); + void http_parser_request_data(struct http_parser_message *request, char *data, int size); void http_parser_response_data(struct http_parser_message *response, char *data, int size); @@ -69,6 +70,7 @@ void http_parser_pair_response_data(struct http_parser_pair *pair, char *data, i void http_parser_pair_free(struct http_parser_pair *pair); void http_parser_message_free(struct http_parser_message *subject); +char * http_parser_status_message(int status); char * http_parser_sprint_pair_response(struct http_parser_pair *pair); char * http_parser_sprint_pair_request(struct http_parser_pair *pair); char * http_parser_sprint_response(struct http_parser_message *response);