Skip to content

Commit 84c9371

Browse files
vedranmileticMarin Martuslović
andcommitted
Respond with HTTP status 405 to DELETE//PUT/PATCH request on a static resource
Co-authored-by: Marin Martuslović <[email protected]>
1 parent 8d2f281 commit 84c9371

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

sapi/cli/php_cli_server.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ typedef struct php_cli_server_http_response_status_code_pair {
205205
static php_cli_server_http_response_status_code_pair template_map[] = {
206206
{ 400, "<h1>%s</h1><p>Your browser sent a request that this server could not understand.</p>" },
207207
{ 404, "<h1>%s</h1><p>The requested resource <code class=\"url\">%s</code> was not found on this server.</p>" },
208+
{ 405, "<h1>%s</h1><p>Requested method not allowed.</p>" },
208209
{ 500, "<h1>%s</h1><p>The server is temporarily unavailable.</p>" },
209210
{ 501, "<h1>%s</h1><p>Request method not supported.</p>" }
210211
};
@@ -2059,6 +2060,12 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv
20592060
int fd;
20602061
int status = 200;
20612062

2063+
if (client->request.request_method == PHP_HTTP_DELETE
2064+
|| client->request.request_method == PHP_HTTP_PUT
2065+
|| client->request.request_method == PHP_HTTP_PATCH) {
2066+
return php_cli_server_send_error_page(server, client, 405);
2067+
}
2068+
20622069
if (client->request.path_translated && strlen(client->request.path_translated) != client->request.path_translated_len) {
20632070
/* can't handle paths that contain nul bytes */
20642071
return php_cli_server_send_error_page(server, client, 400);

0 commit comments

Comments
 (0)