Class: Net::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/appengine-apis/urlfetch.rb

Overview

Monkey patch Net::HTTP to makes requests using Google App Engine’s URLFetch Service.

Instance Method Summary collapse

Instance Method Details

#request(req, body = nil, &block) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/appengine-apis/urlfetch.rb', line 190

def request(req, body=nil, &block)
  begin
    proto = use_ssl? ? 'https' : 'http'
    url = "#{proto}://#{addr_port}#{req.path}"
    options = {
        :payload => body,
        :follow_redirects => false,
        :allow_truncated => true,
        :method => req.method,
        :headers => req
        }
    res = AppEngine::URLFetch.fetch(url, options)
  end while res.kind_of?(Net::HTTPContinue)
  res.reading_body(nil, req.response_body_permitted?) {
    yield res if block_given?
  }
  return res
end