com php-src: Implemented FR #55716 - Add an option to pass a custom stream context: ext/standard/basic_functions.c ext/standard/test
s/url/get_headers_error_001.phpt ext/standard/t ests/url/get_headers_error_003.phpt ext/standar d/url.c
| From: | Ferenc Kovacs | Date: | Sun, 29 Mar 2015 23:09:07 +0000 |
| Subject: | com php-src: Implemented FR #55716 - Add an option to pass a custom stream context: ext/standard/basic_functions.c ext/standard/test s/url/get_headers_error_001.phpt ext/standard/t ests/url/get_headers_error_003.phpt ext/standar d/url.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-89334@lists.php.net to get a copy of this message | ||
Commit: fd01b47b8e07ebfbd39627c4a8926d40c48f93d3
Author: Ferenc Kovacs <tyrael@php.net> Mon, 30 Mar 2015 01:08:39 +0200
Parents: 6a8ab3d7c6e24b2294099647ba0ebf2addf16bd0
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=fd01b47b8e07ebfbd39627c4a8926d40c48f93d3
Log:
Implemented FR #55716 - Add an option to pass a custom stream context
Bugs:
https://bugs.php.net/55716
Changed paths:
M ext/standard/basic_functions.c
M ext/standard/tests/url/get_headers_error_001.phpt
A ext/standard/tests/url/get_headers_error_003.phpt
M ext/standard/url.c
Diff:
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 7bf51eb..d270459 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -2583,6 +2583,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_get_headers, 0, 0, 1)
ZEND_ARG_INFO(0, url)
ZEND_ARG_INFO(0, format)
+ ZEND_ARG_INFO(0, context)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ user_filters.c */
diff --git a/ext/standard/tests/url/get_headers_error_001.phpt
b/ext/standard/tests/url/get_headers_error_001.phpt
index 8d5fd11..270c835 100644
--- a/ext/standard/tests/url/get_headers_error_001.phpt
+++ b/ext/standard/tests/url/get_headers_error_001.phpt
@@ -5,7 +5,7 @@ June Henriksen <juneih@redpill-linpro.com>
#PHPTestFest2009 Norway 2009-06-09 \o/
--FILE--
<?php
-/* Prototype : proto array get_headers(string url[, int format])
+/* Prototype : proto array get_headers(string url[, int format[, resource $context]])
* Description: Fetches all the headers sent by the server in response to a HTTP request
* Source code: ext/standard/url.c
* Alias to functions:
@@ -21,8 +21,9 @@ var_dump( get_headers() );
echo "\n-- Testing get_headers() function with more than expected no. of arguments --\n";
$url = 'string_val';
$format = 1;
+$context = stream_context_get_default();
$extra_arg = 10;
-var_dump( get_headers($url, $format, $extra_arg) );
+var_dump( get_headers($url, $format, $context, $extra_arg) );
echo "Done";
?>
@@ -36,7 +37,7 @@ NULL
-- Testing get_headers() function with more than expected no. of arguments --
-Warning: get_headers() expects at most 2 parameters, 3 given in %s on line 19
+Warning: get_headers() expects at most 3 parameters, 4 given in %s on line 20
NULL
Done
diff --git a/ext/standard/tests/url/get_headers_error_003.phpt
b/ext/standard/tests/url/get_headers_error_003.phpt
new file mode 100644
index 0000000..6c88785
--- /dev/null
+++ b/ext/standard/tests/url/get_headers_error_003.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Test get_headers() function : test with context
+--FILE--
+<?php
+
+include dirname(__FILE__)."/../../../../sapi/cli/tests/php_cli_server.inc";
+php_cli_server_start('header("X-Request-Method:
".$_SERVER["REQUEST_METHOD"]);');
+
+$opts = array(
+ 'http' => array(
+ 'method' => 'HEAD'
+ )
+);
+
+$context = stream_context_create($opts);
+$headers = get_headers("http://".PHP_CLI_SERVER_ADDRESS, 1, $context);
+echo $headers["X-Request-Method"]."\n";
+
+stream_context_set_default($opts);
+$headers = get_headers("http://".PHP_CLI_SERVER_ADDRESS, 1);
+echo $headers["X-Request-Method"]."\n";
+
+echo "Done";
+?>
+--EXPECTF--
+HEAD
+HEAD
+Done
+
+
+
diff --git a/ext/standard/url.c b/ext/standard/url.c
index 63327cb..58ac90e 100644
--- a/ext/standard/url.c
+++ b/ext/standard/url.c
@@ -708,22 +708,24 @@ PHPAPI size_t php_raw_url_decode(char *str, size_t len)
}
/* }}} */
-/* {{{ proto array get_headers(string url[, int format])
+/* {{{ proto array get_headers(string url[, int format[, resource context]])
fetches all the headers sent by the server in response to a HTTP request */
PHP_FUNCTION(get_headers)
{
char *url;
size_t url_len;
- php_stream_context *context;
php_stream *stream;
zval *prev_val, *hdr = NULL, *h;
HashTable *hashT;
zend_long format = 0;
+ zval *zcontext = NULL;
+ php_stream_context *context = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &url, &url_len, &format)
== FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lr", &url, &url_len, &format,
&zcontext) == FAILURE) {
return;
}
- context = FG(default_context) ? FG(default_context) : (FG(default_context) =
php_stream_context_alloc());
+
+ context = php_stream_context_from_zval(zcontext, 0);
if (!(stream = php_stream_open_wrapper_ex(url, "r", REPORT_ERRORS | STREAM_USE_URL |
STREAM_ONLY_GET_HEADERS, NULL, context))) {
RETURN_FALSE;