]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: http-server-request - Add http_server_request_fail_bad_method().
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 19 Nov 2019 00:34:06 +0000 (01:34 +0100)
committermartti.rannanjarvi <martti.rannanjarvi@open-xchange.com>
Sat, 18 Apr 2020 14:55:11 +0000 (14:55 +0000)
src/lib-http/http-server-request.c
src/lib-http/http-server.h

index 6328d0206748243391fdef0bab07d3370da6ecd1..d7d22f8560d934c207f8d60c941a5bd0b556db71 100644 (file)
@@ -503,6 +503,20 @@ void http_server_request_fail_auth_basic(struct http_server_request *req,
        http_server_request_fail_auth(req, reason, &chlng);
 }
 
+void http_server_request_fail_bad_method(struct http_server_request *req,
+                                        const char *allow)
+{
+       struct http_server_response *resp;
+       const char *reason = "Method Not Allowed";
+
+       req->failed = TRUE;
+
+       resp = http_server_request_create_fail_response(req, 405, reason,
+                                                       reason);
+       http_server_response_add_header(resp, "Allow", allow);
+       http_server_response_submit(resp);
+}
+
 /*
  * Payload input stream
  */
index 0eea4afc51b7a4d9ec22bf1ab29a5de420fc7916..fce35eed6c5c28effe6047b19fec2e9b4efebc09 100644 (file)
@@ -264,6 +264,12 @@ void http_server_request_fail_auth_basic(struct http_server_request *req,
                                         const char *reason, const char *realm)
                                         ATTR_NULL(2);
 
+/* Send a 405 failure response for a request with an unknown method. The allow
+   parameter is the value used for the mandatory "Allow" header in the response.
+ */
+void http_server_request_fail_bad_method(struct http_server_request *req,
+                                        const char *allow);
+
 /* Call the specified callback when HTTP request is destroyed. This happens
    after one of the following: