Skip to content

Instantly share code, notes, and snippets.

@nayutaya
Created February 1, 2010 06:05
Show Gist options
  • Save nayutaya/291481 to your computer and use it in GitHub Desktop.
Save nayutaya/291481 to your computer and use it in GitHub Desktop.
# 「follow_redirectsオプションを無効にできない不具合」を修正するモンキーパッチ
# リポジトリの最新版では修正済み
# 対象はappengine-apis-0.0.12
module AppEngine
module URLFetch
module_function
def build_urlfetch_request(url, options) # :nodoc:
method = options.delete(:method) || 'GET'
payload = options.delete(:payload)
headers = options.delete(:headers) || {}
truncate = options.delete(:allow_truncated)
follow_redirects = options.delete(:follow_redirects)
deadline = options.delete(:deadline)
follow_redirects = true if follow_redirects.nil?
unless options.empty?
raise ArgumentError, "Unsupported options #{options.inspect}."
end
begin
method = HTTPMethod.value_of(method.to_s.upcase)
rescue java.lang.IllegalArgumentException
raise ArgumentError, "Invalid method #{method.inspect}."
end
if truncate
options = FetchOptions::Builder.allow_truncate
else
options = FetchOptions::Builder.disallow_truncate
end
if follow_redirects
options.follow_redirects
else
options.do_not_follow_redirects
end
options.set_deadline(deadline) if deadline
url = java.net.URL.new(url) unless url.java_kind_of? java.net.URL
request = HTTPRequest.new(url, method, options)
iterator = if headers.respond_to?(:canonical_each)
:canonical_each
else
:each
end
headers.send(iterator) do |name, value|
request.set_header(HTTPHeader.new(name, value))
end
if payload
request.set_payload(payload.to_java_bytes)
end
return request
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment