lib/async/http/response.rb in async-http-0.24.3 vs lib/async/http/response.rb in async-http-0.25.0
- old
+ new
@@ -20,13 +20,27 @@
require_relative 'body/buffered'
module Async
module HTTP
- class Response < Struct.new(:version, :status, :reason, :headers, :body)
+ class Response
prepend Body::Buffered::Reader
+ def initialize(version = nil, status = 200, reason = nil, headers = [], body = nil)
+ @version = version
+ @status = status
+ @reason = reason
+ @headers = headers
+ @body = body
+ end
+
+ attr_accessor :version
+ attr_accessor :status
+ attr_accessor :reason
+ attr_accessor :headers
+ attr_accessor :body
+
def continue?
status == 100
end
def success?
@@ -43,17 +57,25 @@
def failure?
status >= 400 && status < 600
end
+ def bad_request?
+ status == 400
+ end
+
def self.[](status, headers = {}, body = [])
body = Body::Buffered.wrap(body)
self.new(nil, status, nil, headers, body)
end
def self.for_exception(exception)
Async::HTTP::Response[500, {'content-type' => 'text/plain'}, ["#{exception.class}: #{exception.message}"]]
+ end
+
+ def to_s
+ "#{@status} #{@reason} #{@version}"
end
end
end
end