Skip to content

Loading…

fix request.defaults and 'close' event in response #22

Closed
wants to merge 3 commits into from

2 participants

@clement
  1. in request.defaults a typo and a misplaced return statement
  2. in request.defaults, override the options with default only if it is not set (===undefined)
  3. when receiving a close event on the response object, propagate also to the response as an end event.

Point 3. covers a case where the server hangs up on us in the middle of a response. Not sure it should be treated like an end event though. An specific error could make more sense.

@mikeal
request member

i'm a little concerned about this. once the bug in http responses is fixed and it properly emits "end" this might cause some bad side effects like end callbacks getting called twice.

Right. And it's unfortunately not the only event problem I'm getting with http.js. I guess I'll work around that somewhere outside request.

Closing the pull request.

@mikeal
request member

i'm gonna pull in these defaults fixes.

@clement clement closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 4 deletions.
  1. +5 −4 main.js
View
9 main.js
@@ -230,7 +230,8 @@ Request.prototype.request = function () {
options._redirectsFollowed = 0;
// Be a good stream and emit end when the response is finished.
// Hack to emit end on close becuase of a core bug that never fires end
- response.on('close', function () {options.emit('end')})
+ response.on('close', function () { options.emit('end');
+ response.emit('end')})
if (options.encoding) {
if (options.dests.length !== 0) {
@@ -322,9 +323,9 @@ request.defaults = function (options) {
var def = function (method) {
var d = function (opts, callback) {
for (i in options) {
- if (!opts[i]) opts[i] = options[i];
- return method(opts, callback);
+ if (opts[i] === undefined) opts[i] = options[i];
}
+ return method(opts, callback);
}
return d;
}
@@ -334,7 +335,7 @@ request.defaults = function (options) {
de.put = def(request.put);
de.head = def(request.head);
de.del = def(request.del);
- return d;
+ return de;
}
request.get = request;
Something went wrong with that request. Please try again.