class Grape::Request
def build_headers
`k, v` pair would be boxed into a throwaway Array on every header. A
`with_object` can only pass the block one value plus the memo, so the
Uses a plain `each_header` block instead of `each_header.with_object`:
def build_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
def cookies
def cookies @cookies ||= Grape::Cookies.new(rack_cookies) end
def cookies?
and the Grape::Cookies allocation it triggers, when no cookie was
written this request). Lets the endpoint skip response-cookie flushing,
True once the cookie jar has been materialized (a cookie was read or
def cookies? !@cookies.nil? end
def headers
def headers @headers ||= build_headers end
def initialize(env, build_params_with: nil)
def initialize(env, build_params_with: nil) super(env) @params_builder = Grape::ParamsBuilder.params_builder_for(build_params_with || Grape.config.param_builder) end
def make_params
def make_params params = @params_builder.call(rack_params) routing_args = env[Grape::Env::GRAPE_ROUTING_ARGS] filtered = routing_args&.except(:version, :route_info) return params if filtered.blank? params.deep_merge!(filtered) rescue *Grape::RACK_ERRORS raise Grape::Exceptions::RequestError end
def params
def params @params ||= make_params end