Skip to content

Commit

Permalink
Don't send http request body on redirected request
Browse files Browse the repository at this point in the history
  • Loading branch information
Paxa committed Feb 18, 2015
1 parent 25117b2 commit 83cfd76
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/excon/middlewares/redirect_follower.rb
Expand Up @@ -17,7 +17,11 @@ def response_call(datum)
params = datum.dup
params.delete(:stack)
params.delete(:connection)
params[:method] = :get if [301, 302, 303].include? response[:status]
if [301, 302, 303].include?(response[:status])
params[:method] = :get
params.delete(:body)
params[:headers].delete('Content-Length')
end
params[:headers] = datum[:headers].dup
params[:headers].delete('Authorization')
params[:headers].delete('Proxy-Connection')
Expand Down
17 changes: 17 additions & 0 deletions tests/middlewares/redirect_follower_tests.rb
Expand Up @@ -61,3 +61,20 @@

env_restore
end

Shindo.tests("Excon redirecting post request") do
env_init

with_rackup('redirecting.ru') do
tests("request not have content-length and body").returns('ok') do
Excon.post(
'http://127.0.0.1:9292',
:path => '/first',
:middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::RedirectFollower],
:body => "a=Some_content"
).body
end
end

env_restore
end
23 changes: 23 additions & 0 deletions tests/rackups/redirecting.ru
@@ -0,0 +1,23 @@
require 'sinatra'
require 'json'
require File.join(File.dirname(__FILE__), 'webrick_patch')

class App < Sinatra::Base
set :environment, :production
enable :dump_errors

post('/first') do
redirect "/second"
end

get('/second') do
post_body = request.body.read
if post_body == "" && request["CONTENT_LENGTH"].nil?
"ok"
else
JSON.pretty_generate(request.env)
end
end
end

run App

0 comments on commit 83cfd76

Please sign in to comment.