diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/civetweb/test/cgi_test.c | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/civetweb/test/cgi_test.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/civetweb/test/cgi_test.c b/src/civetweb/test/cgi_test.c new file mode 100644 index 000000000..bd446c0a9 --- /dev/null +++ b/src/civetweb/test/cgi_test.c @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#if defined(_WIN32) || defined(WIN32) || defined(WINDOWS) +#include <fcntl.h> +#include <io.h> +#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; +} |