Skip to content

Commit

Permalink
Merge pull request #5 from sebdelta/master
Browse files Browse the repository at this point in the history
Update deprecated use of /e modifier with preg_replace
  • Loading branch information
swimson committed Apr 6, 2017
2 parents c239bbc + 7f0f28b commit e47451d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/CachedReverseProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ public function getHTTPStatusCode(Response $response)
}

foreach ($response->headers as $header) {
if (preg_match("#^HTTP/\S+\s+(\d\d\d)#i", $header, $matches)) {

if (preg_match_all("#^HTTP/\S+\s+(\d\d\d)#i", $header, $matches)) {
return $matches[1];
}
}
Expand All @@ -154,17 +155,23 @@ public function parseHTTPHeaders($header)
$retVal = array();
$fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header));
foreach ($fields as $field) {
if (preg_match('/([^:]+): (.+)/m', $field, $match)) {
$match[1] = preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1])));
if (isset($retVal[$match[1]])) {
$retVal[$match[1]] = array($retVal[$match[1]], $match[2]);
if (preg_match_all('/([^:]+): (.+)/m', $field, $match)) {
$match[1][0] = preg_replace_callback(
'/(?<=^|[\x09\x20\x2D])./',
function ($matches) {
return strtolower($matches[0]);
},
strtolower(trim($match[1][0]))
);
if (isset($retVal[$match[1][0]])) {
$retVal[$match[1][0]] = array($retVal[$match[1][0]], $match[2][0]);
} else {
$retVal[$match[1]] = trim($match[2]);
$retVal[$match[1][0]] = trim($match[2][0]);
}
}
}

return $retVal;

}
}
}

0 comments on commit e47451d

Please sign in to comment.