Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add https.get()

  • Loading branch information...
commit db8736ad93231986b747e21131719fdacdf39a02 1 parent e65f6b4
@ry ry authored
Showing with 30 additions and 1 deletion.
  1. +20 −1 doc/api/https.markdown
  2. +10 −0 lib/https.js
View
21 doc/api/https.markdown
@@ -23,9 +23,10 @@ Example:
}).listen(8000);
-## https.request
+## https.request(options, callback)
Makes a request to a secure web server.
+Similar options to `http.request()`.
Example:
@@ -52,7 +53,25 @@ Example:
console.error(e);
});
+## https.get(options, callback)
+Like `http.get()` but for HTTPS.
+
+Example:
+
+ var https = require('https');
+
+ https.get({ host: 'encrypted.google.com', path: '/' }, function(res) {
+ console.log("statusCode: ", res.statusCode);
+ console.log("headers: ", res.headers);
+
+ res.on('data', function(d) {
+ process.stdout.write(d);
+ });
+
+ }).on('error', function(e) {
+ console.error(e);
+ });
View
10 lib/https.js
@@ -44,6 +44,8 @@ Agent.prototype._getConnection = function(host, port, cb) {
function getAgent(options) {
+ if (!options.port) options.port = 443;
+
var id = options.host + ':' + options.port;
var agent = agents[id];
@@ -59,3 +61,11 @@ exports.request = function(options, cb) {
var agent = getAgent(options);
return http._requestFromAgent(agent, options, cb);
};
+
+
+exports.get = function(options, cb) {
+ options.method = 'GET';
+ var req = exports.request(options, cb);
+ req.end();
+ return req;
+};
Please sign in to comment.
Something went wrong with that request. Please try again.