lostisland / faraday_middleware

Various Faraday middlewares for Faraday-based API wrappers
MIT License
557 stars 203 forks source link

FollowRedirects should disregard content headers #265

Open stevelacey opened 3 years ago

stevelacey commented 3 years ago

FollowRedirects was failing with a ReadTimeout for me, the reason turned out to be because the request I was doing was a multipart post which naturally has a form multipart Content-Type and a long Content-Length for the post body.

When this request is convert to a GET as per standards_compliance: false these headers should probably be disregarded by default, the POST body is not coming along for the ride so these are definitely going to be wrong.

To achieve this myself I had to use the callback option:

f.use FaradayMiddleware::FollowRedirects, callback: lambda { |response, redirect|
  redirect.request_headers.delete("Content-Length")
  redirect.request_headers.delete("Content-Type")
}
iMacTia commented 3 years ago

Thanks @stevelacey, that makes sense and it would make the middleware smarter. I won't be able to work on this right now, but hopefully there will be takers ❤️ .