Commit 50a7734
committed
Fix ChunkedBody double-encoding under Rack 3 / Rackup
Rack 2's Rack::Handler::WEBrick uses a monkey-patch on
WEBrick::HTTPResponse#setup_header that sets @Chunked = true only during
header setup (so Transfer-Encoding: chunked is emitted), then immediately
restores @Chunked = false. This means WEBrick's send_body_string sends the
response body as-is, relying on ChunkedBody to have pre-encoded it.
Rackup 2.x's WEBrick handler takes the opposite approach: it buffers the
entire body into a String, and WEBrick's []= setter permanently sets
@Chunked = true when Transfer-Encoding: chunked is assigned, so WEBrick
chunks the plain String itself. Pre-encoding with ChunkedBody under Rack 3
therefore produced double-chunked wire data that Net::HTTP decoded to raw
chunk markers instead of the actual response body.
Introduce a rack_v3? helper and guard the ChunkedBody wrapping behind it:
under Rack 3 return the plain body (callable or enumerable) and let the
server apply a single layer of chunked encoding; under Rack 2 keep the
existing ChunkedBody behaviour.1 parent a5a3e92 commit 50a7734
1 file changed
Lines changed: 24 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
87 | 96 | | |
88 | | - | |
89 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
90 | 105 | | |
91 | 106 | | |
92 | 107 | | |
| |||
112 | 127 | | |
113 | 128 | | |
114 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
115 | 135 | | |
116 | 136 | | |
117 | 137 | | |
| |||
0 commit comments