Class: Debugbar::HttpRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/debugbar/http/http.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, url, headers, body) ⇒ HttpRequest

Returns a new instance of HttpRequest.



5
6
7
8
9
10
# File 'lib/debugbar/http/http.rb', line 5

def initialize(method, url, headers, body)
  @method = method
  @url = url
  @headers = headers
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/debugbar/http/http.rb', line 3

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



3
4
5
# File 'lib/debugbar/http/http.rb', line 3

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



3
4
5
# File 'lib/debugbar/http/http.rb', line 3

def method
  @method
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/debugbar/http/http.rb', line 3

def url
  @url
end

Class Method Details

.from_rack(rack_req) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/debugbar/http/http.rb', line 12

def self.from_rack(rack_req)
  headers = rack_req.env.select { |k,v| k.start_with? 'HTTP_'} # https://stackoverflow.com/a/55406700/1001125
    .transform_keys { |k| k.sub(/^HTTP_/, '').split('_').map(&:capitalize).join('-') }
    .sort.to_h

  new(rack_req.method, rack_req.original_url, headers, rack_req.body)
end

Instance Method Details

#to_hObject



20
21
22
# File 'lib/debugbar/http/http.rb', line 20

def to_h
  { method:, url:, headers:, body: }
end