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 19 |
# 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.input" => StringIO.new } Rack::Request.new(build_rack_env(headers).merge(args)) end |
#headers(rack_request) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/linzer/request.rb', line 33 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
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/linzer/request.rb', line 21 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 |