Proxy: Fix HLS proxy response header loss and m3u8 URL query parameter corruption#4658
Open
sevico wants to merge 2 commits into
Open
Proxy: Fix HLS proxy response header loss and m3u8 URL query parameter corruption#4658sevico wants to merge 2 commits into
sevico wants to merge 2 commits into
Conversation
6ce415e to
6ee6f1c
Compare
…r corruption 1. Move WriteHeader() after setting response headers. In Go's http.ResponseWriter, headers set after WriteHeader() are silently ignored, which caused all backend response headers (Content-Type, Cache-Control, etc.) to be lost during HLS proxying. 2. Fix double ampersand (&&) in m3u8 ts URL rewriting. When the original ts URL already contains query parameters, the proxy generated malformed URLs like ".ts?spbhid=xxx&&token=abc" instead of ".ts?spbhid=xxx&token=abc".
044fb3c to
4fa87de
Compare
1. Fix test expectation: change && to & in m3u8 rewrite test 2. Add TestHLSPlayStream_ServeByBackend_HeadersCopiedFromBackend to verify backend headers reach the client for m3u8 responses 3. Add TestHLSPlayStream_ServeByBackend_TSHeadersCopiedFromBackend to verify header copy for .ts file responses 4. Add TestHTTPFlvTsConn_ServeByBackend_HeadersCopiedFromBackend to verify header copy for FLV/TS streaming responses These tests protect against regression where calling WriteHeader() before Header.Add() causes headers to be silently discarded by Go's http.ResponseWriter.
suzp1984
approved these changes
May 19, 2026
Contributor
suzp1984
left a comment
There was a problem hiding this comment.
Approve
I added the UT to cover the committed code.
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.
Problem
Two bugs in the HLS proxy handler (
internal/protocol/http.go):1. Response headers lost during HLS proxying
WriteHeader()is called before copying backend response headers. In Go'shttp.ResponseWriter, headers set afterWriteHeader()are silently ignored. This causes all backend headers (Content-Type,Cache-Control, etc.) to be dropped.2. Double ampersand (
&&) in m3u8 ts URL rewritingWhen the original
.tsURL already contains query parameters (e.g.,.ts?token=abc), the proxy generates malformed URLs:Fix
WriteHeader()after setting response headers (both streaming and HLS handlers).&&to&in the m3u8 URL rewriting logic.Impact
.tssegments have existing query parameters, because&&is not a valid URL separator.