-
-
Save jwang/361450 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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