summaryrefslogtreecommitdiffstats
path: root/src/PurpleCode/PCurl/PCurl.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/PurpleCode/PCurl/PCurl.php')
-rw-r--r--src/PurpleCode/PCurl/PCurl.php23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/PurpleCode/PCurl/PCurl.php b/src/PurpleCode/PCurl/PCurl.php
index 4c2a428..9af612c 100644
--- a/src/PurpleCode/PCurl/PCurl.php
+++ b/src/PurpleCode/PCurl/PCurl.php
@@ -38,8 +38,8 @@ class PCurl {
$this->setOption(CURLOPT_SSL_VERIFYPEER, true);
// should curl_exec return response, not print it on stdout
$this->setOption(CURLOPT_RETURNTRANSFER, true);
- // should not include headers in response
- $this->setOption(CURLOPT_HEADER, 0);
+ // should include headers in response
+ $this->setOption(CURLOPT_HEADER, 1);
}
/**
@@ -103,8 +103,16 @@ class PCurl {
curl_close($curl);
throw new PCurlException($error);
}
+
+ $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
curl_close($curl);
- return $response;
+
+ $header = substr($response, 0, $header_size);
+ $body = substr($response, $header_size);
+
+ $processedResponse = $this->postProcessResponseBody($header, $body);
+
+ return $body;
}
/**
@@ -137,6 +145,15 @@ class PCurl {
}
/**
+ * Allow to postprocess response body, ex. parse to specified format.
+ * @param string $header
+ * @param string $body
+ */
+ protected function postProcessResponseBody($header, $body){
+ return $body;
+ }
+
+ /**
* @return PCurl
*/
public function headers(array $headers) {