@@ -532,6 +532,8 @@ int make_http_soap_request(zval *this_ptr,
532532 }
533533 PG (allow_url_fopen ) = old_allow_url_fopen ;
534534
535+ bool client_trace = Z_TYPE_P (Z_CLIENT_TRACE_P (this_ptr )) == IS_TRUE ;
536+
535537 if (stream ) {
536538 zval * cookies , * login , * password ;
537539 zend_resource * ret = zend_register_resource (phpurl , le_url );
@@ -863,7 +865,7 @@ int make_http_soap_request(zval *this_ptr,
863865
864866 smart_str_append_const (& soap_headers , "\r\n" );
865867 smart_str_0 (& soap_headers );
866- if (Z_TYPE_P ( Z_CLIENT_TRACE_P ( this_ptr )) == IS_TRUE ) {
868+ if (client_trace ) {
867869 zval_ptr_dtor (Z_CLIENT_LAST_REQUEST_HEADERS_P (this_ptr ));
868870 /* Need to copy the string here, as we continue appending to soap_headers below. */
869871 ZVAL_STRINGL (Z_CLIENT_LAST_REQUEST_HEADERS_P (this_ptr ),
@@ -892,65 +894,78 @@ int make_http_soap_request(zval *this_ptr,
892894 return FALSE;
893895 }
894896
895- if (!return_value ) {
896- php_stream_close (stream );
897- convert_to_null (Z_CLIENT_HTTPSOCKET_P (this_ptr ));
898- convert_to_null (Z_CLIENT_USE_PROXY_P (this_ptr ));
899- smart_str_free (& soap_headers_z );
900- return TRUE;
901- }
897+ http_headers = NULL ;
898+ if (return_value || client_trace ) {
899+ do {
900+ http_headers = get_http_headers (stream );
901+ if (!http_headers ) {
902+ if (request != buf ) {
903+ zend_string_release_ex (request , 0 );
904+ }
905+ php_stream_close (stream );
906+ convert_to_null (Z_CLIENT_HTTPSOCKET_P (this_ptr ));
907+ convert_to_null (Z_CLIENT_USE_PROXY_P (this_ptr ));
908+ add_soap_fault (this_ptr , "HTTP" , "Error Fetching http headers" , NULL , NULL );
909+ smart_str_free (& soap_headers_z );
910+ return FALSE;
911+ }
902912
903- do {
904- http_headers = get_http_headers (stream );
905- if (!http_headers ) {
906- if (request != buf ) {
907- zend_string_release_ex (request , 0 );
913+ if (client_trace ) {
914+ zval_ptr_dtor (Z_CLIENT_LAST_RESPONSE_HEADERS_P (this_ptr ));
915+ ZVAL_STR_COPY (Z_CLIENT_LAST_RESPONSE_HEADERS_P (this_ptr ), http_headers );
908916 }
909- php_stream_close (stream );
910- convert_to_null (Z_CLIENT_HTTPSOCKET_P (this_ptr ));
911- convert_to_null (Z_CLIENT_USE_PROXY_P (this_ptr ));
912- add_soap_fault (this_ptr , "HTTP" , "Error Fetching http headers" , NULL , NULL );
913- smart_str_free (& soap_headers_z );
914- return FALSE;
915- }
916917
917- if (Z_TYPE_P (Z_CLIENT_TRACE_P (this_ptr )) == IS_TRUE ) {
918- zval_ptr_dtor (Z_CLIENT_LAST_RESPONSE_HEADERS_P (this_ptr ));
919- ZVAL_STR_COPY (Z_CLIENT_LAST_RESPONSE_HEADERS_P (this_ptr ), http_headers );
920- }
918+ /* Check to see what HTTP status was sent */
919+ http_1_1 = 0 ;
920+ http_status = 0 ;
921+ http_version = get_http_header_value (ZSTR_VAL (http_headers ), "HTTP/" );
922+ if (http_version ) {
923+ char * tmp ;
921924
922- /* Check to see what HTTP status was sent */
923- http_1_1 = 0 ;
924- http_status = 0 ;
925- http_version = get_http_header_value (ZSTR_VAL (http_headers ), "HTTP/" );
926- if (http_version ) {
927- char * tmp ;
925+ if (!strncmp (http_version ,"1.1" , 3 )) {
926+ http_1_1 = 1 ;
927+ }
928928
929- if (!strncmp (http_version ,"1.1" , 3 )) {
930- http_1_1 = 1 ;
931- }
929+ tmp = strstr (http_version ," " );
930+ if (tmp != NULL ) {
931+ tmp ++ ;
932+ http_status = atoi (tmp );
933+ }
934+ tmp = strstr (tmp ," " );
935+ if (tmp != NULL ) {
936+ tmp ++ ;
937+ if (http_msg ) {
938+ efree (http_msg );
939+ }
940+ http_msg = estrdup (tmp );
941+ }
942+ efree (http_version );
932943
933- tmp = strstr (http_version ," " );
934- if (tmp != NULL ) {
935- tmp ++ ;
936- http_status = atoi (tmp );
937- }
938- tmp = strstr (tmp ," " );
939- if (tmp != NULL ) {
940- tmp ++ ;
941- if (http_msg ) {
942- efree (http_msg );
944+ /* Try and get headers again */
945+ if (http_status == 100 ) {
946+ zend_string_release_ex (http_headers , 0 );
943947 }
944- http_msg = estrdup (tmp );
945948 }
946- efree (http_version );
949+ } while (http_status == 100 );
950+ }
947951
948- /* Try and get headers again */
949- if (http_status == 100 ) {
950- zend_string_release_ex (http_headers , 0 );
951- }
952+ if (!return_value ) {
953+ /* In this case, the headers were only fetched because client_trace was true. */
954+ if (request != buf ) {
955+ zend_string_release_ex (request , 0 );
956+ }
957+ php_stream_close (stream );
958+ if (http_headers ) {
959+ zend_string_release_ex (http_headers , 0 );
960+ }
961+ convert_to_null (Z_CLIENT_HTTPSOCKET_P (this_ptr ));
962+ convert_to_null (Z_CLIENT_USE_PROXY_P (this_ptr ));
963+ if (http_msg ) {
964+ efree (http_msg );
952965 }
953- } while (http_status == 100 );
966+ smart_str_free (& soap_headers_z );
967+ return true;
968+ }
954969
955970 /* Grab and send back every cookie */
956971
0 commit comments