Skip to content

Proxy: Preserve HTTP response headers and safely rewrite HLS. v8.0.20 - #4718

Merged
winlinvip merged 3 commits into
ossrs:developfrom
winlinvip:develop
Aug 13, 2026
Merged

Proxy: Preserve HTTP response headers and safely rewrite HLS. v8.0.20#4718
winlinvip merged 3 commits into
ossrs:developfrom
winlinvip:develop

Conversation

@winlinvip

@winlinvip winlinvip commented Aug 13, 2026

Copy link
Copy Markdown
Member

Summary

  • Preserve end-to-end backend response headers for HTTP-FLV, HTTP-TS, and HLS responses.
  • Remove standard hop-by-hop headers and additional fields nominated by Connection.
  • Rewrite HLS segment URLs with a canonical single & when the original URL already has query parameters.
  • Repair response metadata after modifying an m3u8 body, and add wire-level regression coverage.

Problem

The HTTP proxy called WriteHeader before copying headers from the backend. Go commits the response at that point, so later additions such as Content-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:

segment.ts?spbhid=xxx&&token=abc

Moving header copying before WriteHeader is not sufficient by itself. An m3u8 playlist is modified when the proxy inserts spbhid, so the backend's original Content-Length, strong ETag, digest, content encoding, and range metadata no longer describe the downstream representation. Forwarding the stale length can make Go reject the enlarged response with http: 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-Length and remove stale validators, digests, encodings, and range metadata when the playlist body changes.

  • Generate existing-query segment URLs as:

    segment.ts?spbhid=xxx&token=abc
    
  • Add real HTTP-boundary tests for header preservation, hop-by-hop removal, query rewriting, complete playlist delivery, and rewritten-body metadata.

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>
@winlinvip winlinvip changed the title Codex: Fix HTTP proxy response headers. Proxy: Preserve HTTP response headers and safely rewrite HLS. v8.0.20 Aug 13, 2026
@winlinvip
winlinvip merged commit 326b5fa into ossrs:develop Aug 13, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant