Class: ProxyTest::Response
- Inherits:
-
Object
- Object
- ProxyTest::Response
- Defined in:
- lib/proxytest/helpers/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
-
#[](v) ⇒ Object
Hack to make it look like a Net::HTTP entity.
- #[]=(k, v) ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
-
#status ⇒ Object
Status wrapper.
- #status=(st) ⇒ Object
- #to_http ⇒ Object
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
11 12 13 14 15 |
# File 'lib/proxytest/helpers/response.rb', line 11 def initialize body = "" # Default set of headers? @headers = {} end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
8 9 10 |
# File 'lib/proxytest/helpers/response.rb', line 8 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
9 10 11 |
# File 'lib/proxytest/helpers/response.rb', line 9 def headers @headers end |
Instance Method Details
#[](v) ⇒ Object
Hack to make it look like a Net::HTTP entity
35 36 37 |
# File 'lib/proxytest/helpers/response.rb', line 35 def [](v) headers[v] end |
#[]=(k, v) ⇒ Object
39 40 41 |
# File 'lib/proxytest/helpers/response.rb', line 39 def []=(k, v) headers[k] = v end |
#status ⇒ Object
Status wrapper
44 45 46 |
# File 'lib/proxytest/helpers/response.rb', line 44 def status @status ||= 200 end |
#status=(st) ⇒ Object
48 49 50 |
# File 'lib/proxytest/helpers/response.rb', line 48 def status=(st) @status = st end |
#to_http ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/proxytest/helpers/response.rb', line 17 def to_http h1 = <<-HTTP HTTP/1.0 #{status} #{STATUSES[status]} Content-Type: text/html Content-Length: #{body.length} HTTP headers.each do |k, v| h1 += "#{k}: #{v}\r\n" end h1 += <<-HTTP #{body} HTTP return h1 end |