class Rack::HttpStreamingResponse

Wraps the hacked net/http in a Rack way.

Attributes

read_timeout[RW]
ssl_version[RW]
use_ssl[RW]
verify_mode[RW]

Public Class Methods

new(request, host, port = nil) click to toggle source
# File lib/rack/http_streaming_response.rb, line 12
def initialize(request, host, port = nil)
  @request, @host, @port = request, host, port
end

Public Instance Methods

body() click to toggle source
# File lib/rack/http_streaming_response.rb, line 16
def body
  self
end
code() click to toggle source
# File lib/rack/http_streaming_response.rb, line 20
def code
  response.code.to_i
end
Also aliased as: status
each(&block) click to toggle source

Can be called only once!

# File lib/rack/http_streaming_response.rb, line 37
def each(&block)
  response.read_body(&block)
ensure
  session.end_request_hacked
  session.finish
end
headers() click to toggle source
# 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
status()

status is deprecated

Alias for: code
to_s() click to toggle source
# 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

Protected Instance Methods

response() click to toggle source

Net::HTTPResponse

# File lib/rack/http_streaming_response.rb, line 59
def response
  @response ||= session.begin_request_hacked(@request)
end
session() click to toggle source

Net::HTTP

# File lib/rack/http_streaming_response.rb, line 64
def session
  @session ||= begin
    http = Net::HTTP.new @host, @port
    http.use_ssl = self.use_ssl
    http.verify_mode = self.verify_mode
    http.read_timeout = self.read_timeout
    http.ssl_version = self.ssl_version if self.use_ssl
    http.start
  end
end