diff options
author | Dmitry Stogov <dmitry@php.net> | 2008-10-01 13:13:34 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2008-10-01 13:13:34 +0000 |
commit | 8d610e79ac0548675e14f69a15248b4d083cb07c (patch) | |
tree | e8d19d02bce2b70dff33cbc494b0529bc5b95399 /ext/soap/php_http.c | |
parent | f37e905b8c6ae0463ef7456309c7614b51089634 (diff) | |
download | php-git-8d610e79ac0548675e14f69a15248b4d083cb07c.tar.gz |
Added ability to send user defined HTTP headers with SOAP request.
Diffstat (limited to 'ext/soap/php_http.c')
-rw-r--r-- | ext/soap/php_http.c | 82 |
1 files changed, 74 insertions, 8 deletions
diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index 717a85d980..4f886a8ee5 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -106,12 +106,11 @@ void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC) } } -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 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, in 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 @@ int make_http_soap_request(zval *this_ptr, 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 @@ int make_http_soap_request(zval *this_ptr, 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 @@ try_again: } 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 @@ try_again: 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 @@ try_again: 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 && |