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