Skip to content
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

Added feature to bind on stream emits via options #18

Merged
merged 7 commits into from Jul 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion request.js
Expand Up @@ -149,7 +149,21 @@ Request.prototype.init = function (options) {
options = {}
}
self.headers = self.headers ? copy(self.headers) : {}


// bind default events sent via options
// additional postman feature starts
if (options.bindOn) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a stricter type check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see request library doing it anywhere

Object.keys(options.bindOn).forEach(function (eventName) {
self.on(eventName, options.bindOn[eventName]);
});
}

if (options.bindOnce) {
Object.keys(options.bindOnce).forEach(function (eventName) {
self.once(eventName, options.bindOnce[eventName]);
});
}
// additional postman feature ends
// Delete headers with value undefined since they break
// ClientRequest.OutgoingMessage.setHeader in node 0.12
for (var headerName in self.headers) {
Expand Down