diff options
-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); |