uhttpd: recognize PATCH, PUT and DELETE HTTP methods
authorJo-Philipp Wich <jo@mein.io>
Tue, 21 Aug 2018 09:39:15 +0000 (11:39 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 21 Aug 2018 12:23:02 +0000 (14:23 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
client.c
file.c
uhttpd.h

index 04d26f1..3c1aa9d 100644 (file)
--- a/client.c
+++ b/client.c
@@ -40,6 +40,9 @@ const char * const http_methods[] = {
        [UH_HTTP_MSG_POST] = "POST",
        [UH_HTTP_MSG_HEAD] = "HEAD",
        [UH_HTTP_MSG_OPTIONS] = "OPTIONS",
        [UH_HTTP_MSG_POST] = "POST",
        [UH_HTTP_MSG_HEAD] = "HEAD",
        [UH_HTTP_MSG_OPTIONS] = "OPTIONS",
+       [UH_HTTP_MSG_PUT] = "PUT",
+       [UH_HTTP_MSG_PATCH] = "PATCH",
+       [UH_HTTP_MSG_DELETE] = "DELETE",
 };
 
 void uh_http_header(struct client *cl, int code, const char *summary)
 };
 
 void uh_http_header(struct client *cl, int code, const char *summary)
diff --git a/file.c b/file.c
index ae9119e..8ccf982 100644 (file)
--- a/file.c
+++ b/file.c
@@ -357,6 +357,11 @@ static void uh_file_response_304(struct client *cl, struct stat *s)
        return uh_file_response_ok_hdrs(cl, s);
 }
 
        return uh_file_response_ok_hdrs(cl, s);
 }
 
+static void uh_file_response_405(struct client *cl)
+{
+       uh_http_header(cl, 405, "Method Not Allowed");
+}
+
 static void uh_file_response_412(struct client *cl)
 {
        uh_http_header(cl, 412, "Precondition Failed");
 static void uh_file_response_412(struct client *cl)
 {
        uh_http_header(cl, 412, "Precondition Failed");
@@ -630,6 +635,20 @@ static void uh_file_request(struct client *cl, const char *url,
        struct http_request *req = &cl->request;
        char *error_handler, *escaped_url;
 
        struct http_request *req = &cl->request;
        char *error_handler, *escaped_url;
 
+       switch (cl->request.method) {
+       case UH_HTTP_MSG_GET:
+       case UH_HTTP_MSG_POST:
+       case UH_HTTP_MSG_HEAD:
+       case UH_HTTP_MSG_OPTIONS:
+               break;
+
+       default:
+               uh_file_response_405(cl);
+               ustream_printf(cl->us, "\r\n");
+               uh_request_done(cl);
+               return;
+       }
+
        if (!(pi->stat.st_mode & S_IROTH))
                goto error;
 
        if (!(pi->stat.st_mode & S_IROTH))
                goto error;
 
index 374cd72..8d6022a 100644 (file)
--- a/uhttpd.h
+++ b/uhttpd.h
@@ -92,6 +92,9 @@ enum http_method {
        UH_HTTP_MSG_POST,
        UH_HTTP_MSG_HEAD,
        UH_HTTP_MSG_OPTIONS,
        UH_HTTP_MSG_POST,
        UH_HTTP_MSG_HEAD,
        UH_HTTP_MSG_OPTIONS,
+       UH_HTTP_MSG_PUT,
+       UH_HTTP_MSG_PATCH,
+       UH_HTTP_MSG_DELETE,
 };
 
 enum http_version {
 };
 
 enum http_version {