summaryrefslogtreecommitdiffstats
path: root/src/handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/handler.c')
-rw-r--r--src/handler.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/handler.c b/src/handler.c
index 5bcef6b..14abe9b 100644
--- a/src/handler.c
+++ b/src/handler.c
@@ -74,6 +74,10 @@ int tip_client_state_process_payload(struct tip_client *cli)
cli->method = TIP_METHOD_HEAD;
if (sscanf(cli->buf, "HEAD %31s HTTP/1.1", uri) != 1)
return tip_client_method_not_found(cli);
+ } else if (!strncmp(cli->buf, "POST", strlen("POST"))) {
+ cli->method = TIP_METHOD_POST;
+ if (sscanf(cli->buf, "POST %31s HTTP/1.1", uri) != 1)
+ return tip_client_method_not_found(cli);
} else {
return tip_client_method_not_found(cli);
}
@@ -102,7 +106,16 @@ int tip_client_state_process_payload(struct tip_client *cli)
cli->path = strdup(path);
cli->size = st.st_size;
- if (cli->method == TIP_METHOD_HEAD) {
+ switch (cli->method) {
+ case TIP_METHOD_GET:
+ break;
+ case TIP_METHOD_HEAD:
+ cli->state = TIP_CLIENT_PROCESSING_REQUEST_2;
+ return 0;
+ case TIP_METHOD_POST:
+ cli->allow_redirect = true;
+ tip_client_redirect_create(cli);
+ tip_client_activate_pending();
cli->state = TIP_CLIENT_PROCESSING_REQUEST_2;
return 0;
}
@@ -143,6 +156,9 @@ int tip_client_state_process_payload_reply(struct tip_client *cli)
if (fd < 0)
return tip_client_file_not_found(cli);
+ if (cli->method == TIP_METHOD_POST)
+ cli->size = 0;
+
snprintf(buf, sizeof(buf),
"HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n",
cli->size);
@@ -155,6 +171,7 @@ int tip_client_state_process_payload_reply(struct tip_client *cli)
cli->state = TIP_CLIENT_PROCESSING_REQUEST_3;
break;
case TIP_METHOD_HEAD:
+ case TIP_METHOD_POST:
/* close connection. */
return 1;
}