Re: com php-src: Implemented FR #65917 (getallheaders() is not supported by the built-in...): NEWS UPGRADING sapi/cgi/cgi_main.c
sapi/cli/php_cli_server.c sapi/cli/tests/php_cli_server_019.phpt

From: Date: Tue, 19 Nov 2013 06:23:48 +0000
Subject: Re: com php-src: Implemented FR #65917 (getallheaders() is not supported by the built-in...): NEWS UPGRADING sapi/cgi/cgi_main.c
sapi/cli/php_cli_server.c sapi/cli/tests/php_cli_server_019.phpt
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-73986@lists.php.net to get a copy of this message
On Tue, Nov 12, 2013 at 9:27 PM, <ajf@php.net> wrote: > Commit: aee271ec0d30c332bed32b5eca1fdff1cb447eab > Author: Andrea Faulds <ajf@ajf.me> Thu, 17 Oct 2013 22:19:09 > +0000 > Parents: 1984919ddc3252c0f9b5d5d0beef10bdc4804091 > Branches: PHP-5.5 > > Link: > > http://git.php.net/?p=php-src.git;a=commitdiff;h=aee271ec0d30c332bed32b5eca1fdff1cb447eab > > Log: > Implemented FR #65917 (getallheaders() is not supported by the built-in...) > > - Implemented apache_request_headers() and getallheaders() alias in CLI > server > - Implemented apache_response_headers() in CLI server using FastCGI code > > Conflicts: > NEWS > UPGRADING > > Bugs: > https://bugs.php.net/65917 > > Changed paths: > M NEWS > M UPGRADING > M sapi/cgi/cgi_main.c > M sapi/cli/php_cli_server.c > A sapi/cli/tests/php_cli_server_019.phpt > > > Diff: > diff --git a/NEWS b/NEWS > index 8331261..de12f57 100644 > --- a/NEWS > +++ b/NEWS > @@ -6,6 +6,10 @@ PHP > NEWS > . Fixed whitespace part of bug #64874 ("json_decode handles whitespace > and > case-sensitivity incorrectly"). (Andrea Faulds) > > +- CLI server: > + . Implemented FR #65917 (getallheaders() is not supported by the > built-in web > + server) - also implements apache_response_headers() (Andrea Faulds) > + > > 14 Nov 2013, PHP 5.5.6 > > diff --git a/UPGRADING b/UPGRADING > index 43e4118..e95ac2a 100755 > --- a/UPGRADING > +++ b/UPGRADING > @@ -85,6 +85,9 @@ PHP 5.5 UPGRADE NOTES > configure this. The service can now use Type=notify in the systemd > unit file. (Remi) > > +- CLI server: > + Now supports apache_request_headers() and apache_response_headers() > + > ======================================== > 3. Deprecated Functionality > ======================================== > diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c > index 4c78fca..6c83f28 100644 > --- a/sapi/cgi/cgi_main.c > +++ b/sapi/cgi/cgi_main.c > @@ -1688,8 +1688,8 @@ static void add_response_header(sapi_header_struct > *h, zval *return_value TSRMLS > > PHP_FUNCTION(apache_response_headers) /* {{{ */ > { > - if (ZEND_NUM_ARGS() > 0) { > - WRONG_PARAM_COUNT; > + if (zend_parse_parameters_none() == FAILURE) { > + return; > } > > if (!&SG(sapi_headers).headers) { > diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c > index 1315a62..ac8530a 100644 > --- a/sapi/cli/php_cli_server.c > +++ b/sapi/cli/php_cli_server.c > @@ -133,6 +133,7 @@ typedef struct php_cli_server_request { > char *query_string; > size_t query_string_len; > HashTable headers; > + HashTable headers_original_case; > char *content; > size_t content_len; > const char *ext; > @@ -435,6 +436,75 @@ static const char *get_mime_type(const char *ext, > size_t ext_len) /* {{{ */ > return NULL; > } /* }}} */ > > +PHP_FUNCTION(apache_request_headers) /* {{{ */ > +{ > + php_cli_server_client *client; > + HashTable *headers; > + char *key; > + uint key_len; > + char **value_pointer; > + HashPosition pos; > + > + if (zend_parse_parameters_none() == FAILURE) { > + return; > + } > + > + client = SG(server_context); > + headers = &client->request.headers_original_case; > + > + array_init_size(return_value, zend_hash_num_elements(headers)); > + > + zend_hash_internal_pointer_reset_ex(headers, &pos); > + while (zend_hash_get_current_data_ex(headers, (void > **)&value_pointer, &pos) == SUCCESS) { > + zend_hash_get_current_key_ex(headers, &key, &key_len, > NULL, 0, &pos); > + add_assoc_string_ex(return_value, key, key_len, > *value_pointer, 1); > + zend_hash_move_forward_ex(headers, &pos); > + } > +} > +/* }}} */ > + > +static void add_response_header(sapi_header_struct *h, zval *return_value > TSRMLS_DC) /* {{{ */ > +{ > + char *s, *p; > + int len; > + ALLOCA_FLAG(use_heap) > + > + if (h->header_len > 0) { > + p = strchr(h->header, ':'); > + len = p - h->header; > + if (p && (len > 0)) { > + while (len > 0 && (h->header[len-1] == ' ' || > h->header[len-1] == '\t')) { > + len--; > + } > + if (len) { > + s = do_alloca(len + 1, use_heap); > + memcpy(s, h->header, len); > + s[len] = 0; > + do { > + p++; > + } while (*p == ' ' || *p == '\t'); > + add_assoc_stringl_ex(return_value, s, > len+1, p, h->header_len - (p - h->header), 1); > + free_alloca(s, use_heap); > + } > + } > + } > +} > +/* }}} */ > + > +PHP_FUNCTION(apache_response_headers) /* {{{ */ > +{ > + if (zend_parse_parameters_none() == FAILURE) { > + return; > + } > + > + if (!&SG(sapi_headers).headers) { > + RETURN_FALSE; > + } > This line looks odd. &foo should always be non-null, right? Nikita

« previous php.cvs (#73986) next »