Commit d79a12b
Build the cookie jar only on use and drop its deferral Proc (#2757)
Two related steps that make the response-cookie path lazy at the request
boundary:
- `build_response_cookies` runs on every request and went through
`cookies` -> `request.cookies`, materializing the `Grape::Cookies` jar
even when the handler never touched a cookie. Gate it on a new
`Grape::Request#cookies?` predicate (true only once the jar exists),
so a cookie-free request allocates no jar at all.
- With the jar now built only when a cookie is actually read or written,
its `-> { rack_cookies }` deferral Proc no longer earns its keep: any
access immediately forces the parse, and a write (`[]=`) always did.
Parse `rack_cookies` eagerly in the constructor and replace the
`is_a?(Proc)` lazy reader with a plain `attr_reader`, dropping the
closure allocation and the per-access branch.
The `ActiveSupport::HashWithIndifferentAccess` wrapping is unchanged --
it backs Grape's string/symbol-indifferent cookie access.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent df9338f commit d79a12b
4 files changed
Lines changed: 14 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 40 | + | |
45 | 41 | | |
46 | 42 | | |
47 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
| 388 | + | |
| 389 | + | |
388 | 390 | | |
389 | 391 | | |
390 | 392 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
157 | 165 | | |
158 | 166 | | |
159 | 167 | | |
| |||
0 commit comments