@@ -279,6 +279,36 @@ private function parseRequestHeaders($raw_headers)
279
279
return $ request_headers ;
280
280
}
281
281
282
+ private function parseResponse ($ response )
283
+ {
284
+ $ response_headers = '' ;
285
+ if (!(strpos ($ response , "\r\n\r\n" ) === false )) {
286
+ list ($ response_header , $ response ) = explode ("\r\n\r\n" , $ response , 2 );
287
+ if ($ response_header === 'HTTP/1.1 100 Continue ' ) {
288
+ list ($ response_header , $ response ) = explode ("\r\n\r\n" , $ response , 2 );
289
+ }
290
+ $ response_headers = $ this ->parseResponseHeaders ($ response_header );
291
+
292
+ if (isset ($ response_headers ['Content-Type ' ])) {
293
+ if (preg_match ('/^application\/json/i ' , $ response_headers ['Content-Type ' ])) {
294
+ $ json_obj = json_decode ($ response , false );
295
+ if (!is_null ($ json_obj )) {
296
+ $ response = $ json_obj ;
297
+ }
298
+ } elseif (preg_match ('/^application\/rss\+xml/i ' , $ response_headers ['Content-Type ' ]) ||
299
+ preg_match ('/^application\/xml/i ' , $ response_headers ['Content-Type ' ]) ||
300
+ preg_match ('/^text\/xml/i ' , $ response_headers ['Content-Type ' ])) {
301
+ $ xml_obj = @simplexml_load_string ($ response );
302
+ if (!($ xml_obj === false )) {
303
+ $ response = $ xml_obj ;
304
+ }
305
+ }
306
+ }
307
+ }
308
+
309
+ return array ($ response_headers , $ response );
310
+ }
311
+
282
312
private function parseResponseHeaders ($ raw_headers )
283
313
{
284
314
$ response_headers = new CaseInsensitiveArray ();
@@ -336,30 +366,7 @@ protected function exec($_ch = null)
336
366
$ ch ->error_code = $ ch ->error ? ($ ch ->curl_error ? $ ch ->curl_error_code : $ ch ->http_status_code ) : 0 ;
337
367
338
368
$ ch ->request_headers = $ this ->parseRequestHeaders (curl_getinfo ($ ch ->curl , CURLINFO_HEADER_OUT ));
339
- $ ch ->response_headers = '' ;
340
- if (!(strpos ($ ch ->response , "\r\n\r\n" ) === false )) {
341
- list ($ response_header , $ ch ->response ) = explode ("\r\n\r\n" , $ ch ->response , 2 );
342
- if ($ response_header === 'HTTP/1.1 100 Continue ' ) {
343
- list ($ response_header , $ ch ->response ) = explode ("\r\n\r\n" , $ ch ->response , 2 );
344
- }
345
- $ ch ->response_headers = $ this ->parseResponseHeaders ($ response_header );
346
-
347
- if (isset ($ ch ->response_headers ['Content-Type ' ])) {
348
- if (preg_match ('/^application\/json/i ' , $ ch ->response_headers ['Content-Type ' ])) {
349
- $ json_obj = json_decode ($ ch ->response , false );
350
- if (!is_null ($ json_obj )) {
351
- $ ch ->response = $ json_obj ;
352
- }
353
- } elseif (preg_match ('/^application\/rss\+xml/i ' , $ ch ->response_headers ['Content-Type ' ]) ||
354
- preg_match ('/^application\/xml/i ' , $ ch ->response_headers ['Content-Type ' ]) ||
355
- preg_match ('/^text\/xml/i ' , $ ch ->response_headers ['Content-Type ' ])) {
356
- $ xml_obj = @simplexml_load_string ($ ch ->response );
357
- if (!($ xml_obj === false )) {
358
- $ ch ->response = $ xml_obj ;
359
- }
360
- }
361
- }
362
- }
369
+ list ($ ch ->response_headers , $ ch ->response ) = $ this ->parseResponse ($ ch ->response );
363
370
364
371
$ ch ->http_error_message = '' ;
365
372
if ($ ch ->error ) {
0 commit comments