Skip to content

Commit 1e1e3c4

Browse files
Cleaning up code, removing not required substr end positions
1 parent 2317de1 commit 1e1e3c4

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/MaileonAPIResult.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,17 @@ private function getHeaderArrayFromCurlResponse($curlSession, $response)
5959
{
6060
$headers = array();
6161

62-
$start = 0;
63-
6462
$headerSize = curl_getinfo( $curlSession , CURLINFO_HEADER_SIZE );
6563

66-
// The header is separated by \n\r\n\r, so trim those 4 bytes from the header as we do not need them
67-
$header_text = substr($response, $start, $headerSize-4);
64+
// The header sectionsis separated by \n\r\n\r, so trim those 4 bytes from the header as we do not need them
65+
$header_text = substr($response, 0, $headerSize-4);
6866

69-
// Check if there is a proxy header. If so, select last header section (from Maileon)
67+
// Check if there is a proxy header section. If so, select last header section (from Maileon)
7068
// Maybe it makes sense to return an array with one entry for each header section (proxies, then normal headers), each containing the entries of the apropriate header section.
7169
// As this is not backwards compatible, skip for now.
7270
if (strpos($header_text, "\r\n\r\n") !== false) {
7371
$start = strrpos($header_text, "\r\n\r\n")+4;
74-
$header_text = substr($header_text, $start, strlen($header_text));
72+
$header_text = substr($header_text, $start);
7573
}
7674

7775
foreach (explode("\r\n", $header_text) as $i => $line) {
@@ -92,8 +90,9 @@ private function getBodyFromCurlResponse($curlSession, $response)
9290
{
9391
// In a recent case, a CMS2 mailing contained \r\n\r\n, so the old approach failed (https://stackoverflow.com/questions/10589889/returning-header-as-array-using-curl).
9492
// Now, we use CURLINFO_HEADER_SIZE (https://blog.devgenius.io/how-to-get-the-response-headers-with-curl-in-php-2173b10d4fc5) and only split up the headers at \r\n\r\n.
95-
$headerSize = curl_getinfo( $curlSession , CURLINFO_HEADER_SIZE );
96-
return substr($response, $headerSize, strlen($response));
93+
// CURLINFO_HEADER_SIZE returns the size of the header including \r\n\r\n.
94+
$headerSize = curl_getinfo( $curlSession , CURLINFO_HEADER_SIZE);
95+
return substr($response, $headerSize);
9796
}
9897

9998
private function checkResult($throwException)

0 commit comments

Comments
 (0)