summaryrefslogtreecommitdiffstats
path: root/src/handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/handler.c')
-rw-r--r--src/handler.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/handler.c b/src/handler.c
index 164a484..36d2628 100644
--- a/src/handler.c
+++ b/src/handler.c
@@ -55,7 +55,6 @@ static bool sanitize(const char *uri)
int tip_client_state_process_payload(struct tip_client *cli)
{
const char *trailer, *x_redirect;
- enum tip_http_method method;
bool allow_redirect = true;
char _uri[32], *uri = _uri;
char path[PATH_MAX + 1];
@@ -68,9 +67,13 @@ int tip_client_state_process_payload(struct tip_client *cli)
ntohs(cli->addr.sin_port), cli->buf); */
if (!strncmp(cli->buf, "GET", strlen("GET"))) {
- method = TIP_METHOD_GET;
+ cli->method = TIP_METHOD_GET;
if (sscanf(cli->buf, "GET %31s HTTP/1.1", uri) != 1)
return tip_client_method_not_found(cli);
+ } else if (!strncmp(cli->buf, "HEAD", strlen("HEAD"))) {
+ cli->method = TIP_METHOD_HEAD;
+ if (sscanf(cli->buf, "HEAD %31s HTTP/1.1", uri) != 1)
+ return tip_client_method_not_found(cli);
} else {
return tip_client_method_not_found(cli);
}
@@ -98,6 +101,12 @@ int tip_client_state_process_payload(struct tip_client *cli)
cli->uri = strdup(uri);
cli->path = strdup(path);
cli->size = st.st_size;
+
+ if (cli->method == TIP_METHOD_HEAD) {
+ cli->state = TIP_CLIENT_PROCESSING_REQUEST_2;
+ return 0;
+ }
+
cli->allow_redirect = allow_redirect;
num_clients++;
@@ -139,7 +148,14 @@ int tip_client_state_process_payload_reply(struct tip_client *cli)
send(tip_client_socket(cli), buf, strlen(buf), 0);
cli->fd = fd;
- cli->state = TIP_CLIENT_PROCESSING_REQUEST_3;
+ switch (cli->method) {
+ case TIP_METHOD_GET:
+ cli->state = TIP_CLIENT_PROCESSING_REQUEST_3;
+ break;
+ case TIP_METHOD_HEAD:
+ /* close connection. */
+ return 1;
+ }
return 0;
}