igrigorik/em-http-request — Issue #154: Redirect Requests Use Original Method (POST, PUT, DELETE)
Author: jbasdf
Created: 2011-11-03 15:28:11+00:00
State: open

I've run into an issue where a server I'm contacting redirects 7 times to authenticate a user using an SSO system. In order to perform the original authentication I do a POST. The server returns a 302 and a location. The library recognizes the 302 and redirects but it never changes the method so all of the redirects use a POST. I think that normally works, but for some reason after several redirects the server accumulates the post data and returns it in the header as the new location. That is a problem because the POST data is enormous and so on the last request the location is quite large and the server returns a 413.

I'm not sure if you are supposed to change to a GET when given a 302, but that fixes the problem.

Here's what happens right now in client.rb:

@req.set_uri(@response_header.location)
@conn.redirect(self)

I added a new method to http_client_options.rb that let's me set the method:
@req.set_uri(@response_header.location)
@req.set_method(:get)
@conn.redirect(self)

I can create a pull request if this change makes sense, but again I'm not sure if the http specs indicate if a 302 should require a :get or not or if the problem I am dealing with is unique.