Skip to content

[4.x] Fix redirects in the stream transport - #82

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-stream-redirects
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-stream-redirects

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

The stream transport failed on every redirect. With follow_location enabled (the default), PHP's http wrapper puts the headers of every response in the chain into wrapper_data. The transport took the status code of the first response (e.g. 302) and turned each further status line (HTTP/1.1 200 OK) into a header without a name, which Diactoros rejects:

(new Http([], new Stream([])))->get('http://example.test/redirecting-url');
// Laminas\Diactoros\Exception\InvalidArgumentException: "" is not valid header name

This change keeps only the header block of the last response, and AbstractTransport::processHeaders() now skips lines that are not Name: value headers instead of creating a header with an empty name.

Testing Instructions

Tests/Transport/StreamRedirectTest.php (new) uses the new Tests/stubs/redirect.php, which redirects a configurable number of times with a relative Location before reaching jhttp_stub.php:

  • following two redirects returns the 200 of jhttp_stub.php without the Location header of the redirects (fails before the change with the exception above);
  • with follow_location => false the 302 and its Location are returned.

Serve the stubs and run the suite: php -S 127.0.0.1:8080 -t Tests/stubs, then vendor/bin/phpunit (CI does the same).

Documentation Changes Required

docs/classes/TransportInterface.md: the options table now lists the stream transport for follow_location and says that the response at the end of the chain is returned.

Related to #81 (transport test setup); both PRs touch Tests/, but not the same files.

🤖 Generated with Claude Code

With follow_location enabled, which is the default, PHP's http wrapper lists
the headers of every response in the redirect chain. The transport took the
status code of the first response and turned each further status line into
a header without a name, which Diactoros rejects, so every redirect ended in
an InvalidArgumentException.

Use only the headers of the last response and skip lines that are not
headers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Hackwar

Hackwar commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant