-
Notifications
You must be signed in to change notification settings - Fork 237
Fix redirect with head with body #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix redirect with head with body #444
Conversation
|
Regardless of the test, does this fix handle the scenario described in the issue? |
Absolutely. Here is how I verified: With the fix: cklein@minitrueee:~/elastisys/needle$ git log -1
commit a52baad790cf6174bc3aa0349425bd4fcb8677e6 (HEAD -> fix-redirect-with-head-with-body, origin/fix-redirect-with-head-with-body)
Author: Cristian Klein <cristian.klein@elastisys.com>
Date: Wed Nov 19 18:36:22 2025 +0100
Rename to unlisten_errors
cklein@minitrueee:~/elastisys/needle$ npx mocha test/redirect_with_bad_redirector.js
redirects with bad redirector
✓ calls back exactly once
✓ calls back exactly once with follow_keep_method
2 passing (35ms)Without the fix: cklein@minitrueee:~/elastisys/needle$ git diff
diff --git a/lib/needle.js b/lib/needle.js
index 9a116a4..fd462d3 100644
--- a/lib/needle.js
+++ b/lib/needle.js
@@ -564,7 +564,7 @@ Needle.prototype.send_request = function(count, method, uri, config, post_data,
var redirect_url = utils.resolve_url(headers.location, uri);
debug('Redirecting to ' + redirect_url.toString());
- unlisten_errors();
+ //unlisten_errors();
return self.send_request(++count, method, redirect_url.toString(), config, post_data, out, callback);
} else if (config.follow_max > 0) {
return done(new Error('Max redirects reached. Possible loop in: ' + headers.location));
cklein@minitrueee:~/elastisys/needle$ npx mocha test/redirect_with_bad_redirector.js
redirects with bad redirector
✓ calls back exactly once
1) calls back exactly once
✓ calls back exactly once with follow_keep_method
2) calls back exactly once with follow_keep_method
2 passing (41ms)
2 failing
1) redirects with bad redirector
calls back exactly once:
Error: done() called multiple times
at /home/cklein/elastisys/needle/test/redirect_with_bad_redirector.js:49:7
at done (lib/needle.js:479:14)
at PassThrough.<anonymous> (lib/needle.js:740:9)
at PassThrough.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1698:12)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
2) redirects with bad redirector
calls back exactly once with follow_keep_method:
Error: done() called multiple times
at /home/cklein/elastisys/needle/test/redirect_with_bad_redirector.js:62:7
at done (lib/needle.js:479:14)
at PassThrough.<anonymous> (lib/needle.js:740:9)
at PassThrough.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1698:12)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
Does this help confirm that the fix works as intended? |
|
Yup, perfect. I'll go ahead and merge. Thanks! |
@tomas Unsure if this is the right fix, but
npx mocha test/redirect_with_bad_redirector.jspasses. It could be that some more stuff needs to be cleared before sending the second request. Perhapsdone()needs something like apartialparameters, so it does most of the cleanup, except callingcallback.