Skip to content

Commit 51a9bcb

Browse files
committed
Merge pull request #5 from honzatrtik/master
fixed issue with incorrect http status & content type if request was redirected
2 parents f1dae2d + 4c4563c commit 51a9bcb

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Resty.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,20 @@ protected function metaToHeaders($meta) {
634634
*/
635635
protected function getStatusCode($meta) {
636636
$matches = array();
637+
638+
// We need last http status
639+
$statusHeader = NULL;
640+
foreach(array_reverse($meta['wrapper_data']) as $header)
641+
{
642+
if (strpos($header, 'HTTP') === 0)
643+
{
644+
$statusHeader = $header;
645+
break;
646+
}
647+
}
648+
637649
$status = 0;
638-
preg_match("|\s(\d\d\d)\s?|", $meta['wrapper_data'][0], $matches);
650+
preg_match("|\s(\d\d\d)\s?|", $statusHeader, $matches);
639651
if (is_array($matches) && isset($matches[1])) {
640652
$status = (int)trim($matches[1]);
641653
}
@@ -854,6 +866,13 @@ protected function processResponseBody($resp) {
854866
if ($this->parse_body === true) {
855867

856868
$header_content_type = isset($resp['headers']['Content-Type']) ? $resp['headers']['Content-Type'] : null;
869+
870+
// If redirected, we use last Content-Type
871+
if (is_array($header_content_type))
872+
{
873+
$header_content_type = end($header_content_type);
874+
}
875+
857876
$content_type = preg_split('/[;\s]+/', $header_content_type);
858877
$content_type = $content_type[0];
859878

0 commit comments

Comments
 (0)