diff options
author | Aaron Ball <nullspoon@oper.io> | 2023-05-25 11:02:35 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2023-05-25 11:02:35 -0600 |
commit | 093d2b208c35df28fdb6b7c7e10690e0d1b59fb8 (patch) | |
tree | 2f29c3a32778e6b074c942846b1385631ab94ee6 | |
parent | a46ad1974426d06959f635a794c107894b833a78 (diff) | |
download | oper.io-093d2b208c35df28fdb6b7c7e10690e0d1b59fb8.tar.gz oper.io-093d2b208c35df28fdb6b7c7e10690e0d1b59fb8.tar.xz |
Support special request for client headers
This will print all HTTP headers the client sends to the server.
-rw-r--r-- | src/cgi.c | 11 | ||||
-rw-r--r-- | src/cgi.h | 4 | ||||
-rw-r--r-- | src/main.c | 7 |
3 files changed, 21 insertions, 1 deletions
@@ -23,6 +23,16 @@ void cgi_print_header(char* ctype, int status) { printf("\n"); } +void cgi_print_headers() { + int i = 0; + while(environ[i] != NULL) { + if(strncmp(environ[i], "HTTP_", 5) == 0) { + puts(environ[i]); + } + i++; + } +} + char* cgi_remote_ip() { if(getenv("HTTP_X_FORWARDED_FOR")) return getenv("HTTP_X_FORWARDED_FOR"); @@ -37,7 +47,6 @@ char* cgi_user_agent() { return NULL; } - int cgi_read_qs(struct querystring* q, char* buf) { // If query string is null, probably env var isn't set if(!q->qs) @@ -21,6 +21,8 @@ #define QS_MAX 256 +extern char** environ; + struct querystring { char* qs; int pos; @@ -28,6 +30,8 @@ struct querystring { void cgi_print_header(char*, int); +void cgi_print_headers(); + char* cgi_remote_ip(); char* cgi_user_agent(); @@ -63,6 +63,13 @@ int main(int argc, char* argv[], char* envp[]) { return 0; } + // If client headers requested + if(strncmp(buf, "headers", 5) == 0) { + cgi_print_header("text/plain", 200); + cgi_print_headers(); + return 0; + } + // Assemble the page path sprintf(path, "%s/%s.html", posts, buf); |