Fix POST (and probably other) requests that are retried after 401 Unauthorized #502

Merged
merged 4 commits into from Apr 14, 2013

Projects

None yet

4 participants

@nylen
Member
nylen commented Apr 1, 2013

These commits fix a regression and a bug that were preventing POST requests from working when the initial request fails with 401 Unauthorized and a WWW-Authenticate header, and the client retries with a proper Authorization header. Also add tests to catch these problems in the future.

nylen added some commits Apr 1, 2013
@nylen nylen Fix a regression introduced by cba36ce
Request.prototype.init() should not clear self.method if it is already
set.  This is relevant when retrying requests with proper authentication
(the retries are handled similarly to redirects, but should keep the
same request method).
c40993f
@nylen nylen Don't delete headers when retrying a request with proper authentication edc2e17
@nylen nylen Refactor and expand basic auth tests
The new tests catch the regression corrected by c40993f and the bug
corrected by edc2e17.
a375ac1
@codehero

Why isn't this change integrated with request yet? I just wasted 80 minutes of my life because I had to track this problem down...

Owner

I have an open pull request for this change: request#502

@mikeal
Member
mikeal commented Apr 13, 2013

somehow i missed this pull request, sorry. it doesn't merge cleanly anymore :(

it looks good otherwise.

@nylen
Member
nylen commented Apr 13, 2013

Try now.

@mikeal mikeal merged commit 7a08abb into request:master Apr 14, 2013
@nylen nylen deleted the nylen:fix-auth-post branch Apr 14, 2013
@wprl
Contributor
wprl commented Sep 5, 2013

This still seems to be a potential issue. The following code does not seem to work as expected, though other requests are being correctly retried. Url, callback, and attachments have all been verified (attachment.content is a Buffer).

var form = rq.post(url, callback).form();

options.attachments.forEach(function (attachment) {
  form.append(attachment.generatedFileName, attachment.content);
});

The POST is never retried after the first response (401) when this request is made, and the callback is never called.

@nylen
Member
nylen commented Sep 11, 2013

@wprl, can you provide a failing test case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment