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



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/appengine-apis/urlfetch.rb', line 198

def request(req, body=nil, &block)
  begin
    proto = use_ssl? ? 'https' : 'http'
    url = "#{proto}://#{addr_port}#{req.path}"
    options = {
        :payload => body || req.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

#use_ssl=(flag) ⇒ Object



217
218
219
# File 'lib/appengine-apis/urlfetch.rb', line 217

def use_ssl=(flag)
  @use_ssl = flag
end