summaryrefslogtreecommitdiff
path: root/sapi/cli/php_cli_server.c
diff options
context:
space:
mode:
Diffstat (limited to 'sapi/cli/php_cli_server.c')
-rw-r--r--sapi/cli/php_cli_server.c41
1 files changed, 36 insertions, 5 deletions
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
index 2d0dbffba2..82bd573b56 100644
--- a/sapi/cli/php_cli_server.c
+++ b/sapi/cli/php_cli_server.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -98,7 +98,7 @@
#include "ext/standard/file.h" /* for php_set_sock_blocking() :-( */
#include "ext/standard/php_smart_str.h"
#include "ext/standard/html.h"
-#include "ext/standard/url.h" /* for php_url_decode() */
+#include "ext/standard/url.h" /* for php_raw_url_decode() */
#include "ext/standard/php_string.h" /* for php_dirname() */
#include "php_network.h"
@@ -246,6 +246,7 @@ static php_cli_server_http_response_status_code_pair status_map[] = {
{ 428, "Precondition Required" },
{ 429, "Too Many Requests" },
{ 431, "Request Header Fields Too Large" },
+ { 451, "Unavailable For Legal Reasons"},
{ 500, "Internal Server Error" },
{ 501, "Not Implemented" },
{ 502, "Bad Gateway" },
@@ -732,6 +733,9 @@ static int sapi_cli_server_register_entry_cb(char **entry TSRMLS_DC, int num_arg
}
}
spprintf(&real_key, 0, "%s_%s", "HTTP", key);
+ if (strcmp(key, "CONTENT_TYPE") == 0 || strcmp(key, "CONTENT_LENGTH") == 0) {
+ sapi_cli_server_register_variable(track_vars_array, key, *entry TSRMLS_CC);
+ }
sapi_cli_server_register_variable(track_vars_array, real_key, *entry TSRMLS_CC);
efree(key);
efree(real_key);
@@ -1574,7 +1578,19 @@ static void normalize_vpath(char **retval, size_t *retval_len, const char *vpath
return;
}
- decoded_vpath_end = decoded_vpath + php_url_decode(decoded_vpath, vpath_len);
+ decoded_vpath_end = decoded_vpath + php_raw_url_decode(decoded_vpath, vpath_len);
+
+#ifdef PHP_WIN32
+ {
+ char *p = decoded_vpath;
+
+ do {
+ if (*p == '\\') {
+ *p = '/';
+ }
+ } while (*p++);
+ }
+#endif
p = decoded_vpath;
@@ -1853,8 +1869,7 @@ static void php_cli_server_client_populate_request_info(const php_cli_server_cli
request_info->request_uri = client->request.request_uri;
request_info->path_translated = client->request.path_translated;
request_info->query_string = client->request.query_string;
- request_info->post_data = client->request.content;
- request_info->content_length = request_info->post_data_length = client->request.content_len;
+ request_info->content_length = client->request.content_len;
request_info->auth_user = request_info->auth_password = request_info->auth_digest = NULL;
if (SUCCESS == zend_hash_find(&client->request.headers, "content-type", sizeof("content-type"), (void**)&val)) {
request_info->content_type = *val;
@@ -2043,6 +2058,19 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv
return php_cli_server_send_error_page(server, client, 400 TSRMLS_CC);
}
+#ifdef PHP_WIN32
+ /* The win32 namespace will cut off trailing dots and spaces. Since the
+ VCWD functionality isn't used here, a sophisticated functionality
+ would have to be reimplemented to know ahead there are no files
+ with invalid names there. The simplest is just to forbid invalid
+ filenames, which is done here. */
+ if (client->request.path_translated &&
+ ('.' == client->request.path_translated[client->request.path_translated_len-1] ||
+ ' ' == client->request.path_translated[client->request.path_translated_len-1])) {
+ return php_cli_server_send_error_page(server, client, 500 TSRMLS_CC);
+ }
+#endif
+
fd = client->request.path_translated ? open(client->request.path_translated, O_RDONLY): -1;
if (fd < 0) {
return php_cli_server_send_error_page(server, client, 404 TSRMLS_CC);
@@ -2186,6 +2214,9 @@ static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client
if (!is_static_file) {
if (SUCCESS == php_cli_server_dispatch_script(server, client TSRMLS_CC)
|| SUCCESS != php_cli_server_send_error_page(server, client, 500 TSRMLS_CC)) {
+ if (SG(sapi_headers).http_response_code == 304) {
+ SG(sapi_headers).send_default_content_type = 0;
+ }
php_cli_server_request_shutdown(server, client TSRMLS_CC);
return SUCCESS;
}