Class: HTTPX::Response
Defined Under Namespace
Classes: Body
Instance Attribute Summary collapse
Instance Method Summary
collapse
#deconstruct, #deconstruct_keys
Methods included from Callbacks
#callbacks_for?, #emit, #on, #once, #only
Constructor Details
#initialize(request, status, version, headers) ⇒ Response
Returns a new instance of Response.
28
29
30
31
32
33
34
35
36
|
# File 'lib/httpx/response.rb', line 28
def initialize(request, status, version, )
@request = request
@options = request.options
@version = version
@status = Integer(status)
@headers = @options..new()
@body = @options.response_body_class.new(self, @options)
@finished = complete?
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
14
15
16
|
# File 'lib/httpx/response.rb', line 14
def body
@body
end
|
Returns the value of attribute headers.
14
15
16
|
# File 'lib/httpx/response.rb', line 14
def
@headers
end
|
#status ⇒ Object
Returns the value of attribute status.
14
15
16
|
# File 'lib/httpx/response.rb', line 14
def status
@status
end
|
#version ⇒ Object
Returns the value of attribute version.
14
15
16
|
# File 'lib/httpx/response.rb', line 14
def version
@version
end
|
Instance Method Details
#<<(data) ⇒ Object
42
43
44
|
# File 'lib/httpx/response.rb', line 42
def <<(data)
@body.write(data)
end
|
#bodyless? ⇒ Boolean
59
60
61
62
|
# File 'lib/httpx/response.rb', line 59
def bodyless?
@request.verb == "HEAD" ||
no_data?
end
|
#complete? ⇒ Boolean
64
65
66
|
# File 'lib/httpx/response.rb', line 64
def complete?
bodyless? || (@request.verb == "CONNECT" && @status == 200)
end
|
#content_type ⇒ Object
46
47
48
|
# File 'lib/httpx/response.rb', line 46
def content_type
@content_type ||= ContentType.new(@headers["content-type"])
end
|
#error ⇒ Object
78
79
80
81
82
|
# File 'lib/httpx/response.rb', line 78
def error
return if @status < 400
HTTPError.new(self)
end
|
#finish! ⇒ Object
54
55
56
57
|
# File 'lib/httpx/response.rb', line 54
def finish!
@finished = true
@headers.freeze
end
|
#finished? ⇒ Boolean
50
51
52
|
# File 'lib/httpx/response.rb', line 50
def finished?
@finished
end
|
94
95
96
|
# File 'lib/httpx/response.rb', line 94
def form
decode(Transcoder::Form)
end
|
#inspect ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/httpx/response.rb', line 69
def inspect
"#<Response:#{object_id} " \
"HTTP/#{version} " \
"@status=#{@status} " \
"@headers=#{@headers} " \
"@body=#{@body.bytesize}>"
end
|
#json(*args) ⇒ Object
90
91
92
|
# File 'lib/httpx/response.rb', line 90
def json(*args)
decode(Transcoder::JSON, *args)
end
|
38
39
40
|
# File 'lib/httpx/response.rb', line 38
def (h)
@headers = @headers.merge(h)
end
|
#raise_for_status ⇒ Object
84
85
86
87
88
|
# File 'lib/httpx/response.rb', line 84
def raise_for_status
return self unless (err = error)
raise err
end
|
#xml ⇒ Object
98
99
100
|
# File 'lib/httpx/response.rb', line 98
def xml
decode(Transcoder::Xml)
end
|