Skip to content

Commit db8736a

Browse files
committed
Add https.get()
1 parent e65f6b4 commit db8736a

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

doc/api/https.markdown

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ Example:
2323
}).listen(8000);
2424

2525

26-
## https.request
26+
## https.request(options, callback)
2727

2828
Makes a request to a secure web server.
29+
Similar options to `http.request()`.
2930

3031
Example:
3132

@@ -52,7 +53,25 @@ Example:
5253
console.error(e);
5354
});
5455

56+
## https.get(options, callback)
5557

58+
Like `http.get()` but for HTTPS.
59+
60+
Example:
61+
62+
var https = require('https');
63+
64+
https.get({ host: 'encrypted.google.com', path: '/' }, function(res) {
65+
console.log("statusCode: ", res.statusCode);
66+
console.log("headers: ", res.headers);
67+
68+
res.on('data', function(d) {
69+
process.stdout.write(d);
70+
});
71+
72+
}).on('error', function(e) {
73+
console.error(e);
74+
});
5675

5776

5877

lib/https.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Agent.prototype._getConnection = function(host, port, cb) {
4444

4545

4646
function getAgent(options) {
47+
if (!options.port) options.port = 443;
48+
4749
var id = options.host + ':' + options.port;
4850
var agent = agents[id];
4951

@@ -59,3 +61,11 @@ exports.request = function(options, cb) {
5961
var agent = getAgent(options);
6062
return http._requestFromAgent(agent, options, cb);
6163
};
64+
65+
66+
exports.get = function(options, cb) {
67+
options.method = 'GET';
68+
var req = exports.request(options, cb);
69+
req.end();
70+
return req;
71+
};

0 commit comments

Comments
 (0)