Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/Models/HttpPaginatedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,36 @@ public function __construct( \Ably\AblyRest $ably, $model, $cipherParams,
}
}

private function parseHeaders( $headers ) {
private function parseHeaders($headers) {
$headers = explode("\n", $headers);
$http = array_shift($headers);
$http = explode(' ', $http);

$this->statusCode = $http[1] * 1;
$this->headers = [];
$this->statusCode = null;

foreach ($headers as $header) {
if (!trim($header)) {
continue;
}

// Handle HTTP status lines, there could be more
if (strncmp($header, 'HTTP/', 5) === 0) {
$http = explode(' ', trim($header));
if (isset($http[1]) && is_numeric($http[1])) {
$this->statusCode = (int) $http[1];
}

// Reset headers for new response block
$this->headers = [];
continue;
}

if (!str_contains($header, ':')) {
continue;
}
Comment thread
basmilius marked this conversation as resolved.
Outdated

foreach($headers as $header) {
if(!trim($header)) continue;
list($key, $value) = explode(':', $header, 2);
$key = trim($key);

// Title-Case
$key = preg_replace_callback('/\w+/', function ($match) {
return ucfirst(strtolower($match[0]));
}, $key);
Expand Down