Using list in http header

This commit is contained in:
2023-01-03 14:05:11 +01:00
parent a54a6af497
commit e82869e993
5 changed files with 35 additions and 27 deletions

View File

@ -11,6 +11,7 @@
#include "../lib/utils.h"
#include "../lib/compress.h"
#include "../workers.h"
#include "../lib/list.h"
#include <string.h>
#include <errno.h>
@ -51,7 +52,7 @@ static int local_handler(client_ctx_t *ctx) {
ctx->msg_buf_ptr = malloc(4096);
ctx->msg_buf = ctx->msg_buf_ptr;
ctx->content_length = snprintf(ctx->msg_buf, 4096 - ctx->content_length, "%s %s HTTP/%s\r\n", req->method, req->uri, req->version);
for (int i = 0; i < req->hdr.field_num; i++) {
for (int i = 0; i < list_size(&req->hdr); i++) {
const http_field *f = &req->hdr.fields[i];
ctx->content_length += snprintf(ctx->msg_buf + ctx->content_length, 4096 - ctx->content_length, "%s: %s\r\n", http_field_get_name(f), http_field_get_value(f));
}