From 5f462239bee22f0f9135385488ffc3a9e2d03da5 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Fri, 3 Jan 2020 20:17:10 +0100 Subject: [PATCH] [cgi] Calculate CONTENT_LENGTH also for file uploads Before big_file.cgi caused pipe errors when ported to Python3. --- src/protocol/file/cgi.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/protocol/file/cgi.c b/src/protocol/file/cgi.c index 29d69c5b..82b448cc 100644 --- a/src/protocol/file/cgi.c +++ b/src/protocol/file/cgi.c @@ -148,16 +148,31 @@ set_vars(struct connection *conn, unsigned char *script) if (res) return -1; if (post) { + struct http_connection_info *http; unsigned char *postend = strchr((const char *)post, '\n'); unsigned char buf[16]; + struct connection_state error; if (postend) { + res = env_set("CONTENT_TYPE", post, postend - post); if (res) return -1; post = postend + 1; } - snprintf(buf, 16, "%d", (int) strlen(post) / 2); - if (env_set("CONTENT_LENGTH", buf, -1)) return -1; + + if (!init_http_connection_info(conn, 1, 0, 1)) { + return -1; + } + + http = conn->info; + + if (!open_http_post(&http->post, post, &error)) { + return -1; + } + snprintf(buf, 16, "%ld", http->post.total_upload_length); + if (env_set("CONTENT_LENGTH", buf, -1)) { + return -1; + } } if (env_set("REQUEST_METHOD", post ? "POST" : "GET", -1)) return -1;