summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2023-05-25 11:02:35 -0600
committerAaron Ball <nullspoon@oper.io>2023-05-25 11:02:35 -0600
commit093d2b208c35df28fdb6b7c7e10690e0d1b59fb8 (patch)
tree2f29c3a32778e6b074c942846b1385631ab94ee6
parenta46ad1974426d06959f635a794c107894b833a78 (diff)
downloadoper.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.c11
-rw-r--r--src/cgi.h4
-rw-r--r--src/main.c7
3 files changed, 21 insertions, 1 deletions
diff --git a/src/cgi.c b/src/cgi.c
index 8aad33d..ae8c591 100644
--- a/src/cgi.c
+++ b/src/cgi.c
@@ -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)
diff --git a/src/cgi.h b/src/cgi.h
index 2aa34cf..0527800 100644
--- a/src/cgi.h
+++ b/src/cgi.h
@@ -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();
diff --git a/src/main.c b/src/main.c
index 0115640..4578318 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);

Generated by cgit