Commit:    657547f8c4758efcf85c73fec6d7fd8b3983d7cb
Author:    Dmitry Stogov <dmi...@zend.com>         Wed, 21 Mar 2012 16:32:49 
+0400
Parents:   944e622821ebd8ab62bcb3513f6b9e7bcc998b04
Branches:  PHP-5.3

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=657547f8c4758efcf85c73fec6d7fd8b3983d7cb

Log:
Fixed bug #49853 (Soap Client stream context header option ignored)

Bugs:
https://bugs.php.net/49853

Changed paths:
  M  NEWS
  M  ext/soap/php_http.c
  M  ext/soap/php_http.h
  M  ext/soap/php_sdl.c

657547f8c4758efcf85c73fec6d7fd8b3983d7cb
diff --git a/NEWS b/NEWS
index 1b1db1e..6866355 100644
--- a/NEWS
+++ b/NEWS
@@ -92,6 +92,8 @@ PHP                                                           
             NEWS
     User-Agent header). (carloschilazo at gmail dot com)
   . Fixed bug #60842, #51775 (Chunked response parsing error when 
     chunksize length line is > 10 bytes). (Ilia)
+  . Fixed bug #49853 (Soap Client stream context header option ignored).
+    (Dmitry)
 
 - SPL
   . Fixed memory leak when calling SplFileInfo's constructor twice. (Felipe)
diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c
index c414bba..358877d 100644
--- a/ext/soap/php_http.c
+++ b/ext/soap/php_http.c
@@ -32,7 +32,7 @@ static int get_http_headers(php_stream *socketd,char 
**response, int *out_size T
        smart_str_appendl(str,const,sizeof(const)-1)
 
 /* Proxy HTTP Authentication */
-void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
+int proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
 {
        zval **login, **password;
 
@@ -53,11 +53,13 @@ void proxy_authentication(zval* this_ptr, smart_str* 
soap_headers TSRMLS_DC)
                smart_str_append_const(soap_headers, "\r\n");
                efree(buf);
                smart_str_free(&auth);
+               return 1;
        }
+       return 0;
 }
 
 /* HTTP Authentication */
-void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
+int basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
 {
        zval **login, **password;
 
@@ -79,6 +81,78 @@ void basic_authentication(zval* this_ptr, smart_str* 
soap_headers TSRMLS_DC)
                smart_str_append_const(soap_headers, "\r\n");
                efree(buf);
                smart_str_free(&auth);
+               return 1;
+       }
+       return 0;
+}
+
+/* Additional HTTP headers */
+void http_context_headers(php_stream_context* context,
+                          zend_bool has_authorization,
+                          zend_bool has_proxy_authorization,
+                          zend_bool has_cookies,
+                          smart_str* soap_headers TSRMLS_DC)
+{
+       zval **tmp;
+
+       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) &&
+                                   (!has_cookies ||
+                                    name_len != sizeof("cookie")-1 ||
+                                    strncasecmp(s, "cookie", 
sizeof("cookie")-1) != 0) &&
+                                   (!has_authorization ||
+                                    name_len != sizeof("authorization")-1 ||
+                                    strncasecmp(s, "authorization", 
sizeof("authorization")-1) != 0) &&
+                                   (!has_proxy_authorization ||
+                                    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;
+               }
        }
 }
 
@@ -662,8 +736,7 @@ try_again:
 
                /* Proxy HTTP Authentication */
                if (use_proxy && !use_ssl) {
-                       has_proxy_authorization = 1;
-                       proxy_authentication(this_ptr, &soap_headers TSRMLS_CC);
+                       has_proxy_authorization = 
proxy_authentication(this_ptr, &soap_headers TSRMLS_CC);
                }
 
                /* Send cookies along with request */
@@ -705,65 +778,7 @@ try_again:
                        }
                }
 
-               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) &&
-                                           (!has_cookies ||
-                                            name_len != sizeof("cookie")-1 ||
-                                            strncasecmp(s, "cookie", 
sizeof("cookie")-1) != 0) &&
-                                           (!has_authorization ||
-                                            name_len != 
sizeof("authorization")-1 ||
-                                            strncasecmp(s, "authorization", 
sizeof("authorization")-1) != 0) &&
-                                           (!has_proxy_authorization ||
-                                            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;
-                       }
-               }
+               http_context_headers(context, has_authorization, 
has_proxy_authorization, has_cookies, &soap_headers TSRMLS_CC);
 
                smart_str_append_const(&soap_headers, "\r\n");
                smart_str_0(&soap_headers);
diff --git a/ext/soap/php_http.h b/ext/soap/php_http.h
index 2cab5c0..540a917 100644
--- a/ext/soap/php_http.h
+++ b/ext/soap/php_http.h
@@ -31,6 +31,11 @@ int make_http_soap_request(zval  *this_ptr,
                            char **response, 
                            int   *response_len TSRMLS_DC);
 
-void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC);
-void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC);
+int proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC);
+int basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC);
+void http_context_headers(php_stream_context* context,
+                          zend_bool has_authorization,
+                          zend_bool has_proxy_authorization,
+                          zend_bool has_cookies,
+                          smart_str* soap_headers TSRMLS_DC);
 #endif
diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c
index 45aee30..e85b606 100644
--- a/ext/soap/php_sdl.c
+++ b/ext/soap/php_sdl.c
@@ -3196,6 +3196,8 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, long cache_wsdl 
TSRMLS_DC)
        smart_str headers = {0};
        char* key = NULL;
        time_t t = time(0);
+       zend_bool has_proxy_authorization = 0;
+       zend_bool has_authorization = 0;
 
        if (strchr(uri,':') != NULL || IS_ABSOLUTE_PATH(uri, uri_len)) {
                uri_len = strlen(uri);
@@ -3299,10 +3301,10 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, long 
cache_wsdl TSRMLS_DC)
                        zval_ptr_dtor(&str_proxy);
                }
 
-               proxy_authentication(this_ptr, &headers TSRMLS_CC);
+               has_proxy_authorization = proxy_authentication(this_ptr, 
&headers TSRMLS_CC);
        }
 
-       basic_authentication(this_ptr, &headers TSRMLS_CC);
+       has_authorization = basic_authentication(this_ptr, &headers TSRMLS_CC);
 
        /* Use HTTP/1.1 with "Connection: close" by default */
        if (php_stream_context_get_option(context, "http", "protocol_version", 
&tmp) == FAILURE) {
@@ -3311,7 +3313,7 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, long cache_wsdl 
TSRMLS_DC)
                ZVAL_DOUBLE(http_version, 1.1);
                php_stream_context_set_option(context, "http", 
"protocol_version", http_version);
                zval_ptr_dtor(&http_version);
-               smart_str_appendl(&headers, "Connection: close", 
sizeof("Connection: close")-1);
+               smart_str_appendl(&headers, "Connection: close\r\n", 
sizeof("Connection: close\r\n")-1);
        }
 
        if (headers.len > 0) {
@@ -3319,6 +3321,8 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, long cache_wsdl 
TSRMLS_DC)
 
                if (!context) {
                        context = php_stream_context_alloc();
+               } else {
+                       http_context_headers(context, has_authorization, 
has_proxy_authorization, 0, &headers TSRMLS_CC);
                }
 
                smart_str_0(&headers);
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to