Permalink
Browse files

Merge pull request #29 from qoobaa/oauth-ruby

---

Sometimes its better to use Net::HTTPGenericRequest instead of Net::HTTP::Get, especially when you need streaming, etc. Net::HTTPGenericRequest is a superclass of Net::HTTPRequest, so the patch doesnt break anything - just allows to sign Net::HTTPGenericRequest instances.
  • Loading branch information...
2 parents 6fccb22 + 7d758c9 commit 057f518a7e7b2e49ac17ebee5f78b86866e68c1f @quirkey quirkey committed Jun 25, 2011
@@ -2,7 +2,7 @@
require 'oauth/client/helper'
require 'oauth/request_proxy/net_http'
-class Net::HTTPRequest
+class Net::HTTPGenericRequest
include OAuth::Helper
attr_reader :oauth_helper
@@ -83,7 +83,7 @@ def oauth_full_request_uri(http,options)
end
def oauth_body_hash_required?
- request_body_permitted? && content_type != "application/x-www-form-urlencoded"
+ request_body_permitted? && !content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
end
def set_oauth_header
@@ -36,7 +36,7 @@ def parameters_for_signature
params << header_params.to_query
params << request.query_string unless query_string_blank?
- if request.post? && request.content_type == Mime::Type.lookup("application/x-www-form-urlencoded")
+ if request.post? && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
params << request.raw_post
end
end
@@ -42,7 +42,7 @@ def post_parameters
post_body = {}
# Post params are only used if posting form data
- if (request.headers['Content-Type'] && request.headers['Content-Type'].downcase == 'application/x-www-form-urlencoded')
+ if (request.headers['Content-Type'] && request.headers['Content-Type'].to_s.downcase.start_with?("application/x-www-form-urlencoded"))
request.post_body.split("&").each do |str|
param = str.split("=")
@@ -41,7 +41,7 @@ def query_parameters
def post_parameters
headers = request.options[:head] || {}
- form_encoded = headers['Content-Type'].to_s.downcase == 'application/x-www-form-urlencoded'
+ form_encoded = headers['Content-Type'].to_s.downcase.start_with?("application/x-www-form-urlencoded")
if ['POST', 'PUT'].include?(method) && form_encoded
CGI.parse(request.normalize_body.to_s)
else
@@ -6,7 +6,7 @@
module OAuth::RequestProxy::Net
module HTTP
class HTTPRequest < OAuth::RequestProxy::Base
- proxies ::Net::HTTPRequest
+ proxies ::Net::HTTPGenericRequest
def method
request.method
@@ -52,7 +52,7 @@ def query_string
end
def form_url_encoded?
- request['Content-Type'] != nil && request['Content-Type'].downcase == 'application/x-www-form-urlencoded'
+ request['Content-Type'] != nil && request['Content-Type'].to_s.downcase.start_with?('application/x-www-form-urlencoded')
end
def query_params
@@ -34,9 +34,9 @@ def query_params
end
def request_params
- if request.content_type and request.content_type.downcase == 'application/x-www-form-urlencoded'
+ if request.content_type and request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
request.POST
- else
+ else
{}
end
end
@@ -43,7 +43,7 @@ def query_parameters
def post_parameters
# Post params are only used if posting form data
- if(method == 'POST' && request.headers['Content-Type'] && request.headers['Content-Type'].downcase == 'application/x-www-form-urlencoded')
+ if(method == 'POST' && request.headers['Content-Type'] && request.headers['Content-Type'].to_s.downcase.start_with?("application/x-www-form-urlencoded"))
request.body || {}
else
{}

0 comments on commit 057f518

Please sign in to comment.