From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/civetweb/test/cgi_test.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/civetweb/test/cgi_test.c (limited to 'src/civetweb/test/cgi_test.c') diff --git a/src/civetweb/test/cgi_test.c b/src/civetweb/test/cgi_test.c new file mode 100644 index 00000000..bd446c0a --- /dev/null +++ b/src/civetweb/test/cgi_test.c @@ -0,0 +1,40 @@ +#include +#include +#include + +#if defined(_WIN32) || defined(WIN32) || defined(WINDOWS) +#include +#include +#endif + +int +main(int argc, char *argv[]) +{ + char buf[1024]; + size_t rec_len = 0; + const char *response_header = "Content-Type: text/plain\r\n" + "Connection: close\r\n" + "\r\n"; + const char *req_method = getenv("REQUEST_METHOD"); + const char *con_length = getenv("CONTENT_LENGTH"); + +#if defined(_WIN32) || defined(WIN32) || defined(WINDOWS) + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); +#endif + + /* Write the response header with \r\n */ + fwrite(response_header, 1, strlen(response_header), stdout); + + /* Headline for generated reply: */ + printf("Got message:\n Method: %s\n Content-Length: %s\n Content: ", + req_method, + con_length ? con_length : "not set"); + + /* Read all data from stdin and send it to stdout */ + while ((rec_len = fread(buf, 1, sizeof(buf) - 1, stdin)) > 0) { + fwrite(buf, 1, rec_len, stdout); + } + + return 0; +} -- cgit v1.2.3