Skip to content

Commit

Permalink
SimplePieFileGuzzle: Fix autodiscovery
Browse files Browse the repository at this point in the history
In #1052, we introduced a class that allowed us to make SimplePie fetch feeds using Guzzle and then pass headers and content back to it. Unfortunately, SimplePie expects the headers to be lower-case and strings, whereas Guzzle returns original case and string arrays as mandated by PSR-7. This in turn broke autodiscovery.

Closes: #1130
  • Loading branch information
jtojnar committed Sep 16, 2019
1 parent 158c90d commit 2307c23
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions helpers/SimplePieFileGuzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ public function __construct($url, $timeout = 10, $redirects = 5, $headers = null
]);

$this->headers = $response->getHeaders();

// SimplePie expects the headers to be lower-case and strings but Guzzle returns original case and string arrays as mandated by PSR-7.
$this->headers = array_change_key_case($this->headers, CASE_LOWER);
array_walk($this->headers, function(&$value, $header) {
// There can be multiple header values if and only if the header is described as a list, in which case, they can be coalesced into a single string, separated by commas:
// https://tools.ietf.org/html/rfc2616#section-4.2
// Non-compliant servers might send multiple instances of single non-list header; we will use the last value then.
// For Simplicity, we consider every header other than Content-Type a list, since it is what SimplePie does.
if ($header === 'content-type') {
$value = array_pop($value);
} else {
$value = implode(', ', $value);
}
});

// Sequence of fetched URLs
$urlStack = [$url] + $response->getHeader(\GuzzleHttp\RedirectMiddleware::HISTORY_HEADER);
$this->url = $urlStack[count($urlStack) - 1];
Expand Down

1 comment on commit 2307c23

@akash07k
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, going to test

Please sign in to comment.