dmitry Wed Oct 1 13:13:34 2008 UTC
Modified files: (Branch: PHP_5_3)
/php-src NEWS
/php-src/ext/soap php_http.c
Log:
Added ability to send user defined HTTP headers with SOAP request.
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.336&r2=1.2027.2.547.2.965.2.337&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.336
php-src/NEWS:1.2027.2.547.2.965.2.337
--- php-src/NEWS:1.2027.2.547.2.965.2.336 Wed Oct 1 07:30:30 2008
+++ php-src/NEWS Wed Oct 1 13:13:34 2008
@@ -8,6 +8,9 @@
- Changed openssl info to show the shared library version number. (Scott)
+- Added ability to send user defined HTTP headers with SOAP request.
+ (Brain J.France, Dmitry)
+
- Fixed bug causing the algorithm parameter of mhash() to be modified. (Scott)
- Fixed bug #46205 (Closure - Memory leaks when ReflectionException is thrown).
http://cvs.php.net/viewvc.cgi/php-src/ext/soap/php_http.c?r1=1.77.2.11.2.12.2.5&r2=1.77.2.11.2.12.2.6&diff_format=u
Index: php-src/ext/soap/php_http.c
diff -u php-src/ext/soap/php_http.c:1.77.2.11.2.12.2.5
php-src/ext/soap/php_http.c:1.77.2.11.2.12.2.6
--- php-src/ext/soap/php_http.c:1.77.2.11.2.12.2.5 Fri Apr 4 13:02:48 2008
+++ php-src/ext/soap/php_http.c Wed Oct 1 13:13:34 2008
@@ -17,7 +17,7 @@
| Dmitry Stogov <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_http.c,v 1.77.2.11.2.12.2.5 2008/04/04 13:02:48 jorton Exp $ */
+/* $Id: php_http.c,v 1.77.2.11.2.12.2.6 2008/10/01 13:13:34 dmitry Exp $ */
#include "php_soap.h"
#include "ext/standard/base64.h"
@@ -106,12 +106,11 @@
}
}
-static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl,
int *use_proxy TSRMLS_DC)
+static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl,
php_stream_context *context, int *use_proxy TSRMLS_DC)
{
php_stream *stream;
zval **proxy_host, **proxy_port, **tmp;
char *host;
- php_stream_context *context = NULL;
char *name;
long namelen;
int port;
@@ -140,11 +139,6 @@
old_error_reporting = EG(error_reporting);
EG(error_reporting) &=
~(E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE);
- if (SUCCESS == zend_hash_find(Z_OBJPROP_P(this_ptr),
- "_stream_context", sizeof("_stream_context"),
(void**)&tmp)) {
- context = php_stream_context_from_zval(*tmp, 0);
- }
-
namelen = spprintf(&name, 0, "%s://%s:%d", (use_ssl && !*use_proxy)?
"ssl" : "tcp", host, port);
stream = php_stream_xport_create(name, namelen,
@@ -240,6 +234,7 @@
char *content_encoding;
char *http_msg = NULL;
zend_bool old_allow_url_fopen;
+ php_stream_context *context = NULL;
if (this_ptr == NULL || Z_TYPE_P(this_ptr) != IS_OBJECT) {
return FALSE;
@@ -307,6 +302,11 @@
phpurl = php_url_parse(location);
}
+ if (SUCCESS == zend_hash_find(Z_OBJPROP_P(this_ptr),
+ "_stream_context", sizeof("_stream_context"),
(void**)&tmp)) {
+ context = php_stream_context_from_zval(*tmp, 0);
+ }
+
try_again:
if (phpurl == NULL || phpurl->host == NULL) {
if (phpurl != NULL) {php_url_free(phpurl);}
@@ -374,7 +374,7 @@
}
if (!stream) {
- stream = http_connect(this_ptr, phpurl, use_ssl, &use_proxy
TSRMLS_CC);
+ stream = http_connect(this_ptr, phpurl, use_ssl, context,
&use_proxy TSRMLS_CC);
if (stream) {
php_stream_auto_cleanup(stream);
add_property_resource(this_ptr, "httpsocket",
php_stream_get_resource_id(stream));
@@ -438,6 +438,14 @@
smart_str_appendl(&soap_headers,
Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
smart_str_append_const(&soap_headers, "\r\n");
}
+ } else if (context &&
+ php_stream_context_get_option(context, "http",
"user_agent", &tmp) == SUCCESS &&
+ Z_TYPE_PP(tmp) == IS_STRING) {
+ if (Z_STRLEN_PP(tmp) > 0) {
+ smart_str_append_const(&soap_headers,
"User-Agent: ");
+ smart_str_appendl(&soap_headers,
Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
+ smart_str_append_const(&soap_headers, "\r\n");
+ }
} else{
smart_str_append_const(&soap_headers, "User-Agent:
PHP-SOAP/"PHP_VERSION"\r\n");
}
@@ -675,6 +683,64 @@
smart_str_append_const(&soap_headers, "\r\n");
}
}
+
+ if (context &&
+ php_stream_context_get_option(context, "http",
"header", &tmp) == SUCCESS &&
+ Z_TYPE_PP(tmp) == IS_STRING && Z_STRLEN_PP(tmp)) {
+ char *s = Z_STRVAL_PP(tmp);
+ char *p;
+ int name_len;
+
+ while (*s) {
+ /* skip leading newlines and spaces */
+ while (*s == ' ' || *s == '\t' || *s == '\r' ||
*s == '\n') {
+ s++;
+ }
+ /* extract header name */
+ p = s;
+ name_len = -1;
+ while (*p) {
+ if (*p == ':') {
+ if (name_len < 0) name_len = p
- s;
+ break;
+ } else if (*p == ' ' || *p == '\t') {
+ if (name_len < 0) name_len = p
- s;
+ } else if (*p == '\r' || *p == '\n') {
+ break;
+ }
+ p++;
+ }
+ if (*p == ':') {
+ /* extract header value */
+ while (*p && *p != '\r' && *p != '\n') {
+ p++;
+ }
+ /* skip some predefined headers */
+ if ((name_len != sizeof("host")-1 ||
+ strncasecmp(s, "host",
sizeof("host")-1) != 0) &&
+ (name_len != sizeof("connection")-1
||
+ strncasecmp(s, "connection",
sizeof("connection")-1) != 0) &&
+ (name_len != sizeof("user-agent")-1
||
+ strncasecmp(s, "user-agent",
sizeof("user-agent")-1) != 0) &&
+ (name_len !=
sizeof("content-length")-1 ||
+ strncasecmp(s, "content-length",
sizeof("content-length")-1) != 0) &&
+ (name_len !=
sizeof("content-type")-1 ||
+ strncasecmp(s, "content-type",
sizeof("content-type")-1) != 0) &&
+ (name_len != sizeof("cookie")-1 ||
+ strncasecmp(s, "cookie",
sizeof("cookie")-1) != 0) &&
+ (name_len !=
sizeof("authorization")-1 ||
+ strncasecmp(s, "authorization",
sizeof("authorization")-1) != 0) &&
+ (name_len !=
sizeof("proxy-authorization")-1 ||
+ strncasecmp(s,
"proxy-authorization", sizeof("proxy-authorization")-1) != 0)) {
+ /* add header */
+
smart_str_appendl(&soap_headers, s, p-s);
+
smart_str_append_const(&soap_headers, "\r\n");
+ }
+ }
+ s = (*p) ? (p + 1) : p;
+ }
+ }
+
smart_str_append_const(&soap_headers, "\r\n");
smart_str_0(&soap_headers);
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "trace",
sizeof("trace"), (void **) &trace) == SUCCESS &&
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php