Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First stab at a HTTPS client

  • Loading branch information...
commit e433c11da2ddece47f3766a10b5b489db7635386 1 parent 147c22b
@tedeh authored
Showing with 51 additions and 2 deletions.
  1. +8 −1 lib/client.js
  2. +12 −1 lib/client/http.js
  3. +31 −0 lib/client/https.js
View
9 lib/client.js
@@ -34,13 +34,20 @@ utils.inherits(Client, events.EventEmitter);
module.exports = Client;
/**
- * HTTP(s) client constructor
+ * HTTP client constructor
* @type HttpClient
* @static
*/
Client.http = require('./client/http');
/**
+ * HTTPS client constructor
+ * @type HttpsClient
+ * @static
+ */
+Client.https = require('./client/https');
+
+/**
* Fork client constructor
* @type ForkClient
* @static
View
13 lib/client/http.js
@@ -45,9 +45,10 @@ HttpClient.prototype._request = function(request, callback) {
"Accept": "application/json"
};
+ // let user override the headers
options.headers = utils.merge(headers, options.headers || {});
- var req = http.request(options);
+ var req = self._getStream(options);
req.on('response', function(res) {
self.emit('http response', res);
@@ -83,3 +84,13 @@ HttpClient.prototype._request = function(request, callback) {
req.end(body);
});
};
+
+/**
+ * Gets a stream interface to a http server
+ * @param {Object} options An options object
+ * @return {require('http').ClientRequest}
+ * @api private
+ */
+HttpClient.prototype._getStream = function(options) {
+ return http.request(options || {});
+};
View
31 lib/client/https.js
@@ -0,0 +1,31 @@
+var https = require('https');
+var utils = require('../utils');
+var HttpClient = require('./http');
+
+/**
+ * Constructor for a Jayson HTTPS Client
+ * @class Jayson JSON-RPC HTTPS Client
+ * @constructor
+ * @extends HttpClient
+ * @param {Object|String} [options] Optional hash of settings or a URL
+ * @return {HttpsClient}
+ * @api public
+ */
+var HttpsClient = function(options) {
+ if(!(this instanceof HttpsClient)) return new HttpsClient(options);
+ // just proxy to constructor for HttpClient
+ HttpClient.call(this, options);
+};
+utils.inherits(HttpsClient, HttpClient);
+
+module.exports = HttpsClient;
+
+/**
+ * Gets a stream interface to a https server
+ * @param {Object} options An options object
+ * @return {require('https').ClientRequest}
+ * @api private
+ */
+HttpsClient.prototype._getStream = function(options) {
+ return https.request(options || {});
+};
Please sign in to comment.
Something went wrong with that request. Please try again.