Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,22 @@ exports.request = function(options, cb) {
return new ClientRequest(options, cb);
};

exports.get = function(options, cb) {
var req = exports.request(options, cb);
req.end();
return req;
};
function shortcutMethod(method) {
return function(options, cb) {
options['method'] = method;
var req = exports.request(options, cb);
Copy link
Contributor

Choose a reason for hiding this comment

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

what if you want to write to the request? Like on a POST or PUT?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, in my current code I have
'Content-Length': body ? Buffer.byteLength(body) : 0,

Then later on:
body && req.write(body);

But for now just want to get some sort of idea if people even want this new shortcut feature implemented.

req.end();
return req;
}
}

exports.get = shortcutMethod('GET');
exports.head = shortcutMethod('HEAD');
exports.post = shortcutMethod('POST');
exports.put = shortcutMethod('PUT');
exports.del = shortcutMethod('DELETE');
exports['delete'] = exports.del;
exports.patch = shortcutMethod('PATCH');

exports._connectionListener = server._connectionListener;
const Server = exports.Server = server.Server;
Expand Down