XSendfile should set the content length to 0
robrwo opened this issue · 6 comments
We removed some homegrown code that set the X-Sendfile header for Apache to use the Plack middleware. The performance was awful.
After some experimentation, and comparison with the original code, it seems that the Content-Length was set to 0.
When adding code to set the Content-Length to 0, this resolved the issue.
When testing with curl directly on the app. a non-zero content length caused a delay while it waited for the content, before timing out. I would assume the reverse proxy would be smarter than that, but apparently not. (I have not found any documentation on this.)
I should add that Content-Length is otherwise set by Catalyst using the ContentLength middleware.
this sounds like a red herring that there's something else that might be in play for the Apache setup...
I suspect something in Apache, but I've not yet found something. Still investigating.
I suspect the issue is the reverse proxy getting confused by the incorrect content-length before it gets handled by mod_xsendfile. Still investigating further.
Actually, the issue is because Catalyst adds the Content-Length header by default. Whether modifying the default middleware in Catalyst to not add Content-Length for this case will fix the issue.
I think the best option is to set the Content-Length to 0, at least for mod_xsendfile as it will remove/update the header as appropriate.
This will also allow it to work with the ContentLength middleware.