Fix slow MP4 playback via proxy (switch to net/http streaming + range handling)#710
Conversation
5rahim
left a comment
There was a problem hiding this comment.
thanks for the PR, but i think this is trying to fix an issue buy doing too much at once, it should be scoped to the issue at hand first (which is the non-HLS path).
i'd suggest testing things step by step, e.g. as i see it, the likely culprit can be: the timeout length from the req client, compression or hopbyhop header or all three combined. if that doesn't do it you can then conditionally keep the content-length header like you're doing. if that still doesn't do it you could first, try to overwrite the content-type, then replace c.Stream and so on.
that way in the end, we know what the root cause is for future reference.
|
I tested the changes step-by-step (timeout, identity/no compression, hop-by-hop headers, conditional Content-Length, and replacing c.Stream). The only change that consistently fixed it was switching the non-HLS upstream fetch from req/v3 to net/http (with HTTP/2 off + identity/no compression). |
|
i investigated further since you said that req/v3 was the bottleneck and indeed simply adding DisableAutoReadResponse() fixed it because it was buffering the vid until timeout. |
|
i can still merge it as a contribution but you'll have to revert everything and add DisableAutoReadResponse(). after req.C()., the other changes aren't necessary |
Removed unused videoProxyHTTPClient and related code for upstream requests. Updated header handling to use videoProxyClient2.
Removed comment about handling marshalling errors in toProxyURL function.
Removed unused 'time' import from proxy.go
|
|
Summary
This PR fixes very slow playback for certain proxied MP4 streams by changing the proxy’s upstream HTTP behavior and response semantics to better match what browsers/video players expect.
Changes
Use net/http client + custom transport for upstream requests:
Strip RFC7230 hop-by-hop headers when proxying upstream headers.
For non-HLS responses:
Preserve upstream status code for HLS playlist responses.