commit 32c77049f555c2cd81969d3fb663032dd5afd62c
parent 5729f8a16f39c55bb7fa0772689e6c0dd4056a86
Author: finwo <finwo@pm.me>
Date: Sun, 18 Feb 2024 22:07:15 +0100
Added minimal test for adding headers
Diffstat:
1 file changed, 12 insertions(+), 0 deletions(-)
diff --git a/test.c b/test.c
@@ -115,6 +115,14 @@ char *responseNotFoundMessage =
"Not Found\r\n"
;
+char *responseNotFoundExtendedMessage =
+ "HTTP/1.0 404 Not Found\r\n"
+ "Content-Length: 11\r\n"
+ "Content-Type: text/plain\r\n"
+ "\r\n"
+ "Not Found\r\n"
+;
+
/* // Passing network data into it */
/* http_parser_request_data(request, message, strlen(message)); */
@@ -235,5 +243,9 @@ int main() {
ASSERT("response->body = \"Not Found\\r\\n\"", strcmp(response->body->data, "Not Found\r\n") == 0);
ASSERT("response->toString matches", strcmp(responseNotFoundMessage, http_parser_sprint_response(response)->data) == 0);
+ http_parser_header_set(response, "Content-Type", "text/plain");
+
+ ASSERT("response->toString matches after header modification", strcmp(responseNotFoundExtendedMessage, http_parser_sprint_response(response)->data) == 0);
+
return err;
}