Module: Linzer::Request
Instance Method Summary collapse
- #build(verb, uri = "/", params = {}, headers = {}) ⇒ Object
- #headers(rack_request) ⇒ Object
- #rack_header_name(field_name) ⇒ Object
Instance Method Details
#build(verb, uri = "/", params = {}, headers = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/linzer/request.rb', line 7 def build(verb, uri = "/", params = {}, headers = {}) validate verb, uri, params, headers # XXX: to-do: handle rack request params? request_method = Rack.const_get(verb.upcase) args = { "REQUEST_METHOD" => request_method, "PATH_INFO" => uri.to_str } Rack::Request.new(build_rack_env(headers).merge(args)) end |
#headers(rack_request) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/linzer/request.rb', line 32 def headers(rack_request) rack_request .each_header .to_h .select do |k, _| k.start_with?("HTTP_") || %w[CONTENT_TYPE CONTENT_LENGTH].include?(k) end .transform_keys { |k| k.downcase.tr("_", "-") } .transform_keys do |k| %w[content-type content-length].include?(k) ? k : k.gsub(/^http-/, "") end end |
#rack_header_name(field_name) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/linzer/request.rb', line 20 def rack_header_name(field_name) validate_header_name field_name rack_name = field_name.upcase.tr("-", "_") case field_name.downcase when "content-type", "content-length" rack_name else "HTTP_#{rack_name}" end end |