Class: Steam::Connection::OpenUri

Inherits:
Object
  • Object
show all
Defined in:
lib/steam/connection/open_uri.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
# File 'lib/steam/connection/open_uri.rb', line 9

def call(env)
  request = Rack::Request.new(env)
  Rack::Response.new(*open(request.url)).to_a
end

#open(uri) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/steam/connection/open_uri.rb', line 14

def open(uri)
  headers = {}
  body = Kernel.open(uri) { |f| headers = f.meta; f.read }
  [body, 200, headers]
rescue OpenURI::HTTPError => e
  status = e.message.split(' ').first
  ['', status, headers]
end