Skip to content

Commit 657547f

Browse files
committed
Fixed bug #49853 (Soap Client stream context header option ignored)
1 parent 944e622 commit 657547f

File tree

4 files changed

+94
-68
lines changed

4 files changed

+94
-68
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ PHP NEWS
9292
User-Agent header). (carloschilazo at gmail dot com)
9393
. Fixed bug #60842, #51775 (Chunked response parsing error when
9494
chunksize length line is > 10 bytes). (Ilia)
95+
. Fixed bug #49853 (Soap Client stream context header option ignored).
96+
(Dmitry)
9597

9698
- SPL
9799
. Fixed memory leak when calling SplFileInfo's constructor twice. (Felipe)

ext/soap/php_http.c

+78-63
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static int get_http_headers(php_stream *socketd,char **response, int *out_size T
3232
smart_str_appendl(str,const,sizeof(const)-1)
3333

3434
/* Proxy HTTP Authentication */
35-
void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
35+
int proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
3636
{
3737
zval **login, **password;
3838

@@ -53,11 +53,13 @@ void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
5353
smart_str_append_const(soap_headers, "\r\n");
5454
efree(buf);
5555
smart_str_free(&auth);
56+
return 1;
5657
}
58+
return 0;
5759
}
5860

5961
/* HTTP Authentication */
60-
void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
62+
int basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
6163
{
6264
zval **login, **password;
6365

@@ -79,6 +81,78 @@ void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
7981
smart_str_append_const(soap_headers, "\r\n");
8082
efree(buf);
8183
smart_str_free(&auth);
84+
return 1;
85+
}
86+
return 0;
87+
}
88+
89+
/* Additional HTTP headers */
90+
void http_context_headers(php_stream_context* context,
91+
zend_bool has_authorization,
92+
zend_bool has_proxy_authorization,
93+
zend_bool has_cookies,
94+
smart_str* soap_headers TSRMLS_DC)
95+
{
96+
zval **tmp;
97+
98+
if (context &&
99+
php_stream_context_get_option(context, "http", "header", &tmp) == SUCCESS &&
100+
Z_TYPE_PP(tmp) == IS_STRING && Z_STRLEN_PP(tmp)) {
101+
char *s = Z_STRVAL_PP(tmp);
102+
char *p;
103+
int name_len;
104+
105+
while (*s) {
106+
/* skip leading newlines and spaces */
107+
while (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n') {
108+
s++;
109+
}
110+
/* extract header name */
111+
p = s;
112+
name_len = -1;
113+
while (*p) {
114+
if (*p == ':') {
115+
if (name_len < 0) name_len = p - s;
116+
break;
117+
} else if (*p == ' ' || *p == '\t') {
118+
if (name_len < 0) name_len = p - s;
119+
} else if (*p == '\r' || *p == '\n') {
120+
break;
121+
}
122+
p++;
123+
}
124+
if (*p == ':') {
125+
/* extract header value */
126+
while (*p && *p != '\r' && *p != '\n') {
127+
p++;
128+
}
129+
/* skip some predefined headers */
130+
if ((name_len != sizeof("host")-1 ||
131+
strncasecmp(s, "host", sizeof("host")-1) != 0) &&
132+
(name_len != sizeof("connection")-1 ||
133+
strncasecmp(s, "connection", sizeof("connection")-1) != 0) &&
134+
(name_len != sizeof("user-agent")-1 ||
135+
strncasecmp(s, "user-agent", sizeof("user-agent")-1) != 0) &&
136+
(name_len != sizeof("content-length")-1 ||
137+
strncasecmp(s, "content-length", sizeof("content-length")-1) != 0) &&
138+
(name_len != sizeof("content-type")-1 ||
139+
strncasecmp(s, "content-type", sizeof("content-type")-1) != 0) &&
140+
(!has_cookies ||
141+
name_len != sizeof("cookie")-1 ||
142+
strncasecmp(s, "cookie", sizeof("cookie")-1) != 0) &&
143+
(!has_authorization ||
144+
name_len != sizeof("authorization")-1 ||
145+
strncasecmp(s, "authorization", sizeof("authorization")-1) != 0) &&
146+
(!has_proxy_authorization ||
147+
name_len != sizeof("proxy-authorization")-1 ||
148+
strncasecmp(s, "proxy-authorization", sizeof("proxy-authorization")-1) != 0)) {
149+
/* add header */
150+
smart_str_appendl(soap_headers, s, p-s);
151+
smart_str_append_const(soap_headers, "\r\n");
152+
}
153+
}
154+
s = (*p) ? (p + 1) : p;
155+
}
82156
}
83157
}
84158

@@ -662,8 +736,7 @@ int make_http_soap_request(zval *this_ptr,
662736

663737
/* Proxy HTTP Authentication */
664738
if (use_proxy && !use_ssl) {
665-
has_proxy_authorization = 1;
666-
proxy_authentication(this_ptr, &soap_headers TSRMLS_CC);
739+
has_proxy_authorization = proxy_authentication(this_ptr, &soap_headers TSRMLS_CC);
667740
}
668741

669742
/* Send cookies along with request */
@@ -705,65 +778,7 @@ int make_http_soap_request(zval *this_ptr,
705778
}
706779
}
707780

