Class: ProxyTest::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/proxytest/helpers/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

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

#bodyObject

Returns the value of attribute body.



8
9
10
# File 'lib/proxytest/helpers/response.rb', line 8

def body
  @body
end

#headersObject (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

#statusObject

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_httpObject



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