From f4d3080c6030eaf884deaa4317a43cbd420ab778 Mon Sep 17 00:00:00 2001 From: Xavier Marchegay Date: Fri, 11 Nov 2022 15:48:31 +0100 Subject: [PATCH] Fix redirection with nginx and http2 --- src/LiveComponent/assets/dist/live_controller.js | 3 ++- src/LiveComponent/assets/src/Component/index.ts | 3 ++- .../src/EventListener/LiveComponentSubscriber.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/LiveComponent/assets/dist/live_controller.js b/src/LiveComponent/assets/dist/live_controller.js index 1824f852d56..8a86fa7a601 100644 --- a/src/LiveComponent/assets/dist/live_controller.js +++ b/src/LiveComponent/assets/dist/live_controller.js @@ -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; } diff --git a/src/LiveComponent/assets/src/Component/index.ts b/src/LiveComponent/assets/src/Component/index.ts index 182489a2a33..6f4e66a8910 100644 --- a/src/LiveComponent/assets/src/Component/index.ts +++ b/src/LiveComponent/assets/src/Component/index.ts @@ -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; diff --git a/src/LiveComponent/src/EventListener/LiveComponentSubscriber.php b/src/LiveComponent/src/EventListener/LiveComponentSubscriber.php index 2e72b5240e9..1785bdd111d 100644 --- a/src/LiveComponent/src/EventListener/LiveComponentSubscriber.php +++ b/src/LiveComponent/src/EventListener/LiveComponentSubscriber.php @@ -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) { @@ -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, ])); }