title: Requests / bravado 302 response to POST turns into GET (python)
body: <p>As I was writing a handler for a webservice in bravado (through a  request.session()) I came across this peculiarity:</p>
  
  <p>A POST request turns into a GET request as it's being redirected.
  Causing my POST to be mangled and I can not get the thing to work.</p>
  
  <p><strong>EDIT:</strong> The actual requests call is made from bravado as explained in:
  <a href="https://stackoverflow.com/questions/31887512/how-do-you-set-a-custom-http-client-in-bravado">How do you set a custom http client in Bravado?</a> Which I needed for setting the additional client side certificates.</p>
  
  <p>So the requests call/session itself is being obscured by bravado.</p>
  
  <p>This issue (the post/get transition by requests) has been discussed in other threads where it is considered according to spec, but a weirdness nonetheless.</p>
  
  <p>In the end I just hacked into requests in the following segments in session.py:</p>
  
  <pre><code>def rebuild_method(self, prepared_request, response):
      """When being redirected we may want to change the method of the request
      based on certain specs or browser behavior.
      """
  
  
      method = prepared_request.method
  
      # http://tools.ietf.org/html/rfc7231#section-6.4.4
      if response.status_code == codes.see_other and method != 'HEAD':
          method = 'GET'
  
  
      # Do what the browsers do, despite standards...
      # First, turn 302s into GETs.
      if response.status_code == codes.found and method != 'HEAD':
          if method == 'POST':
              #print ( '\n\nDeliberately not changing to GET\n\n' )
          else:
              method = 'GET'
  
      # Second, if a POST is responded to with a 301, turn it into a GET.
      # This bizarre behaviour is explained in Issue 1704.
      if response.status_code == codes.moved and method == 'POST':
          method = 'GET'
  
  
      prepared_request.method = method
  </code></pre>
  
  <p>Where I simply not change to get.</p>
  
  <p>And also here:</p>
  
  <pre><code>def resolve_redirects(self, resp, req, stream=False, timeout=None,
                        verify=True, cert=None, proxies=None, yield_requests=False, **adapter_kwargs):
  </code></pre>
  
  <p>Where I commented out:</p>
  
  <pre><code>##            # https://github.com/requests/requests/issues/1084
  ##            if resp.status_code not in (codes.temporary_redirect, codes.permanent_redirect):
  ##                # https://github.com/requests/requests/issues/3490
  ##                print(prepared_request.headers)
  ##                purged_headers = ('Content-Length', 'Content-Type', 'Transfer-Encoding')
  ##                for header in purged_headers:
  ##                    prepared_request.headers.pop(header, None)
  ##                prepared_request.body = None
  </code></pre>
  
  <p>Surely this is the ugly hack, but what should I have done?
  Hope anyone has a pointer on this.</p>