ux icon indicating copy to clipboard operation
ux copied to clipboard

[Live] With nginx and http2, the "Content-Type" header is stripped in a 204 response

Open xaviermarchegay opened this issue 4 years ago • 2 comments

Pre-requisites:

  • nginx with http2
  • redirection in a LiveAction
  • symfony/ux-live-component v2.5.0

Steps:

  • Any redirection in a controller with a LiveAction
  • Symfony returns a 204 response with a specific header Content-Type - \Symfony\UX\LiveComponent\EventListener
  • Nginx drops the header - https://trac.nginx.org/nginx/ticket/2109
  • Symfony displays an error because the header is missing - https://github.com/symfony/ux/blob/2.x/src/LiveComponent/assets/dist/live_controller.js#L1520

Technically it is a nginx bug but a 204 response means "no content" so it is confusing to have a content type header when there is none? Moreover nginx does not seem in a hurry to fix it (2 years and counting) so I think it should be fixed in this package. Maybe simply an other header or another way to detect errors?

xaviermarchegay avatar Nov 10 '22 20:11 xaviermarchegay

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 :)

weaverryan avatar Nov 11 '22 11:11 weaverryan

@weaverryan done :)

xaviermarchegay avatar Nov 11 '22 14:11 xaviermarchegay