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.



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

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

Instance Attribute Details

#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

Instance Method Details

#bodyObject



27
28
29
# File 'lib/rack/http_streaming_response.rb', line 27

def body
  self
end

#each(&block) ⇒ Object

Can be called only once!



32
33
34
35
36
# File 'lib/rack/http_streaming_response.rb', line 32

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

#headersObject



17
18
19
20
21
22
23
24
25
# File 'lib/rack/http_streaming_response.rb', line 17

def headers
  h = Utils::HeaderHash.new
  
  response.each_header do |k, v|
    h[k] = v
  end
  
  h
end

#statusObject



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

def status
  response.code.to_i
end

#to_sObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rack/http_streaming_response.rb', line 38

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

    each do |line|
      lines << line
    end
    
    lines.join
  end
end