Class: LongBody::ThinHandler::BodyWrapperWithExplicitClose

Inherits:
Object
  • Object
show all
Defined in:
lib/long_body/thin_handler.rb

Overview

We need a way to raise from each() when the connection is closed prematurely.

Instance Method Summary collapse

Constructor Details

#initialize(rack_body) ⇒ BodyWrapperWithExplicitClose

Returns a new instance of BodyWrapperWithExplicitClose.



76
77
78
# File 'lib/long_body/thin_handler.rb', line 76

def initialize(rack_body)
  @rack_body = rack_body
end

Instance Method Details

#abort!Object



68
69
70
# File 'lib/long_body/thin_handler.rb', line 68

def abort!
  @aborted = true; close
end

#closeObject



72
73
74
# File 'lib/long_body/thin_handler.rb', line 72

def close
  @rack_body.close if @rack_body.respond_to?(:close)
end

#eachObject



80
81
82
83
84
85
86
# File 'lib/long_body/thin_handler.rb', line 80

def each
  @rack_body.each do | bytes |
    # Break the body out of the loop if the response is aborted (client disconnect)
    raise "Disconnect or connection close" if @aborted
    yield(bytes)
  end
end