Skip to content

call end() when redirecting#15014

Merged
brandonkelly merged 3 commits into4.xfrom
bugfix/prevent-redirect-recursion
May 17, 2024
Merged

call end() when redirecting#15014
brandonkelly merged 3 commits into4.xfrom
bugfix/prevent-redirect-recursion

Conversation

@timkelty
Copy link
Copy Markdown
Contributor

Description

Without this, redirects can cause Response::send() to be called multiple times, causing HeadersAlreadySentException to be thrown.

Example:

  • A controller calls $this->response->sendFile()
  • A listener on \yii\web\Response::EVENT_AFTER_PREPARE calls Response::redirect()
  • That triggers another Response::send(), which sends headers
  • The remaining calls to Response::send() (from $app->run) attempt to send headers, throwing HeadersAlreadySentException.

@timkelty timkelty requested a review from brandonkelly May 16, 2024 20:27
@brandonkelly brandonkelly merged commit df84dc4 into 4.x May 17, 2024
@brandonkelly brandonkelly deleted the bugfix/prevent-redirect-recursion branch May 17, 2024 19:54
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.

2 participants