From a4c0093fbefcc2d6555c696bf44f39a5b3da31b1 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Mon, 2 Jan 2023 15:43:26 +0100 Subject: [PATCH] Small improvements --- src/lib/http.h | 8 ++++---- src/worker/local_handler.c | 3 +++ src/worker/request_handler.c | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/http.h b/src/lib/http.h index a5d9802..a10ace5 100644 --- a/src/lib/http.h +++ b/src/lib/http.h @@ -37,7 +37,7 @@ #define HTTP_COLOR_ERROR "#C00000" #define CLIENT_MAX_HEADER_SIZE 8192 -#define HTTP_MAX_HEADER_FIELD_NUM 64 +#define HTTP_MAX_HEADER_FIELD_NUM 32 #ifndef SERVER_STR # define SERVER_STR "sesimos" @@ -69,11 +69,11 @@ typedef struct { char type; union { struct { - char name[64]; - char value[192]; + char name[32]; + char value[32]; } normal; struct { - char name[192]; + char name[64 - sizeof(char *)]; char *value; } ex_value; struct { diff --git a/src/worker/local_handler.c b/src/worker/local_handler.c index b039291..d2f70c4 100644 --- a/src/worker/local_handler.c +++ b/src/worker/local_handler.c @@ -13,6 +13,7 @@ #include "../workers.h" #include +#include static int local_handler(client_ctx_t *ctx); @@ -112,6 +113,7 @@ static int local_handler(client_ctx_t *ctx) { ctx->file = fopen(uri->meta->filename_comp_br, "rb"); if (ctx->file == NULL) { cache_mark_dirty(ctx->conf->cache, uri->filename); + errno = 0; } else { http_add_header_field(&res->hdr, "Content-Encoding", "br"); enc = COMPRESS_BR; @@ -120,6 +122,7 @@ static int local_handler(client_ctx_t *ctx) { ctx->file = fopen(uri->meta->filename_comp_gz, "rb"); if (ctx->file == NULL) { cache_mark_dirty(ctx->conf->cache, uri->filename); + errno = 0; } else { http_add_header_field(&res->hdr, "Content-Encoding", "gzip"); enc = COMPRESS_GZ; diff --git a/src/worker/request_handler.c b/src/worker/request_handler.c index a88f0bc..8975d37 100644 --- a/src/worker/request_handler.c +++ b/src/worker/request_handler.c @@ -375,6 +375,7 @@ void request_complete(client_ctx_t *ctx) { ctx->req_e = clock_micros(); info("Transfer complete: %s", format_duration(ctx->req_e - ctx->req_s, buf)); + if (ctx->file) fclose(ctx->file); free(ctx->msg_buf_ptr); uri_free(&ctx->uri); http_free_req(&ctx->req);