@@ -202,6 +202,7 @@ typedef struct php_cli_server_http_response_status_code_pair {
202
202
static php_cli_server_http_response_status_code_pair template_map [] = {
203
203
{ 400 , "<h1>%s</h1><p>Your browser sent a request that this server could not understand.</p>" },
204
204
{ 404 , "<h1>%s</h1><p>The requested resource <code class=\"url\">%s</code> was not found on this server.</p>" },
205
+ { 405 , "<h1>%s</h1><p>Requested method not allowed.</p>" },
205
206
{ 500 , "<h1>%s</h1><p>The server is temporarily unavailable.</p>" },
206
207
{ 501 , "<h1>%s</h1><p>Request method not supported.</p>" }
207
208
};
@@ -2040,6 +2041,15 @@ static zend_result php_cli_server_send_error_page(php_cli_server *server, php_cl
2040
2041
smart_str_appends_ex (& buffer , "Content-Length: " , 1 );
2041
2042
smart_str_append_unsigned_ex (& buffer , php_cli_server_buffer_size (& client -> content_sender .buffer ), 1 );
2042
2043
smart_str_appendl_ex (& buffer , "\r\n" , 2 , 1 );
2044
+ if (status == 405 ) {
2045
+ smart_str_appends_ex (& buffer , "Allow: " , 1 );
2046
+ smart_str_appends_ex (& buffer , php_http_method_str (PHP_HTTP_GET ), 1 );
2047
+ smart_str_appends_ex (& buffer , ", " , 1 );
2048
+ smart_str_appends_ex (& buffer , php_http_method_str (PHP_HTTP_HEAD ), 1 );
2049
+ smart_str_appends_ex (& buffer , ", " , 1 );
2050
+ smart_str_appends_ex (& buffer , php_http_method_str (PHP_HTTP_POST ), 1 );
2051
+ smart_str_appendl_ex (& buffer , "\r\n" , 2 , 1 );
2052
+ }
2043
2053
smart_str_appendl_ex (& buffer , "\r\n" , 2 , 1 );
2044
2054
2045
2055
chunk = php_cli_server_chunk_heap_new (buffer .s , ZSTR_VAL (buffer .s ), ZSTR_LEN (buffer .s ));
@@ -2094,6 +2104,12 @@ static zend_result php_cli_server_begin_send_static(php_cli_server *server, php_
2094
2104
int fd ;
2095
2105
int status = 200 ;
2096
2106
2107
+ if (client -> request .request_method == PHP_HTTP_DELETE
2108
+ || client -> request .request_method == PHP_HTTP_PUT
2109
+ || client -> request .request_method == PHP_HTTP_PATCH ) {
2110
+ return php_cli_server_send_error_page (server , client , 405 );
2111
+ }
2112
+
2097
2113
if (client -> request .path_translated && strlen (client -> request .path_translated ) != client -> request .path_translated_len ) {
2098
2114
/* can't handle paths that contain nul bytes */
2099
2115
return php_cli_server_send_error_page (server , client , 400 );
0 commit comments