range requests can return a full 200 response, upstream
I think I figured out why the pleroma media cache is serving up files abruptly cut off at roughly 1 megabyte, giving you only a glitchy slice of the top of larger pictures.
Some (stupid) webservers will return code 200 when you include a "Range: " header in your request. The response body will be the full file, ignoring any range request. Unfortunately, that leaves the burden to the proxy to correctly adjust that to a 206 response code, and to only send the requested range of the body. Currently, nginx fails horribly and messily at this, so if your web browser requests a Range: and the webserver upstream from nginx returns a full 200 response, nginx just cuts off the file halfway through, logs an error, and fails.
[error] *26006 unexpected status code 200 in slice response while reading response header from upstream,
The problem is when we try to cache our URLs locally via /proxy/ pleroma will properly send the Range: request upstream, and then send the erroneous 200 response downstream to nginx, where nginx expects a 206 response and flips out. So pleroma's not flipping out, but there needs to be logic in lib/pleroma/web/reverse_proxy.ex that will itself cache an erroneous 200 response, and then serve the requested 206 response from a piece of that cache. That should stop nginx from killing the connection halfway through sending the cached file.
So currently:
Browser -> Range -> nginx -> Range -> pleroma -> Range -> stupidsite.com
Browser <- Hissy fit, broken file <- nginx <- 200 <- pleroma <- 200 <- stupidsite.com
And what's needed:
Browser -> Range -> nginx -> Range -> pleroma -> Range -> stupidsite.com
Browser <- Full file <- nginx <- 206 <- pleroma <- 200 <- stupidsite.com
↳ super special cache for serving 206es
This sounds like a lot of trouble, and I've no idea where one would store this cache for a cache, so it's okay if you leave images broken in the pleroma interface for now. I just wanted to give a crack at the reason behind this problem. It might not even be the problem, so it's just my best guess at what it is. Maybe I'm just configuring nginx wrong.