Skip to content

Commit 843f1dd

Browse files
committed
bug #546 Fix redirection with nginx and http2 (xaviermarchegay)
This PR was merged into the 2.x branch. Discussion ---------- Fix redirection with nginx and http2 | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Tickets | Fix #543 | License | MIT > Let’s drop the header during the redirect (which is when we have an empty body) and, instead, add a 2nd header - something custom like X-Live-Redirect. Then, in the javascript, only throw the error of the content-type is wrong/missing AND that special header is missing. > > I’d welcome a PR of you’re open to it :) Commits ------- f4d3080 Fix redirection with nginx and http2
2 parents 0048027 + f4d3080 commit 843f1dd

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/LiveComponent/assets/dist/live_controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,8 @@ class Component {
15171517
const backendResponse = new BackendResponse(response);
15181518
thisPromiseResolve(backendResponse);
15191519
const html = await backendResponse.getBody();
1520-
if (backendResponse.response.headers.get('Content-Type') !== 'application/vnd.live-component+html') {
1520+
const headers = backendResponse.response.headers;
1521+
if (headers.get('Content-Type') !== 'application/vnd.live-component+html' && !headers.get('X-Live-Redirect')) {
15211522
this.renderError(html);
15221523
return response;
15231524
}

src/LiveComponent/assets/src/Component/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ export default class Component {
302302
thisPromiseResolve(backendResponse);
303303
const html = await backendResponse.getBody();
304304
// if the response does not contain a component, render as an error
305-
if (backendResponse.response.headers.get('Content-Type') !== 'application/vnd.live-component+html') {
305+
const headers = backendResponse.response.headers;
306+
if (headers.get('Content-Type') !== 'application/vnd.live-component+html' && !headers.get('X-Live-Redirect')) {
306307
this.renderError(html);
307308

308309
return response;

src/LiveComponent/src/EventListener/LiveComponentSubscriber.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
class LiveComponentSubscriber implements EventSubscriberInterface, ServiceSubscriberInterface
4848
{
4949
private const HTML_CONTENT_TYPE = 'application/vnd.live-component+html';
50+
private const REDIRECT_HEADER = 'X-Live-Redirect';
5051

5152
public function __construct(private ContainerInterface $container)
5253
{
@@ -282,7 +283,7 @@ public function onKernelResponse(ResponseEvent $event): void
282283

283284
$event->setResponse(new Response(null, 204, [
284285
'Location' => $response->headers->get('Location'),
285-
'Content-Type' => self::HTML_CONTENT_TYPE,
286+
self::REDIRECT_HEADER => 1,
286287
]));
287288
}
288289

0 commit comments

Comments
 (0)