Commit 3a5fa84
committed
Normalise response headers to lowercase; fix Set-Cookie for Rack 3
Two related problems prevented cookies from being sent correctly under
Rack 3 with WEBrick 1.9:
1. Header key casing: Rackup's WEBrick handler looks up the cookie header
with headers.delete('set-cookie') (lowercase). The previous code
produced Title-Case keys via HeaderHash#flattened, so the lookup never
matched and cookies were left in the general headers loop where they
were passed to res[key] = value instead of res.cookies.
2. Embedded newlines in the value: multiple cookies were joined with "\n"
into a single string. WEBrick 1.9 validates every header and cookie
value through check_header, raising WEBrick::HTTPResponse::InvalidHeader
for any value that contains \r or \n, which caused a 500 response.
Introduce build_rack_response_headers which:
- Lowercases all header names (required by Rack 3; harmless for Rack 2
because all Rack 2 handlers match header names case-insensitively).
- Under Rack 3 emits set-cookie as an Array so Rackup can call
res.cookies.concat(Array(value)), emitting one Set-Cookie line per cookie
with no embedded newlines.
- Under Rack 2 emits set-cookie as a newline-joined String, matching the
expectation of Rack::Handler::WEBrick which calls vs.split("\n") before
adding cookies (passing an Array would raise NoMethodError on Array#split).
Because all header keys are now lowercase, update LOWERCASE_CONTENT_TYPE
in RackResponse and adjust the two RackResponse unit specs accordingly.1 parent 50a7734 commit 3a5fa84
File tree
2 files changed
+48
-5
lines changed- lib/webmachine/adapters
- spec/webmachine/adapters
2 files changed
+48
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
120 | 159 | | |
121 | 160 | | |
122 | 161 | | |
| |||
153 | 192 | | |
154 | 193 | | |
155 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
156 | 199 | | |
157 | 200 | | |
158 | 201 | | |
| |||
161 | 204 | | |
162 | 205 | | |
163 | 206 | | |
164 | | - | |
165 | | - | |
| 207 | + | |
| 208 | + | |
166 | 209 | | |
167 | 210 | | |
168 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
0 commit comments