Module: Rack::HttpPipe
- Defined in:
- lib/rack/http-pipe/pipe.rb
Instance Method Summary collapse
Instance Method Details
#http_pipe(url, opts = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rack/http-pipe/pipe.rb', line 5 def http_pipe(url, opts = {}) st = opts.fetch(:status, 200) uri = URI(url) status st if opts[:headers] and opts[:headers].is_a? Hash headers opts[:headers] end stream do Net::HTTP.start(uri.host, uri.port) do |http| req = Net::HTTP::Get.new(uri.request_uri) req.basic_auth uri.user, uri.password http.request req do |res| res.read_body do |c| response.write c end end end end end |