Proxy: Preserve HTTP response headers and safely rewrite HLS. v8.0.20 - #4718
Merged
Conversation
Preserve end-to-end backend metadata while removing hop-by-hop fields, and repair representation headers after rewriting HLS playlists. Add wire-level regression coverage for HLS and HTTP-FLV responses. --------- Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Connection.&when the original URL already has query parameters.Problem
The HTTP proxy called
WriteHeaderbefore copying headers from the backend. Go commits the response at that point, so later additions such asContent-Type,Cache-Control,ETag,Last-Modified,Vary, and custom origin metadata never reached the downstream client.HLS playlist rewriting also generated segment URLs containing an unnecessary empty query component:
Moving header copying before
WriteHeaderis not sufficient by itself. An m3u8 playlist is modified when the proxy insertsspbhid, so the backend's originalContent-Length, strongETag, digest, content encoding, and range metadata no longer describe the downstream representation. Forwarding the stale length can make Go reject the enlarged response withhttp: wrote more than the declared Content-Length.A proxy must also avoid forwarding connection-specific headers to the next hop.
Changes
Copy backend end-to-end headers before committing HTTP-FLV, HTTP-TS, and HLS responses.
Strip
Connection, its nominated fields, and the standard proxy/connection-specific header set.Keep byte-transparent FLV and TS representation metadata unchanged.
Read and rewrite m3u8 playlists before sending response headers.
Recompute
Content-Lengthand remove stale validators, digests, encodings, and range metadata when the playlist body changes.Generate existing-query segment URLs as:
Add real HTTP-boundary tests for header preservation, hop-by-hop removal, query rewriting, complete playlist delivery, and rewritten-body metadata.