Class: Async::HTTP::Response

Inherits:
Object
  • Object
show all
Includes:
Body::Buffered::Reader
Defined in:
lib/async/http/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Body::Buffered::Reader

#finish, #read

Constructor Details

#initialize(version = nil, status = 200, reason = nil, headers = [], body = nil) ⇒ Response

Returns a new instance of Response.



28
29
30
31
32
33
34
# File 'lib/async/http/response.rb', line 28

def initialize(version = nil, status = 200, reason = nil, headers = [], body = nil)
	@version = version
	@status = status
	@reason = reason
	@headers = headers
	@body = body
end

Instance Attribute Details

#body ⇒ Object

Returns the value of attribute body.



40
41
42
# File 'lib/async/http/response.rb', line 40

def body
  @body
end

#headers ⇒ Object

Returns the value of attribute headers.



39
40
41
# File 'lib/async/http/response.rb', line 39

def headers
  @headers
end

#reason ⇒ Object

Returns the value of attribute reason.



38
39
40
# File 'lib/async/http/response.rb', line 38

def reason
  @reason
end

#status ⇒ Object

Returns the value of attribute status.



37
38
39
# File 'lib/async/http/response.rb', line 37

def status
  @status
end

#version ⇒ Object

Returns the value of attribute version.



36
37
38
# File 'lib/async/http/response.rb', line 36

def version
  @version
end

Class Method Details

.[](status, headers = {}, body = []) ⇒ Object



66
67
68
69
70
# File 'lib/async/http/response.rb', line 66

def self.[](status, headers = {}, body = [])
	body = Body::Buffered.wrap(body)
	
	self.new(nil, status, nil, headers, body)
end

.for_exception(exception) ⇒ Object



72
73
74
# File 'lib/async/http/response.rb', line 72

def self.for_exception(exception)
	Async::HTTP::Response[500, {'content-type' => 'text/plain'}, ["#{exception.class}: #{exception.message}"]]
end

Instance Method Details

#bad_request? ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/async/http/response.rb', line 62

def bad_request?
	status == 400
end

#continue? ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/async/http/response.rb', line 42

def continue?
	status == 100
end

#failure? ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/async/http/response.rb', line 58

def failure?
	status >= 400 && status < 600
end

#preserve_method? ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/async/http/response.rb', line 54

def preserve_method?
	status == 307 || status == 308
end

#redirection? ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/async/http/response.rb', line 50

def redirection?
	status >= 300 && status < 400
end

#success? ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/async/http/response.rb', line 46

def success?
	status >= 200 && status < 300
end

#to_s ⇒ Object



76
77
78
# File 'lib/async/http/response.rb', line 76

def to_s
	"#{@status} #{@reason} #{@version}"
end