@@ -32,7 +32,7 @@ static int get_http_headers(php_stream *socketd,char **response, int *out_size T
32
32
smart_str_appendl(str,const,sizeof(const)-1)
33
33
34
34
/* 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 )
36
36
{
37
37
zval * * login , * * password ;
38
38
@@ -53,11 +53,13 @@ void proxy_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
53
53
smart_str_append_const (soap_headers , "\r\n" );
54
54
efree (buf );
55
55
smart_str_free (& auth );
56
+ return 1 ;
56
57
}
58
+ return 0 ;
57
59
}
58
60
59
61
/* 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 )
61
63
{
62
64
zval * * login , * * password ;
63
65
@@ -79,6 +81,78 @@ void basic_authentication(zval* this_ptr, smart_str* soap_headers TSRMLS_DC)
79
81
smart_str_append_const (soap_headers , "\r\n" );
80
82
efree (buf );
81
83
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
+ }
82
156
}
83
157
}
84
158
@@ -662,8 +736,7 @@ int make_http_soap_request(zval *this_ptr,
662
736
663
737
/* Proxy HTTP Authentication */
664
738
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 );
667
740
}
668
741
669
742
/* Send cookies along with request */
@@ -705,65 +778,7 @@ int make_http_soap_request(zval *this_ptr,
705
778
}
706
779
}
707
780
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 );
767
782
768
783
smart_str_append_const (& soap_headers , "\r\n" );
769
784
smart_str_0 (& soap_headers );
0 commit comments