Skip to content

Instantly share code, notes, and snippets.

@jwang
Forked from woodie/openid_fetch_fix.rb
Created April 9, 2010 18:42
Show Gist options
  • Save jwang/361450 to your computer and use it in GitHub Desktop.
Save jwang/361450 to your computer and use it in GitHub Desktop.
require 'openid'
require 'net/http'
require 'appengine-apis/urlfetch'
class MyFetcher < OpenID::StandardFetcher
def fetch(url, body=nil, headers=nil, redirect_limit=REDIRECT_LIMIT)
raise OpenID::FetchingError, "Blank URL: #{url}" if url.blank?
headers ||= {}
headers['User-agent'] ||= USER_AGENT
options = {
:follow_redirects => false,
:allow_truncated => false,
:headers => headers,
:follow_redirects => true,
:allow_truncated => false,
}
response = nil
if not body.nil?
query = Rack::Utils.build_query(body)
options[:method] = 'POST'
options[:headers]["Content-type"] ||= "application/x-www-form-urlencoded"
options[:payload] = query
else
options[:method] = 'GET'
end
begin
response = AppEngine::URLFetch.fetch(url, options)
rescue Exception => why
raise OpenID::FetchingError, "Error fetching #{url}: #{why}"
end
return OpenID::HTTPResponse._from_net_response(response, url)
end
end
OpenID.fetcher = MyFetcher.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment