http-parser.c

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

commit 0fe9a8cb48e57e96ebfc933fee97a488ce945f0e
parent 043cb7b959eb4f64119ee83961c336420f7a13f0
Author: finwo <finwo@pm.me>
Date:   Wed,  4 Nov 2020 21:48:25 +0100

Make a copy of the strings in header_set

Diffstat:
Msrc/http-parser.c | 6++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/http-parser.c b/src/http-parser.c @@ -80,10 +80,12 @@ char *http_parser_header_get(struct http_parser_message *subject, char *key) { */ void http_parser_header_set(struct http_parser_message *subject, char *key, char *value) { struct http_parser_header *header = malloc(sizeof(struct http_parser_header)); - header->key = key; - header->value = value; + header->key = malloc(strlen(key)+1); + header->value = malloc(strlen(value)+1); header->next = subject->headers; subject->headers = header; + strcpy(header->key, key); + strcpy(header->value, value); } /**