@@ -202,6 +202,7 @@ typedef struct php_cli_server_http_response_status_code_pair {
202202static php_cli_server_http_response_status_code_pair template_map [] = {
203203 { 400 , "<h1>%s</h1><p>Your browser sent a request that this server could not understand.</p>" },
204204 { 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>" },
205206 { 500 , "<h1>%s</h1><p>The server is temporarily unavailable.</p>" },
206207 { 501 , "<h1>%s</h1><p>Request method not supported.</p>" }
207208};
@@ -2040,6 +2041,15 @@ static zend_result php_cli_server_send_error_page(php_cli_server *server, php_cl
20402041 smart_str_appends_ex (& buffer , "Content-Length: " , 1 );
20412042 smart_str_append_unsigned_ex (& buffer , php_cli_server_buffer_size (& client -> content_sender .buffer ), 1 );
20422043 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+ }
20432053 smart_str_appendl_ex (& buffer , "\r\n" , 2 , 1 );
20442054
20452055 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_
20942104 int fd ;
20952105 int status = 200 ;
20962106
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+
20972113 if (client -> request .path_translated && strlen (client -> request .path_translated ) != client -> request .path_translated_len ) {
20982114 /* can't handle paths that contain nul bytes */
20992115 return php_cli_server_send_error_page (server , client , 400 );
0 commit comments