@@ -120,7 +120,7 @@ public function sendRequest($method, $url, $data = array(), $options = array())
120
120
public function getHeaders ($ url , $ data = array (), $ options = array ()) {
121
121
$ headers = array ();
122
122
if ($ res = $ this ->head ($ url , $ data = array (), $ options = array ())) {
123
- $ headers = $ this -> parseHeader ( $ res );
123
+ $ headers = $ res -> getHeaders ( );
124
124
}
125
125
return $ headers ;
126
126
}
@@ -311,7 +311,9 @@ public function execute($url = '') {
311
311
return false ;
312
312
}
313
313
314
- isset ($ this ->options [CURLOPT_RETURNTRANSFER ]) or $ this ->options [CURLOPT_RETURNTRANSFER ] = true ;
314
+ $ this ->options [CURLOPT_HEADER ] = true ;
315
+ $ this ->options [CURLOPT_RETURNTRANSFER ] = true ;
316
+
315
317
isset ($ this ->options [CURLOPT_TIMEOUT ]) or $ this ->options [CURLOPT_TIMEOUT ] = $ this ->timeout ;
316
318
isset ($ this ->options [CURLOPT_FAILONERROR ]) or $ this ->options [CURLOPT_FAILONERROR ] = $ this ->strict_mode ;
317
319
@@ -345,7 +347,13 @@ public function execute($url = '') {
345
347
$ response = $ this ->response ;
346
348
curl_close ($ this ->request );
347
349
$ this ->clear ();
348
- return $ response ;
350
+
351
+ $ header_size = $ this ->info ['header_size ' ];
352
+ $ http_code = $ info ['http_code ' ];
353
+ $ headers = substr ($ response , 0 , $ header_size );
354
+ $ body = substr ($ response , $ header_size );
355
+
356
+ return new CurlResponse ($ response , $ headers , $ body , $ http_code );
349
357
}
350
358
} else {
351
359
$ this ->clear ();
@@ -397,21 +405,6 @@ public function errorMsg() {
397
405
return $ this ->error_msg ;
398
406
}
399
407
400
- /**
401
- * Parse raw header text
402
- * @param string $raw_header
403
- */
404
- public function parseHeader ($ raw_header ) {
405
- $ headers = array ();
406
- foreach (explode ("\r\n" , trim ($ raw_header , "\r\n" )) as $ line ) {
407
- if (strpos ($ line , ': ' ) !== false ) {
408
- list ($ key , $ value ) = explode (': ' , $ line , 2 );
409
- $ headers [trim ($ key )] = trim ($ value );
410
- }
411
- }
412
- return $ headers ;
413
- }
414
-
415
408
protected function initialize ($ config ) {
416
409
if (is_array ($ config )) {
417
410
isset ($ config ['timeout ' ]) and $ this ->timeout = $ config ['timeout ' ];
0 commit comments