<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,8 +1,9 @@
-== 0.1.3 2008-08-XX
+== 0.1.3 2008-08-22
 
-* 1 major enhancement:
-	* Added : http_proxy key for setting proxy server and port
-	* Added : raises exception when http error occurs
+* 3 major enhancements:
+	* Added http_proxy key for setting proxy server and port (francxk@gmail.com)
+	* Now raises exception when http error occurs (francxk@gmail.com)
+	* Changed auto format detection from file extension to response content type (Jay Pignata)
 
 == 0.1.2 2008-08-09
 </diff>
      <filename>History.txt</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,6 @@ module AAWS
     include HTTParty
     base_uri 'http://ecs.amazonaws.com'
     default_params :Service =&gt; 'AWSECommerceService', :Operation =&gt; 'ItemSearch', :SearchIndex =&gt; 'Books'
-    format :xml
     
     def initialize(key)
       self.class.default_params :AWSAccessKeyId =&gt; key</diff>
      <filename>examples/aaws.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,6 @@ config = YAML::load(File.read(File.join(ENV['HOME'], '.delicious')))
 class Delicious
   include HTTParty
   base_uri 'https://api.del.icio.us/v1'
-  format :xml
   
   def initialize(u, p)
     @auth = {:username =&gt; u, :password =&gt; p}</diff>
      <filename>examples/delicious.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,6 @@ require 'pp'
 
 class Rep
   include HTTParty
-  format :xml
 end
 
 puts Rep.get('http://whoismyrepresentative.com/whoismyrep.php?zip=46544').inspect
\ No newline at end of file</diff>
      <filename>examples/whoismyrep.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,13 +12,13 @@ dir = File.expand_path(File.join(File.dirname(__FILE__), 'httparty'))
 require dir + '/core_ext'
   
 module HTTParty
+  class UnsupportedFormat &lt; StandardError; end
+  
   def self.included(base)
     base.extend ClassMethods
   end
   
-  class UnsupportedFormat &lt; StandardError; end
-  
-  AllowedFormats = %w[xml json]
+  AllowedFormats = {:xml =&gt; 'text/xml', :json =&gt; 'application/json'}
   
   module ClassMethods    
     #
@@ -64,8 +64,7 @@ module HTTParty
     end
     
     def format(f)
-      f = f.to_s
-      raise UnsupportedFormat, &quot;Must be one of: #{AllowedFormats.join(', ')}&quot; unless AllowedFormats.include?(f)
+      raise UnsupportedFormat, &quot;Must be one of: #{AllowedFormats.keys.join(', ')}&quot; unless AllowedFormats.key?(f)
       @format = f
     end
     
@@ -111,9 +110,6 @@ module HTTParty
         raise ArgumentError, 'only get, post, put and delete methods are supported' unless %w[get post put delete].include?(method.to_s)
         raise ArgumentError, ':headers must be a hash' if options[:headers] &amp;&amp; !options[:headers].is_a?(Hash)
         raise ArgumentError, ':basic_auth must be a hash' if options[:basic_auth] &amp;&amp; !options[:basic_auth].is_a?(Hash)
-        # we always want path that begins with /
-        path           = path =~ /^(\/|https?:\/\/)/ ? path : &quot;/#{path}&quot;
-        @format      ||= format_from_path(path)
         uri            = URI.parse(&quot;#{base_uri}#{path}&quot;)
         existing_query = uri.query ? &quot;#{uri.query}&amp;&quot; : ''
         uri.query      = if options[:query].blank?
@@ -129,9 +125,10 @@ module HTTParty
         # note to self: self, do not put basic auth above headers because it removes basic auth
         request.basic_auth(basic_auth[:username], basic_auth[:password]) if basic_auth
         response       = http(uri).request(request)
-
+        @format      ||= format_from_mimetype(response['content-type'])
+        
         case response
-        when Net::HTTPSuccess     then
+        when Net::HTTPSuccess
           parse_response(response.body)
         else
           response.instance_eval { class &lt;&lt; self; attr_accessor :body_parsed; end }
@@ -143,9 +140,9 @@ module HTTParty
       
       def parse_response(body) #:nodoc:
         case @format
-        when 'xml'
+        when :xml
           Hash.from_xml(body)
-        when 'json'
+        when :json
           ActiveSupport::JSON.decode(body)
         else
           # just return the response if no format 
@@ -158,13 +155,10 @@ module HTTParty
         str =~ /^https?:\/\// ? str : &quot;http#{'s' if str.include?(':443')}://#{str}&quot;
       end
       
-      # Returns a format that we can handle from the path if possible. 
-      # Just does simple pattern matching on file extention:
-      #   /foobar.xml =&gt; 'xml'
-      #   /foobar.json =&gt; 'json'
-      def format_from_path(path) #:nodoc:
-        ext = File.extname(path)[1..-1]
-        !ext.blank? &amp;&amp; AllowedFormats.include?(ext) ? ext : nil
+      # Uses the HTTP Content-Type header to determine the format of the response
+      # It compares the MIME type returned to the types stored in the AllowedFormats hash
+      def format_from_mimetype(mimetype) #:nodoc:
+        AllowedFormats.each { |k, v| return k if mimetype.include?(v) }
       end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/httparty.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b0f1cc2a8d6ab02f2fc7485ad3c25b87319443e4</id>
    </parent>
  </parents>
  <author>
    <name>John Nunemaker</name>
    <email>nunemaker@gmail.com</email>
  </author>
  <url>http://github.com/jnunemaker/httparty/commit/76601ba0c7d6daea37f94c71d01367a3ff684fa5</url>
  <id>76601ba0c7d6daea37f94c71d01367a3ff684fa5</id>
  <committed-date>2008-08-22T18:50:51-07:00</committed-date>
  <authored-date>2008-08-22T18:50:51-07:00</authored-date>
  <message>Changed format detection from crappy file extension to awesome response content type. [#2 state:resolved]</message>
  <tree>192335eca4b34adda91317d1b540efaa6de0ae78</tree>
  <committer>
    <name>John Nunemaker</name>
    <email>nunemaker@gmail.com</email>
  </committer>
</commit>
