Commit 326b5fa
Proxy: Preserve HTTP response headers and safely rewrite HLS. v8.0.20 (#4718)
## 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:
```text
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:
```text
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.
---------
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>1 parent b666bd6 commit 326b5fa
5 files changed
Lines changed: 383 additions & 19 deletions
File tree
- internal
- proxy
- version
- trunk
- doc
- src/core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
47 | 101 | | |
48 | 102 | | |
49 | 103 | | |
| |||
347 | 401 | | |
348 | 402 | | |
349 | 403 | | |
350 | | - | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
351 | 407 | | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | 408 | | |
358 | 409 | | |
359 | 410 | | |
| |||
476 | 527 | | |
477 | 528 | | |
478 | 529 | | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | 530 | | |
488 | 531 | | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
489 | 535 | | |
490 | 536 | | |
491 | 537 | | |
| |||
500 | 546 | | |
501 | 547 | | |
502 | 548 | | |
503 | | - | |
| 549 | + | |
| 550 | + | |
504 | 551 | | |
505 | | - | |
| 552 | + | |
506 | 553 | | |
507 | 554 | | |
508 | 555 | | |
509 | 556 | | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
510 | 563 | | |
511 | 564 | | |
512 | 565 | | |
| |||
0 commit comments