Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#### Fixes

* [#2767](https://github.com/ruby-grape/grape/pull/2767): Update rubocop to 1.88.0 and rubocop-rspec to 3.10.2 - [@ericproulx](https://github.com/ericproulx).
* [#2770](https://github.com/ruby-grape/grape/pull/2770): Avoid per-entry array allocation in `Request#build_headers` - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

### 3.3.0 (2026-06-20)
Expand Down
8 changes: 7 additions & 1 deletion lib/grape/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,19 @@ def make_params
raise Grape::Exceptions::RequestError
end

# Uses a plain `each_header` block instead of `each_header.with_object`:
# `with_object` can only pass the block one value plus the memo, so the
# `k, v` pair would be boxed into a throwaway Array on every header. A
# two-arg block receives `k`/`v` directly and allocates nothing extra.
def build_headers
each_header.with_object(Grape::Util::Header.new) do |(k, v), headers|
headers = Grape::Util::Header.new
each_header do |k, v|
next unless k.start_with? 'HTTP_'

transformed_header = KNOWN_HEADERS.fetch(k) { -k[5..].tr('_', '-').downcase }
headers[transformed_header] = v
end
headers
end
end
end
Loading