Class: Rack::HttpStreamingResponse

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#certObject

Returns the value of attribute cert.



13
14
15
# File 'lib/rack/http_streaming_response.rb', line 13

def cert
  @cert
end

#keyObject

Returns the value of attribute key.



13
14
15
# File 'lib/rack/http_streaming_response.rb', line 13

def key
  @key
end

#read_timeoutObject

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_versionObject

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_sslObject

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_modeObject

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

#bodyObject



19
20
21
# File 'lib/rack/http_streaming_response.rb', line 19

def body
  self
end

#codeObject 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

#headersObject



31
32
33
# File 'lib/rack/http_streaming_response.rb', line 31

def headers
  Rack::Proxy.build_header_hash(response.to_hash)
end

#to_sObject



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