commit b0f652b99de4c6f8235319d11df9a7393543db46
parent 84339d984e71705d70e55a3e77a704cff5f45e3b
Author: finwo <finwo@pm.me>
Date: Mon, 7 Aug 2023 23:58:41 +0200
Fix printing request when the body's missing
Diffstat:
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/http-parser.c b/src/http-parser.c
@@ -388,7 +388,9 @@ struct buf * http_parser_sprint_response(struct http_parser_message *response) {
// Treat result as buffer from here
result->len = strlen(result->data);
- buf_append(result, response->body->data, response->body->len);
+ if (response->body) {
+ buf_append(result, response->body->data, response->body->len);
+ }
return result;
}
@@ -399,11 +401,15 @@ struct buf * http_parser_sprint_request(struct http_parser_message *request) {
result->cap = 65536;
result->data = calloc(1, result->cap);
+ char *path = request->path;
+ if (!path) path = "/";
+ if (!strlen(path)) path = "/";
+
// Status
sprintf(result->data,
"%s %s"
, request->method
- , request->path
+ , path
);
// Query
@@ -435,7 +441,9 @@ struct buf * http_parser_sprint_request(struct http_parser_message *request) {
// Treat result as buffer from here
result->len = strlen(result->data);
- buf_append(result, request->body->data, request->body->len);
+ if (request->body) {
+ buf_append(result, request->body->data, request->body->len);
+ }
if (isChunked) {
buf_append(result, "0\r\n\r\n", 5);