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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, host, port = nil) ⇒ HttpStreamingResponse

Returns a new instance of HttpStreamingResponse.



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

def initialize(request, host, port = nil)
  @request, @host, @port = request, host, port
end

Instance Attribute Details

#read_timeoutObject

Returns the value of attribute read_timeout.



9
10
11
# File 'lib/rack/http_streaming_response.rb', line 9

def read_timeout
  @read_timeout
end

#ssl_versionObject

Returns the value of attribute ssl_version.



10
11
12
# File 'lib/rack/http_streaming_response.rb', line 10

def ssl_version
  @ssl_version
end

#use_sslObject

Returns the value of attribute use_ssl.



7
8
9
# File 'lib/rack/http_streaming_response.rb', line 7

def use_ssl
  @use_ssl
end

#verify_modeObject

Returns the value of attribute verify_mode.



8
9
10
# File 'lib/rack/http_streaming_response.rb', line 8

def verify_mode
  @verify_mode
end

Instance Method Details

#bodyObject



16
17
18
# File 'lib/rack/http_streaming_response.rb', line 16

def body
  self
end

#codeObject Also known as: status



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

def code
  response.code.to_i
end

#each(&block) ⇒ Object

Can be called only once!



37
38
39
40
41
42
# File 'lib/rack/http_streaming_response.rb', line 37

def each(&block)
  response.read_body(&block)
ensure
  session.end_request_hacked
  session.finish
end

#headersObject



26
27
28
29
30
31
32
33
34
# File 'lib/rack/http_streaming_response.rb', line 26

def headers
  h = Utils::HeaderHash.new

  response.to_hash.each do |k, v|
    h[k] = v
  end

  h
end

#to_sObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rack/http_streaming_response.rb', line 44

def to_s
  @body ||= begin
    lines = []

    each do |line|
      lines << line
    end

    lines.join
  end
end