@@ -78,6 +78,68 @@ int basic_authentication(zval* this_ptr, smart_str* soap_headers)
78
78
return 0 ;
79
79
}
80
80
81
+ static void http_context_add_header (const char * s ,
82
+ bool has_authorization ,
83
+ bool has_proxy_authorization ,
84
+ bool has_cookies ,
85
+ smart_str * soap_headers )
86
+ {
87
+ const char * p ;
88
+ int name_len ;
89
+
90
+ while (* s ) {
91
+ /* skip leading newlines and spaces */
92
+ while (* s == ' ' || * s == '\t' || * s == '\r' || * s == '\n' ) {
93
+ s ++ ;
94
+ }
95
+ /* extract header name */
96
+ p = s ;
97
+ name_len = -1 ;
98
+ while (* p ) {
99
+ if (* p == ':' ) {
100
+ if (name_len < 0 ) name_len = p - s ;
101
+ break ;
102
+ } else if (* p == ' ' || * p == '\t' ) {
103
+ if (name_len < 0 ) name_len = p - s ;
104
+ } else if (* p == '\r' || * p == '\n' ) {
105
+ break ;
106
+ }
107
+ p ++ ;
108
+ }
109
+ if (* p == ':' ) {
110
+ /* extract header value */
111
+ while (* p && * p != '\r' && * p != '\n' ) {
112
+ p ++ ;
113
+ }
114
+ /* skip some predefined headers */
115
+ if ((name_len != sizeof ("host" )- 1 ||
116
+ strncasecmp (s , "host" , sizeof ("host" )- 1 ) != 0 ) &&
117
+ (name_len != sizeof ("connection" )- 1 ||
118
+ strncasecmp (s , "connection" , sizeof ("connection" )- 1 ) != 0 ) &&
119
+ (name_len != sizeof ("user-agent" )- 1 ||
120
+ strncasecmp (s , "user-agent" , sizeof ("user-agent" )- 1 ) != 0 ) &&
121
+ (name_len != sizeof ("content-length" )- 1 ||
122
+ strncasecmp (s , "content-length" , sizeof ("content-length" )- 1 ) != 0 ) &&
123
+ (name_len != sizeof ("content-type" )- 1 ||
124
+ strncasecmp (s , "content-type" , sizeof ("content-type" )- 1 ) != 0 ) &&
125
+ (!has_cookies ||
126
+ name_len != sizeof ("cookie" )- 1 ||
127
+ strncasecmp (s , "cookie" , sizeof ("cookie" )- 1 ) != 0 ) &&
128
+ (!has_authorization ||
129
+ name_len != sizeof ("authorization" )- 1 ||
130
+ strncasecmp (s , "authorization" , sizeof ("authorization" )- 1 ) != 0 ) &&
131
+ (!has_proxy_authorization ||
132
+ name_len != sizeof ("proxy-authorization" )- 1 ||
133
+ strncasecmp (s , "proxy-authorization" , sizeof ("proxy-authorization" )- 1 ) != 0 )) {
134
+ /* add header */
135
+ smart_str_appendl (soap_headers , s , p - s );
136
+ smart_str_append_const (soap_headers , "\r\n" );
137
+ }
138
+ }
139
+ s = (* p ) ? (p + 1 ) : p ;
140
+ }
141
+ }
142
+
81
143
/* Additional HTTP headers */
82
144
void http_context_headers (php_stream_context * context ,
83
145
bool has_authorization ,
@@ -86,64 +148,16 @@ void http_context_headers(php_stream_context* context,
86
148
smart_str * soap_headers )
87
149
{
88
150
zval * tmp ;
89
-
90
- if (context &&
91
- (tmp = php_stream_context_get_option (context , "http" , "header" )) != NULL &&
92
- Z_TYPE_P (tmp ) == IS_STRING && Z_STRLEN_P (tmp )) {
93
- char * s = Z_STRVAL_P (tmp );
94
- char * p ;
95
- int name_len ;
96
-
97
- while (* s ) {
98
- /* skip leading newlines and spaces */
99
- while (* s == ' ' || * s == '\t' || * s == '\r' || * s == '\n' ) {
100
- s ++ ;
101
- }
102
- /* extract header name */
103
- p = s ;
104
- name_len = -1 ;
105
- while (* p ) {
106
- if (* p == ':' ) {
107
- if (name_len < 0 ) name_len = p - s ;
108
- break ;
109
- } else if (* p == ' ' || * p == '\t' ) {
110
- if (name_len < 0 ) name_len = p - s ;
111
- } else if (* p == '\r' || * p == '\n' ) {
112
- break ;
151
+ if (context && (tmp = php_stream_context_get_option (context , "http" , "header" )) != NULL ) {
152
+ if (Z_TYPE_P (tmp ) == IS_STRING && Z_STRLEN_P (tmp )) {
153
+ http_context_add_header (Z_STRVAL_P (tmp ), has_authorization , has_proxy_authorization , has_cookies , soap_headers );
154
+ } else if (Z_TYPE_P (tmp ) == IS_ARRAY ) {
155
+ zval * value ;
156
+ ZEND_HASH_FOREACH_VAL (Z_ARR_P (tmp ), value ) {
157
+ if (Z_TYPE_P (value ) == IS_STRING && Z_STRLEN_P (value )) {
158
+ http_context_add_header (Z_STRVAL_P (value ), has_authorization , has_proxy_authorization , has_cookies , soap_headers );
113
159
}
114
- p ++ ;
115
- }
116
- if (* p == ':' ) {
117
- /* extract header value */
118
- while (* p && * p != '\r' && * p != '\n' ) {
119
- p ++ ;
120
- }
121
- /* skip some predefined headers */
122
- if ((name_len != sizeof ("host" )- 1 ||
123
- strncasecmp (s , "host" , sizeof ("host" )- 1 ) != 0 ) &&
124
- (name_len != sizeof ("connection" )- 1 ||
125
- strncasecmp (s , "connection" , sizeof ("connection" )- 1 ) != 0 ) &&
126
- (name_len != sizeof ("user-agent" )- 1 ||
127
- strncasecmp (s , "user-agent" , sizeof ("user-agent" )- 1 ) != 0 ) &&
128
- (name_len != sizeof ("content-length" )- 1 ||
129
- strncasecmp (s , "content-length" , sizeof ("content-length" )- 1 ) != 0 ) &&
130
- (name_len != sizeof ("content-type" )- 1 ||
131
- strncasecmp (s , "content-type" , sizeof ("content-type" )- 1 ) != 0 ) &&
132
- (!has_cookies ||
133
- name_len != sizeof ("cookie" )- 1 ||
134
- strncasecmp (s , "cookie" , sizeof ("cookie" )- 1 ) != 0 ) &&
135
- (!has_authorization ||
136
- name_len != sizeof ("authorization" )- 1 ||
137
- strncasecmp (s , "authorization" , sizeof ("authorization" )- 1 ) != 0 ) &&
138
- (!has_proxy_authorization ||
139
- name_len != sizeof ("proxy-authorization" )- 1 ||
140
- strncasecmp (s , "proxy-authorization" , sizeof ("proxy-authorization" )- 1 ) != 0 )) {
141
- /* add header */
142
- smart_str_appendl (soap_headers , s , p - s );
143
- smart_str_append_const (soap_headers , "\r\n" );
144
- }
145
- }
146
- s = (* p ) ? (p + 1 ) : p ;
160
+ } ZEND_HASH_FOREACH_END ();
147
161
}
148
162
}
149
163
}
0 commit comments