diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2025-03-24 22:16:32 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska@appnovation.com> | 2025-03-24 22:16:32 +0000 |
| commit | fc3255cf6939d22cc54240c5c9be1fddcfea8beb (patch) | |
| tree | 03aa4f093d6e21981b4fbf10d3edb4c63e9fc352 /src | |
| parent | 7adb5cfb425dd927b3e78f1a9da75d825f6a3904 (diff) | |
| download | tipidee-fc3255cf6939d22cc54240c5c9be1fddcfea8beb.tar.gz | |
Add PATCH support, accept PUT/DELETE/PATCH on cgi
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/include/tipidee/method.h | 1 | ||||
| -rw-r--r-- | src/libtipidee/tipidee_method.c | 1 | ||||
| -rw-r--r-- | src/tipideed/cgi.c | 2 | ||||
| -rw-r--r-- | src/tipideed/errors.c | 4 | ||||
| -rw-r--r-- | src/tipideed/options.c | 2 | ||||
| -rw-r--r-- | src/tipideed/tipideed.c | 9 |
6 files changed, 11 insertions, 8 deletions
diff --git a/src/include/tipidee/method.h b/src/include/tipidee/method.h index b6efaa6..8c1b500 100644 --- a/src/include/tipidee/method.h +++ b/src/include/tipidee/method.h @@ -11,6 +11,7 @@ enum tipidee_method_e TIPIDEE_METHOD_GET, TIPIDEE_METHOD_HEAD, TIPIDEE_METHOD_OPTIONS, + TIPIDEE_METHOD_PATCH, TIPIDEE_METHOD_POST, TIPIDEE_METHOD_PRI, TIPIDEE_METHOD_PUT, diff --git a/src/libtipidee/tipidee_method.c b/src/libtipidee/tipidee_method.c index c5e7195..1a33af8 100644 --- a/src/libtipidee/tipidee_method.c +++ b/src/libtipidee/tipidee_method.c @@ -18,6 +18,7 @@ static struct blah_s const table[] = { .num = TIPIDEE_METHOD_GET, .str = "GET" }, { .num = TIPIDEE_METHOD_HEAD, .str = "HEAD" }, { .num = TIPIDEE_METHOD_OPTIONS, .str = "OPTIONS" }, + { .num = TIPIDEE_METHOD_PATCH, .str = "PATCH" }, { .num = TIPIDEE_METHOD_POST, .str = "POST" }, { .num = TIPIDEE_METHOD_PRI, .str = "PRI" }, { .num = TIPIDEE_METHOD_PUT, .str = "PUT" }, diff --git a/src/tipideed/cgi.c b/src/tipideed/cgi.c index 069d045..905792c 100644 --- a/src/tipideed/cgi.c +++ b/src/tipideed/cgi.c @@ -338,7 +338,7 @@ static inline int do_cgi (tipidee_rql *rql, char const *docroot, char const *con buffer_putsnoflush(buffer_1, fmt) ; buffer_putnoflush(buffer_1, "\r\n", 2) ; } - else if (autochunk && rql->m != TIPIDEE_METHOD_HEAD) + else if (autochunk) buffer_putsnoflush(buffer_1, "Transfer-Encoding: chunked\r\n") ; buffer_putnoflush(buffer_1, "\r\n", 2) ; diff --git a/src/tipideed/errors.c b/src/tipideed/errors.c index 9b00f3b..edde934 100644 --- a/src/tipideed/errors.c +++ b/src/tipideed/errors.c @@ -38,7 +38,7 @@ void response_error_early_plus_and_exit (tipidee_rql const *rql, unsigned int st void eexit_405 (tipidee_rql const *rql) { - static tipidee_response_header const allowpost = { .key = "Allow", .value = "GET, HEAD, POST", .options = 0 } ; + static tipidee_response_header const allowpost = { .key = "Allow", .value = "GET, HEAD, POST, PUT, DELETE, PATCH", .options = 0 } ; response_error_early_plus_and_exit(rql, 405, "Method Not Allowed", "Invalid method for the resource.", &allowpost, 1) ; } @@ -127,7 +127,7 @@ void response_error_plus_and_die (tipidee_rql const *rql, int e, char const *doc void exit_405 (tipidee_rql const *rql, char const *docroot, uint32_t options) { - tipidee_response_header hd = { .key = "Allow", .value = options & 1 ? "GET, HEAD, POST" : "GET, HEAD", .options = 0 } ; + tipidee_response_header hd = { .key = "Allow", .value = options & 1 ? "GET, HEAD, POST, PUT, DELETE, PATCH" : "GET, HEAD", .options = 0 } ; response_error_plus_and_exit(rql, docroot, 405, &hd, 1) ; } diff --git a/src/tipideed/options.c b/src/tipideed/options.c index 0ecbb6f..6de40ba 100644 --- a/src/tipideed/options.c +++ b/src/tipideed/options.c @@ -17,7 +17,7 @@ int respond_options (tipidee_rql const *rql, uint32_t flags) tipidee_response_status(buffer_1, rql, 200, "OK") ; tipidee_response_header_writeall_G(buffer_1, g.rhdr, g.rhdrn, 0) ; buffer_putsnoflush(buffer_1, "Content-Length: 0\r\nAllow: GET, HEAD") ; - if (flags & 1) buffer_putsnoflush(buffer_1, ", POST") ; + if (flags & 1) buffer_putsnoflush(buffer_1, ", POST, PUT, DELETE, PATCH") ; buffer_putnoflush(buffer_1, "\r\n\r\n", 4) ; if (flags & 2) tipidee_log_answer(g.logv, rql, 200, 0) ; tain_add_g(&deadline, &g.writetto) ; diff --git a/src/tipideed/tipideed.c b/src/tipideed/tipideed.c index 35abdf2..4c226cb 100644 --- a/src/tipideed/tipideed.c +++ b/src/tipideed/tipideed.c @@ -458,7 +458,7 @@ int main (int argc, char const *const *argv, char const *const *envp) } x = tipidee_headers_search(&hdr, "Transfer-Encoding") ; - if (x) + if (rql.http_minor && x) { if (strcasecmp(x, "chunked")) eexit_400(&rql, "unsupported Transfer-Encoding") ; else tcoding = TIPIDEE_TRANSFERCODING_CHUNKED ; @@ -483,12 +483,13 @@ int main (int argc, char const *const *argv, char const *const *envp) case TIPIDEE_METHOD_GET : case TIPIDEE_METHOD_HEAD : case TIPIDEE_METHOD_POST : - case TIPIDEE_METHOD_TRACE : break ; + case TIPIDEE_METHOD_TRACE : + case TIPIDEE_METHOD_PUT : + case TIPIDEE_METHOD_DELETE : + case TIPIDEE_METHOD_PATCH : break ; case TIPIDEE_METHOD_OPTIONS : if (!rql.uri.path) { respond_options(&rql, 1) ; continue ; } break ; - case TIPIDEE_METHOD_PUT : - case TIPIDEE_METHOD_DELETE : eexit_405(&rql) ; case TIPIDEE_METHOD_CONNECT : eexit_501(&rql, "CONNECT method unsupported") ; case TIPIDEE_METHOD_PRI : eexit_501(&rql, "PRI method attempted with HTTP version 1") ; default : strerr_dief2x(101, "can't happen: ", "unknown HTTP method") ; |
