Skip to content

File: expose headers on failure#930

Open
jtojnar wants to merge 4 commits intosimplepie:masterfrom
jtojnar:wip/jtojnar/file-error-headers
Open

File: expose headers on failure#930
jtojnar wants to merge 4 commits intosimplepie:masterfrom
jtojnar:wip/jtojnar/file-error-headers

Conversation

@jtojnar
Copy link
Member

@jtojnar jtojnar commented Jul 28, 2025

Tries to fix #905 (comment)

@jtojnar jtojnar force-pushed the wip/jtojnar/file-error-headers branch from b82278d to 7441fae Compare July 28, 2025 08:02
@pull-request-size pull-request-size bot added size/S and removed size/M labels Jul 28, 2025
@jtojnar jtojnar force-pushed the wip/jtojnar/file-error-headers branch 2 times, most recently from 909bd36 to 1a6aa8b Compare July 29, 2025 00:03
@pull-request-size pull-request-size bot added size/M and removed size/S labels Jul 29, 2025
*
* @return array<string, string[]>
*/
public function get_http_headers(): array
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if we want to have this. Maybe exposing Response will be better.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this new method is a reasonable compromise. Once we have exposed the Response class or implemented #190, we will be able to deprecate many methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

One issue is that the File turns all header names to lowercase, while Psr7Response keeps the original casing. So it is inconsistent between clients.

Ideally, we would keep the introduction of new methods minimal but with Psr7Response response behaviour, if user is interseted in a specific header, they would need to lowercase it themselves, which is inconvenient.

@jtojnar jtojnar requested a review from Art4 July 29, 2025 07:16
@jtojnar jtojnar marked this pull request as ready for review July 29, 2025 23:15

$this->assertFalse($return);
$this->assertSame(429, $simplepie->status_code());
$this->assertSame(['3600'], $simplepie->get_http_header('Retry-After'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe adding a test for SimplePie::get_http_headers() as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, looking at the headers, most of them are set by PHP test server itself so we probably cannot rely on them remaining consistent:

'Host' => Array &1 [
   0 => '127.0.0.1:39477',
],
'Date' => Array &2 [
   0 => 'Fri, 01 Aug 2025 08:57:44 GMT',
],
'Connection' => Array &3 [
   0 => 'close',
],
'X-Powered-By' => Array &4 [
   0 => 'PHP/8.4.8',
],
'Retry-After' => Array &5 [
    0 => '3600',
],
'Content-type' => Array &6 [
   0 => 'text/html; charset=UTF-8',
],

Copy link
Contributor

@Art4 Art4 Aug 1, 2025

Choose a reason for hiding this comment

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

Could you add a unit test with a mocked response instead?

If we enable `CURLOPT_FAILONERROR`, `curl_exec` will return `false` on HTTP error
so we would not get access to response and thus unable to parse headers.

Reverts 9b5f209
@jtojnar jtojnar force-pushed the wip/jtojnar/file-error-headers branch 2 times, most recently from c2b9531 to 98917bd Compare August 1, 2025 08:58
jtojnar added 3 commits August 1, 2025 11:00
Currently, the `SimplePie::$data` property is only marked `@access private` using a PHPDoc comment so consumers can access HTTP headers in that. But when we mark it as private later, there would be no way to obtain HTTP headers.
@jtojnar jtojnar force-pushed the wip/jtojnar/file-error-headers branch from 98917bd to d6077f7 Compare August 1, 2025 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants