Skip to content

Fix redirection with nginx and http2 #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/LiveComponent/assets/dist/live_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,8 @@ class Component {
const backendResponse = new BackendResponse(response);
thisPromiseResolve(backendResponse);
const html = await backendResponse.getBody();
if (backendResponse.response.headers.get('Content-Type') !== 'application/vnd.live-component+html') {
const headers = backendResponse.response.headers;
if (headers.get('Content-Type') !== 'application/vnd.live-component+html' && !headers.get('X-Live-Redirect')) {
this.renderError(html);
return response;
}
Expand Down
3 changes: 2 additions & 1 deletion src/LiveComponent/assets/src/Component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ export default class Component {
thisPromiseResolve(backendResponse);
const html = await backendResponse.getBody();
// if the response does not contain a component, render as an error
if (backendResponse.response.headers.get('Content-Type') !== 'application/vnd.live-component+html') {
const headers = backendResponse.response.headers;
if (headers.get('Content-Type') !== 'application/vnd.live-component+html' && !headers.get('X-Live-Redirect')) {
this.renderError(html);

return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
class LiveComponentSubscriber implements EventSubscriberInterface, ServiceSubscriberInterface
{
private const HTML_CONTENT_TYPE = 'application/vnd.live-component+html';
private const REDIRECT_HEADER = 'X-Live-Redirect';

public function __construct(private ContainerInterface $container)
{
Expand Down Expand Up @@ -282,7 +283,7 @@ public function onKernelResponse(ResponseEvent $event): void

$event->setResponse(new Response(null, 204, [
'Location' => $response->headers->get('Location'),
'Content-Type' => self::HTML_CONTENT_TYPE,
self::REDIRECT_HEADER => 1,
]));
}

Expand Down