Class: Rack::HttpStreamingResponse
- Inherits:
-
Object
- Object
- Rack::HttpStreamingResponse
- Defined in:
- lib/rack/http_streaming_response.rb
Overview
Wraps the hacked net/http in a Rack way.
Constant Summary collapse
- STATUSES_WITH_NO_ENTITY_BODY =
{ 204 => true, 205 => true, 304 => true }.freeze
Instance Attribute Summary collapse
-
#cert ⇒ Object
Returns the value of attribute cert.
-
#key ⇒ Object
Returns the value of attribute key.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#ssl_version ⇒ Object
Returns the value of attribute ssl_version.
-
#use_ssl ⇒ Object
Returns the value of attribute use_ssl.
-
#verify_mode ⇒ Object
Returns the value of attribute verify_mode.
Instance Method Summary collapse
- #body ⇒ Object
- #code ⇒ Object (also: #status)
-
#each(&block) ⇒ Object
Can be called only once!.
- #headers ⇒ Object
-
#initialize(request, host, port = nil) ⇒ HttpStreamingResponse
constructor
A new instance of HttpStreamingResponse.
- #to_s ⇒ Object
Constructor Details
#initialize(request, host, port = nil) ⇒ HttpStreamingResponse
Returns a new instance of HttpStreamingResponse.
15 16 17 |
# File 'lib/rack/http_streaming_response.rb', line 15 def initialize(request, host, port = nil) @request, @host, @port = request, host, port end |
Instance Attribute Details
#cert ⇒ Object
Returns the value of attribute cert.
13 14 15 |
# File 'lib/rack/http_streaming_response.rb', line 13 def cert @cert end |
#key ⇒ Object
Returns the value of attribute key.
13 14 15 |
# File 'lib/rack/http_streaming_response.rb', line 13 def key @key end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
13 14 15 |
# File 'lib/rack/http_streaming_response.rb', line 13 def read_timeout @read_timeout end |
#ssl_version ⇒ Object
Returns the value of attribute ssl_version.
13 14 15 |
# File 'lib/rack/http_streaming_response.rb', line 13 def ssl_version @ssl_version end |
#use_ssl ⇒ Object
Returns the value of attribute use_ssl.
13 14 15 |
# File 'lib/rack/http_streaming_response.rb', line 13 def use_ssl @use_ssl end |
#verify_mode ⇒ Object
Returns the value of attribute verify_mode.
13 14 15 |
# File 'lib/rack/http_streaming_response.rb', line 13 def verify_mode @verify_mode end |
Instance Method Details
#body ⇒ Object
19 20 21 |
# File 'lib/rack/http_streaming_response.rb', line 19 def body self end |
#code ⇒ Object Also known as: status
23 24 25 26 27 |
# File 'lib/rack/http_streaming_response.rb', line 23 def code response.code.to_i.tap do |response_code| STATUSES_WITH_NO_ENTITY_BODY[response_code] && close_connection end end |
#each(&block) ⇒ Object
Can be called only once!
36 37 38 39 40 41 42 |
# File 'lib/rack/http_streaming_response.rb', line 36 def each(&block) return if connection_closed response.read_body(&block) ensure close_connection end |
#headers ⇒ Object
31 32 33 |
# File 'lib/rack/http_streaming_response.rb', line 31 def headers Rack::Proxy.build_header_hash(response.to_hash) end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/rack/http_streaming_response.rb', line 44 def to_s @to_s ||= StringIO.new.tap { |io| each { |line| io << line } }.string end |