Skip to content

Instantly share code, notes, and snippets.

@tinco
Created March 6, 2010 02:59
Show Gist options
  • Save tinco/323465 to your computer and use it in GitHub Desktop.
Save tinco/323465 to your computer and use it in GitHub Desktop.
diff --git a/ug-gadget/vendor/gems/httparty-0.5.2/lib/httparty/request.rb b/ug-gadget/vendor/gems/httparty-0.5.2/lib/httparty/request.rb
index 67ac94f..a7089da 100644
--- a/ug-gadget/vendor/gems/httparty-0.5.2/lib/httparty/request.rb
+++ b/ug-gadget/vendor/gems/httparty-0.5.2/lib/httparty/request.rb
@@ -104,7 +104,12 @@ module HTTParty
def setup_raw_request
@raw_request = http_method.new(uri.request_uri)
- @raw_request.body = body if body
+ if body
+ @raw_request.body = body
+ if not body.is_a?(Hash)
+ options[:headers].merge!('content-type' => mimetype_from_format(format))
+ end
+ end
@raw_request.initialize_http_header(options[:headers])
@raw_request.basic_auth(username, password) if options[:basic_auth]
end
@@ -178,6 +183,16 @@ module HTTParty
end
end
+ # Determines the mimetype from the format
+ #TODO make this a bit more smart (perhaps using the parser)
+ def mimetype_from_format(format)
+ case format
+ when :xml : 'text/xml'
+ when :json : 'text/json'
+ when :html : 'text/html'
+ end
+ end
+
def validate
raise HTTParty::RedirectionTooDeep.new(last_response), 'HTTP redirects too deep' if options[:limit].to_i <= 0
raise ArgumentError, 'only get, post, put, delete, head, and options methods are supported' unless SupportedHTTPMethods.include?(ht
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment