} php_cli_server_poller;
typedef struct php_cli_server_request {
- enum php_http_method request_method;
+ enum php_http_method request_method;
int protocol_version;
char *request_uri;
size_t request_uri_len;
static php_cli_server_http_reponse_status_code_pair template_map[] = {
{ 400, "<h1 class=\"h\">%s</h1><p>Your browser sent a request that this server could not understand.</p>" },
{ 404, "<h1 class=\"h\">%s</h1><p>The requested resource %s was not found on this server.</p>" },
- { 500, "<h1 class=\"h\">%s</h1><p>The server is temporality unavaiable.</p>" }
+ { 500, "<h1 class=\"h\">%s</h1><p>The server is temporarily unavailable.</p>" },
+ { 501, "<h1 class=\"h\">%s</h1><p>Request method not supported.</p>" }
};
static php_cli_server_ext_mime_type_pair mime_type_map[] = {
ZEND_DECLARE_MODULE_GLOBALS(cli_server);
-/* {{{ static char php_cli_server_css[]
+/* {{{ static char php_cli_server_css[]
* copied from ext/standard/info.c
*/
static const char php_cli_server_css[] = "<style type=\"text/css\">\n" \
}
} /* }}} */
-static int sapi_cli_server_register_entry_cb(char **entry TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ {
+static int sapi_cli_server_register_entry_cb(char **entry TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ {
zval *track_vars_array = va_arg(args, zval *);
if (hash_key->nKeyLength) {
char *real_key, *key;
} else {
sapi_cli_server_register_variable(track_vars_array, "REMOTE_ADDR", client->addr_str TSRMLS_CC);
}
- }
+ }
{
char *tmp;
spprintf(&tmp, 0, "PHP %s Development Server", PHP_VERSION);
sapi_cli_server_log_message, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */
-
+
STANDARD_SAPI_MODULE_PROPERTIES
}; /* }}} */
}
}
}
-
+
#else
php_socket_t fd = 0;
const php_socket_t max_fd = poller->max_fd;
} else if (nbytes_sent == chunk->data.immortal.len) {
php_cli_server_chunk_dtor(chunk);
pefree(chunk, 1);
- sender->buffer.first = next;
+ sender->buffer.first = next;
if (!next) {
sender->buffer.last = NULL;
}
}
}
break; /* regular file */
- }
+ }
if (prev_path) {
pefree(prev_path, 1);
*q = DEFAULT_SLASH;
if (request->vpath[i] == '\\') {
request->vpath[i] = '/';
}
- }
+ }
}
#endif
request->sb = sb;
}
}
}
-
+
*decoded_vpath_end = '\0';
*retval = decoded_vpath;
*retval_len = decoded_vpath_end - decoded_vpath;
smart_str_append_generic_ex(&buffer, php_cli_server_buffer_size(&client->content_sender.buffer), 1, size_t, _unsigned);
smart_str_appendl_ex(&buffer, "\r\n", 2, 1);
smart_str_appendl_ex(&buffer, "\r\n", 2, 1);
-
+
chunk = php_cli_server_chunk_heap_new(buffer.c, buffer.c, buffer.len);
if (!chunk) {
smart_str_free_ex(&buffer, 1);
}
/* }}} */
-static int php_cli_server_request_startup(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) { /* {{{ */
+static int php_cli_server_request_startup(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) { /* {{{ */
char **auth;
php_cli_server_client_populate_request_info(client, &SG(request_info));
if (SUCCESS == zend_hash_find(&client->request.headers, "Authorization", sizeof("Authorization"), (void**)&auth)) {
SG(server_context) = NULL;
SG(rfc1867_uploaded_files) = NULL;
return SUCCESS;
-}
-/* }}} */
+}
+/* }}} */
static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */
{
destroy_request_info(&SG(request_info));
return SUCCESS;
}
- }
+ }
if (server->router) {
if (!php_cli_server_dispatch_router(server, client TSRMLS_CC)) {
|| SUCCESS != php_cli_server_send_error_page(server, client, 500 TSRMLS_CC)) {
php_cli_server_request_shutdown(server, client TSRMLS_CC);
return SUCCESS;
- }
+ }
} else {
if (server->router) {
static int (*send_header_func)(sapi_headers_struct * TSRMLS_DC);
sapi_module.send_headers = send_header_func;
SG(sapi_headers).send_default_content_type = 1;
SG(rfc1867_uploaded_files) = NULL;
- }
+ }
if (SUCCESS != php_cli_server_begin_send_static(server, client TSRMLS_CC)) {
php_cli_server_close_connection(server, client TSRMLS_CC);
}
efree(errstr);
php_cli_server_close_connection(server, client TSRMLS_CC);
return FAILURE;
+ } else if (status == 1 && client->request.request_method == PHP_HTTP_NOT_IMPLEMENTED) {
+ return php_cli_server_send_error_page(server, client, 501 TSRMLS_CC);
} else if (status == 1) {
php_cli_server_poller_remove(&server->poller, POLLIN, client->sock);
php_cli_server_dispatch(server, client TSRMLS_CC);
static int php_cli_server_do_event_loop(php_cli_server *server TSRMLS_DC) /* {{{ */
{
int retval = SUCCESS;
- while (server->is_running) {
+ while (server->is_running) {
static const struct timeval tv = { 1, 0 };
int n = php_cli_server_poller_poll(&server->poller, &tv);
if (n > 0) {