Permalink
Browse files

Allowed options to be changed in http and https servers on the fly by…

… altering how the request handler is bound
  • Loading branch information...
1 parent a7a786c commit 943995eeafeb37a6d72c20bdff43dc24807d84e6 @tedeh committed Jan 8, 2013
Showing with 16 additions and 8 deletions.
  1. +5 −1 lib/server/http.js
  2. +5 −1 lib/server/https.js
  3. +5 −5 lib/utils.js
  4. +1 −1 package.json
View
@@ -12,7 +12,11 @@ var utils = require('../utils');
*/
var HttpServer = function(server, options) {
if(!(this instanceof HttpServer)) return new HttpServer(server, options);
- http.Server.call(this, utils.httpRequestWrapper(server, options));
+
+ this.options = utils.merge(server.options, options || {});
+
+ var requestWrapper = utils.httpRequestWrapper.bind(this);
+ http.Server.call(this, requestWrapper(server));
};
utils.inherits(HttpServer, http.Server);
View
@@ -12,7 +12,11 @@ var utils = require('../utils');
*/
var HttpsServer = function(server, options) {
if(!(this instanceof HttpsServer)) return new HttpsServer(server, options);
- https.Server.call(this, utils.httpRequestWrapper(server, options));
+
+ this.options = utils.merge(server.options, options || {});
+
+ var requestWrapper = utils.httpRequestWrapper.bind(this);
+ https.Server.call(this, requestWrapper(server));
};
utils.inherits(HttpsServer, https.Server);
View
@@ -111,15 +111,15 @@ Utils.parseBody = function(req, reviver, callback) {
};
/**
- * Wraps a server instance around a HTTP request listener (used by the HTTP and HTTPS server modules)
- * @param {JaysonServer} server Instance of JaysonServer (typically jayson.Server.http or jayson.Server.https)
- * @param {Object} [options] Optional name => value pairs of settings
+ * Returns a HTTP request listener bound to the server in the argument. "this" must be an instanceof jayson.Server.http or jayson.Server.https
+ * @param {JaysonServer} server Instance of JaysonServer (typically jayson.Server)
* @return {Function}
* @api private
*/
-Utils.httpRequestWrapper = function(server, options) {
+Utils.httpRequestWrapper = function(server) {
+ var self = this;
return function(req, res) {
- options = Utils.merge(server.options, options || {});
+ var options = self.options || {};
// 405 method not allowed if not POST
if(!Utils.isMethod(req, 'POST')) return respondError('Method not allowed', 405, { 'allow': 'POST' });
View
@@ -1,6 +1,6 @@
{
"name": "jayson",
- "version": "1.0.5",
+ "version": "1.0.6",
"description": "JSON-RPC 2.0 compliant server and client",
"keywords": ["jsonrpc", "rpc", "json", "jsonrpc-2.0", "middleware", "connect", "express", "jquery", "fork", "cluster", "distributed", "relay"],
"author": "Tedde Lundgren <mail@tedeh.net> (http://tedeh.net)",

0 comments on commit 943995e

Please sign in to comment.