708-
if (context &&
709-
php_stream_context_get_option(context, "http", "header", &tmp) == SUCCESS &&
710-
Z_TYPE_PP(tmp) == IS_STRING && Z_STRLEN_PP(tmp)) {
711-
char *s = Z_STRVAL_PP(tmp);
712-
char *p;
713-
int name_len;
714-
715-
while (*s) {
716-
/* skip leading newlines and spaces */
717-
while (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n') {
718-
s++;
719-
}
720-
/* extract header name */
721-
p = s;
722-
name_len = -1;
723-
while (*p) {
724-
if (*p == ':') {
725-
if (name_len < 0) name_len = p - s;
726-
break;
727-
} else if (*p == ' ' || *p == '\t') {
728-
if (name_len < 0) name_len = p - s;
729-
} else if (*p == '\r' || *p == '\n') {
730-
break;
731-
}
732-
p++;
733-
}
734-
if (*p == ':') {
735-
/* extract header value */
736-
while (*p && *p != '\r' && *p != '\n') {
737-
p++;
738-
}
739-
/* skip some predefined headers */
740-
if ((name_len != sizeof("host")-1 ||
741-
strncasecmp(s, "host", sizeof("host")-1) != 0) &&
742-
(name_len != sizeof("connection")-1 ||
743-
strncasecmp(s, "connection", sizeof("connection")-1) != 0) &&
744-
(name_len != sizeof("user-agent")-1 ||
745-
strncasecmp(s, "user-agent", sizeof("user-agent")-1) != 0) &&
746-
(name_len != sizeof("content-length")-1 ||
747-
strncasecmp(s, "content-length", sizeof("content-length")-1) != 0) &&
748-
(name_len != sizeof("content-type")-1 ||
749-
strncasecmp(s, "content-type", sizeof("content-type")-1) != 0) &&
750-
(!has_cookies ||
751-
name_len != sizeof("cookie")-1 ||
752-
strncasecmp(s, "cookie", sizeof("cookie")-1) != 0) &&
753-
(!has_authorization ||
754-
name_len != sizeof("authorization")-1 ||
755-
strncasecmp(s, "authorization", sizeof("authorization")-1) != 0) &&
756-
(!has_proxy_authorization ||
757-
name_len != sizeof("proxy-authorization")-1 ||
758-
strncasecmp(s, "proxy-authorization", sizeof("proxy-authorization")-1) != 0)) {
759-
/* add header */
760-
smart_str_appendl(&soap_headers, s, p-s);
761-
smart_str_append_const(&soap_headers, "\r\n");
762-
}
763-
}
764-
s = (*p) ? (p + 1) : p;
765-
}
766-
}
781+
http_context_headers(context, has_authorization, has_proxy_authorization, has_cookies, &soap_headers TSRMLS_CC);
767782

768783
smart_str_append_const(&soap_headers, "\r\n");
769784
smart_str_0(&soap_headers);

ext/soap/php_http.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ int make_http_soap_request(zval *this_ptr,
3131
char **response,
3232
int *response_len TSRMLS_DC);
3333

34-
void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC);
35-
void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC);
34+
int proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC);
35+
int basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC);
36+
void http_context_headers(php_stream_context* context,
37+
zend_bool has_authorization,
38+
zend_bool has_proxy_authorization,
39+
zend_bool has_cookies,
40+
smart_str* soap_headers TSRMLS_DC);
3641
#endif

ext/soap/php_sdl.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -3196,6 +3196,8 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, long cache_wsdl TSRMLS_DC)
31963196
smart_str headers = {0};
31973197
char* key = NULL;
31983198
time_t t = time(0);
3199+
zend_bool has_proxy_authorization = 0;
3200+
zend_bool has_authorization = 0;
31993201

32003202
if (strchr(uri,':') != NULL || IS_ABSOLUTE_PATH(uri, uri_len)) {
32013203
uri_len = strlen(uri);
@@ -3299,10 +3301,10 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, long cache_wsdl TSRMLS_DC)
32993301
zval_ptr_dtor(&str_proxy);
33003302
}
33013303

3302-
proxy_authentication(this_ptr, &headers TSRMLS_CC);
3304+
has_proxy_authorization = proxy_authentication(this_ptr, &headers TSRMLS_CC);
33033305
}
33043306

3305-
basic_authentication(this_ptr, &headers TSRMLS_CC);
3307+
has_authorization = basic_authentication(this_ptr, &headers TSRMLS_CC);
33063308

33073309
/* Use HTTP/1.1 with "Connection: close" by default */
33083310
if (php_stream_context_get_option(context, "http", "protocol_version", &tmp) == FAILURE) {
@@ -3311,14 +3313,16 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, long cache_wsdl TSRMLS_DC)
33113313
ZVAL_DOUBLE(http_version, 1.1);
33123314
php_stream_context_set_option(context, "http", "protocol_version", http_version);
33133315
zval_ptr_dtor(&http_version);
3314-
smart_str_appendl(&headers, "Connection: close", sizeof("Connection: close")-1);
3316+
smart_str_appendl(&headers, "Connection: close\r\n", sizeof("Connection: close\r\n")-1);
33153317
}
33163318

33173319
if (headers.len > 0) {
33183320
zval *str_headers;
33193321

33203322
if (!context) {
33213323
context = php_stream_context_alloc();
3324+
} else {
3325+
http_context_headers(context, has_authorization, has_proxy_authorization, 0, &headers TSRMLS_CC);
33223326
}
33233327

33243328
smart_str_0(&headers);

0 commit comments

Comments
 (0)