From 946adb54d746e9f5446a5b62fe516e9fadd3a31e Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Fri, 6 Jan 2023 10:37:24 +0100 Subject: [PATCH] Handle HEAD for proxy --- src/worker/proxy_handler.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/worker/proxy_handler.c b/src/worker/proxy_handler.c index b9a8d67..496edb5 100644 --- a/src/worker/proxy_handler.c +++ b/src/worker/proxy_handler.c @@ -57,9 +57,7 @@ static int proxy_handler_1(client_ctx_t *ctx) { ctx->use_proxy = proxy_init(&ctx->proxy, &ctx->req, res, status, ctx->conf, &ctx->socket, &ctx->custom_status, ctx->err_msg) == 0; ctx->proxy->client = ctx; - if (strcmp(ctx->req.method, "HEAD") == 0) { - return 1; - } else if (res->status->code == 101) { + if (res->status->code == 101) { const char *connection = http_get_header_field(&res->hdr, "Connection"); const char *upgrade = http_get_header_field(&res->hdr, "Upgrade"); if (connection != NULL && upgrade != NULL && @@ -83,10 +81,11 @@ static int proxy_handler_1(client_ctx_t *ctx) { const char *content_length_f = http_get_header_field(&res->hdr, "Content-Length"); const char *content_encoding = http_get_header_field(&res->hdr, "Content-Encoding"); if (content_encoding == NULL && ( + content_length_f == NULL || (content_length_f != NULL && strcmp(content_length_f, "0") == 0) || (content_type != NULL && content_length_f != NULL && strncmp(content_type, "text/html", 9) == 0))) { - long content_len = (content_length_f != NULL) ? strtol(content_length_f, NULL, 10) : 0; + long content_len = (strcmp(ctx->req.method, "HEAD") != 0 && content_length_f != NULL) ? strtol(content_length_f, NULL, 10) : 0; if (content_len <= sizeof(ctx->msg_content) - 1) { if (status->status != 101) { status->status = res->status->code; @@ -102,6 +101,10 @@ static int proxy_handler_1(client_ctx_t *ctx) { } } + if (strcmp(ctx->req.method, "HEAD") == 0) { + return 1; + } + /* char *content_encoding = http_get_header_field(&res->hdr, "Content-Encoding"); if (use_proxy && content_encoding == NULL) {