Respond without body to HEAD request on a static resource

Co-authored-by: Marin Martuslović <marin.martuslovic@student.uniri.hr>
This commit is contained in:
Vedran Miletić 2022-03-20 22:49:08 +01:00 committed by Jakub Zelenka
parent ca011bbf56
commit 4f509058a9
2 changed files with 48 additions and 43 deletions

View file

@ -1980,6 +1980,7 @@ static zend_result php_cli_server_send_error_page(php_cli_server *server, php_cl
php_cli_server_content_sender_ctor(&client->content_sender);
client->content_sender_initialized = true;
if (client->request.request_method != PHP_HTTP_HEAD) {
escaped_request_uri = php_escape_html_entities_ex((const unsigned char *) ZSTR_VAL(client->request.request_uri), ZSTR_LEN(client->request.request_uri), 0, ENT_QUOTES, NULL, /* double_encode */ 0, /* quiet */ 0);
{
@ -2024,6 +2025,7 @@ static zend_result php_cli_server_send_error_page(php_cli_server *server, php_cl
}
php_cli_server_buffer_append(&client->content_sender.buffer, chunk);
}
}
{
php_cli_server_chunk *chunk;
@ -2053,14 +2055,18 @@ static zend_result php_cli_server_send_error_page(php_cli_server *server, php_cl
if (errstr) {
pefree(errstr, 1);
}
if (escaped_request_uri) {
zend_string_free(escaped_request_uri);
}
return SUCCESS;
fail:
if (errstr) {
pefree(errstr, 1);
}
if (escaped_request_uri) {
zend_string_free(escaped_request_uri);
}
return FAILURE;
} /* }}} */
@ -2115,7 +2121,9 @@ static zend_result php_cli_server_begin_send_static(php_cli_server *server, php_
php_cli_server_content_sender_ctor(&client->content_sender);
client->content_sender_initialized = true;
if (client->request.request_method != PHP_HTTP_HEAD) {
client->file_fd = fd;
}
{
php_cli_server_chunk *chunk;

View file

@ -93,6 +93,3 @@ Date: %s
Connection: close
Content-Type: text/html; charset=UTF-8
Content-Length: %d
<!doctype html><html><head><title>404 Not Found</title><style>AAA</style>
</head><body><h1>Not Found</h1><p>The requested resource <code class="url">/main/foo/bar</code> was not found on this server.</p></body></html>