lib/async/http/response.rb in async-http-0.18.0 vs lib/async/http/response.rb in async-http-0.19.0
- old
+ new
@@ -16,15 +16,17 @@
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
-require_relative 'body'
+require_relative 'body/buffered'
module Async
module HTTP
class Response < Struct.new(:version, :status, :reason, :headers, :body)
+ prepend Body::Buffered::Reader
+
def continue?
status == 100
end
def success?
@@ -41,9 +43,17 @@
def failure?
status >= 400 && status < 600
end
- include BufferedBody::Reader
+ 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
end
end
end