summaryrefslogtreecommitdiff
path: root/sapi/cli/php_cli_server.c
diff options
context:
space:
mode:
authorSammy Kaye Powers <sammyk@sammykmedia.com>2017-03-29 09:27:18 -0500
committerSara Golemon <pollita@php.net>2017-04-11 15:08:05 -0700
commitfd0e71d001b76c0ce16bd2d2f7d80956ae9fc6f9 (patch)
tree4365add450bc645208ffbcc7bd86955e52087364 /sapi/cli/php_cli_server.c
parent8121cb50465268d645a61f79a8bec4d144700b34 (diff)
downloadphp-git-fd0e71d001b76c0ce16bd2d2f7d80956ae9fc6f9.tar.gz
Fix bug 60471 by correctly identifying unused speculative preconnections
* Correctly identify unused speculative preconnections from browsers like Chrome and Firefox * Add a new message to the debug level that is emitted when a TCP connection is closed without sending any request (a preconnection) * Fix an issue where the existing debug messages were not being displayed even when debug mode was enabled
Diffstat (limited to 'sapi/cli/php_cli_server.c')
-rw-r--r--sapi/cli/php_cli_server.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
index de4cfb2195..1f4eb38604 100644
--- a/sapi/cli/php_cli_server.c
+++ b/sapi/cli/php_cli_server.c
@@ -211,6 +211,8 @@ static php_cli_server_http_response_status_code_pair template_map[] = {
static int php_cli_output_is_tty = OUTPUT_NOT_CHECKED;
#endif
+static const char php_cli_server_request_error_unexpected_eof[] = "Unexpected EOF";
+
static size_t php_cli_server_client_send_through(php_cli_server_client *client, const char *str, size_t str_len);
static php_cli_server_chunk *php_cli_server_chunk_heap_new_self_contained(size_t len);
static void php_cli_server_buffer_append(php_cli_server_buffer *buffer, php_cli_server_chunk *chunk);
@@ -1462,7 +1464,7 @@ static void normalize_vpath(char **retval, size_t *retval_len, const char *vpath
#ifdef PHP_WIN32
{
char *p = decoded_vpath;
-
+
do {
if (*p == '\\') {
*p = '/';
@@ -1677,7 +1679,7 @@ static int php_cli_server_client_read_request(php_cli_server_client *client, cha
*errstr = php_socket_strerror(err, NULL, 0);
return -1;
} else if (nbytes_read == 0) {
- *errstr = estrdup("Unexpected EOF");
+ *errstr = estrdup(php_cli_server_request_error_unexpected_eof);
return -1;
}
client->parser.data = client;
@@ -1806,7 +1808,7 @@ static void php_cli_server_client_dtor(php_cli_server_client *client) /* {{{ */
static void php_cli_server_close_connection(php_cli_server *server, php_cli_server_client *client) /* {{{ */
{
-#ifdef DEBUG
+#if PHP_DEBUG
php_cli_server_logf("%s Closing", client->addr_str);
#endif
zend_hash_index_del(&server->clients, client->sock);
@@ -2297,7 +2299,13 @@ static int php_cli_server_recv_event_read_request(php_cli_server *server, php_cl
char *errstr = NULL;
int status = php_cli_server_client_read_request(client, &errstr);
if (status < 0) {
- php_cli_server_logf("%s Invalid request (%s)", client->addr_str, errstr);
+ if (strcmp(errstr, php_cli_server_request_error_unexpected_eof) == 0 && client->parser.state == s_start_req) {
+#if PHP_DEBUG
+ php_cli_server_logf("%s Closed without sending a request; it was probably just an unused speculative preconnection", client->addr_str);
+#endif
+ } else {
+ php_cli_server_logf("%s Invalid request (%s)", client->addr_str, errstr);
+ }
efree(errstr);
php_cli_server_close_connection(server, client);
return FAILURE;
@@ -2379,7 +2387,7 @@ static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socke
closesocket(client_sock);
return SUCCESS;
}
-#ifdef DEBUG
+#if PHP_DEBUG
php_cli_server_logf("%s Accepted", client->addr_str);
#endif
zend_hash_index_update_ptr(&server->clients, client_sock, client);