<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -10,9 +10,11 @@ $:.unshift(File.dirname(__FILE__)) unless
 
 dir = File.expand_path(File.join(File.dirname(__FILE__), 'httparty'))
 require dir + '/core_ext'
-  
+
 module HTTParty
   class UnsupportedFormat &lt; StandardError; end
+
+  class RedirectionTooDeep &lt; StandardError; end
   
   def self.included(base)
     base.extend ClassMethods
@@ -107,6 +109,9 @@ module HTTParty
       #   basic_auth  =&gt; :username and :password to use as basic http authentication (overrides @auth class instance variable)
       # Raises exception Net::XXX (http error code) if an http error occured
       def send_request(method, path, options={}) #:nodoc:
+        options = {:limit =&gt; 5}.merge(options)
+        options[:limit] = 0 if options.delete(:no_follow)
+        raise HTTParty::RedirectionTooDeep, 'HTTP redirects too deep' if options[:limit].to_i &lt;= 0
         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)
@@ -130,6 +135,9 @@ module HTTParty
         case response
         when Net::HTTPSuccess
           parse_response(response.body)
+        when Net::HTTPRedirection
+          options[:limit] -= 1
+          send_request(method, response['location'], options)
         else
           response.instance_eval { class &lt;&lt; self; attr_accessor :body_parsed; end }
           begin; response.body_parsed = parse_response(response.body); rescue; end</diff>
      <filename>lib/httparty.rb</filename>
    </modified>
    <modified>
      <diff>@@ -138,5 +138,78 @@ describe HTTParty do
       response.stub!(:body).and_return(&quot;&quot;)
       Foo.send(:send_request, 'get', 'bar').should be_nil
     end
+
+    describe &quot;that respond with redirects&quot; do
+      def setup_http
+        @http = Net::HTTP.new('localhost', 80)
+        Foo.stub!(:http).and_return(@http)
+        @redirect = Net::HTTPFound.new(&quot;1.1&quot;, 302, &quot;&quot;)
+        @redirect.stub!(:[]).with('location').and_return('/foo')
+        @ok = Net::HTTPOK.new(&quot;1.1&quot;, 200, &quot;Content for you&quot;)
+        @ok.stub!(:body).and_return({&quot;foo&quot; =&gt; &quot;bar&quot;}.to_xml)
+        @http.should_receive(:request).and_return(@redirect, @ok)
+        Foo.headers.clear
+        Foo.format :xml
+      end
+
+      it &quot;should handle redirects for GET transparently&quot; do
+        setup_http
+        Foo.get('/foo/').should == {&quot;hash&quot; =&gt; {&quot;foo&quot; =&gt; &quot;bar&quot;}}
+      end
+
+      it &quot;should handle redirects for POST transparently&quot; do
+        setup_http
+        Foo.post('/foo/', {:foo =&gt; :bar}).should == {&quot;hash&quot; =&gt; {&quot;foo&quot; =&gt; &quot;bar&quot;}}
+      end
+
+      it &quot;should handle redirects for DELETE transparently&quot; do
+        setup_http
+        Foo.delete('/foo/').should == {&quot;hash&quot; =&gt; {&quot;foo&quot; =&gt; &quot;bar&quot;}}
+      end
+
+      it &quot;should handle redirects for PUT transparently&quot; do
+        setup_http
+        Foo.put('/foo/').should == {&quot;hash&quot; =&gt; {&quot;foo&quot; =&gt; &quot;bar&quot;}}
+      end
+
+      it &quot;should prevent infinite loops&quot; do
+        http = Net::HTTP.new('localhost', 80)
+        Foo.stub!(:http).and_return(http)
+        redirect = Net::HTTPFound.new(&quot;1.1&quot;, &quot;302&quot;, &quot;Look, over there!&quot;)
+        redirect.stub!(:[]).with('location').and_return('/foo')
+        http.stub!(:request).and_return(redirect)
+
+        lambda do
+          Foo.send(:send_request, 'get', '/foo')
+        end.should raise_error(HTTParty::RedirectionTooDeep)
+      end
+
+      describe &quot;with explicit override of automatic redirect handling&quot; do
+
+        it &quot;should fail with redirected GET&quot; do
+          lambda do
+            Foo.get('/foo', :no_follow =&gt; true)
+          end.should raise_error(HTTParty::RedirectionTooDeep)
+        end
+
+        it &quot;should fail with redirected POST&quot; do
+          lambda do
+            Foo.post('/foo', :no_follow =&gt; true)
+          end.should raise_error(HTTParty::RedirectionTooDeep)
+        end
+
+        it &quot;should fail with redirected DELETE&quot; do
+          lambda do
+            Foo.delete('/foo', :no_follow =&gt; true)
+          end
+        end
+
+        it &quot;should fail with redirected PUT&quot; do
+          lambda do
+            Foo.put('/foo', :no_follow =&gt; true)
+          end
+        end
+      end
+    end
   end
 end
\ No newline at end of file</diff>
      <filename>spec/httparty_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f90c40914a3dec04face3a160eb5bdb6b2226ad6</id>
    </parent>
  </parents>
  <author>
    <name>Alex Vollmer</name>
    <email>alex@evri.com</email>
  </author>
  <url>http://github.com/jnunemaker/httparty/commit/ae7ce3097731a034e7b9ddae2b30d3916efa3a5c</url>
  <id>ae7ce3097731a034e7b9ddae2b30d3916efa3a5c</id>
  <committed-date>2008-10-24T21:34:33-07:00</committed-date>
  <authored-date>2008-09-19T16:31:06-07:00</authored-date>
  <message>Add the ability to automatically follow redirects and to turn it off.</message>
  <tree>6c16d50dad43cc43ad8538a352da5b0bf2682f29</tree>
  <committer>
    <name>John Nunemaker</name>
    <email>nunemaker@gmail.com</email>
  </committer>
</commit>
