Browse files

[minor] Fix whitespace

  • Loading branch information...
1 parent 1884602 commit 908ff5735ef58118ab76c99adc38e2b724afed5b @pksunkara pksunkara committed Apr 14, 2012
Showing with 67 additions and 67 deletions.
  1. +14 −14 lib/buffered-stream.js
  2. +15 −15 lib/core.js
  3. +3 −3 lib/http-stream.js
  4. +1 −1 lib/index.js
  5. +3 −3 lib/request-stream.js
  6. +15 −15 lib/response-stream.js
  7. +16 −16 lib/routing-stream.js
View
28 lib/buffered-stream.js
@@ -2,33 +2,33 @@
* buffered-stream.js: A simple(r) Stream which is partially buffered into memory.
*
* (C) 2010, Mikeal Rogers
- *
+ *
* Adapted for Flatiron
* (C) 2011, Nodejitsu Inc.
* MIT LICENSE
*
*/
-
+
var events = require('events'),
- fs = require('fs'),
- stream = require('stream'),
+ fs = require('fs'),
+ stream = require('stream'),
util = require('util');
//
// ### function BufferedStream (limit)
// #### @limit {number} **Optional** Size of the buffer to limit
-// Constructor function for the BufferedStream object responsible for
-// maintaining a stream interface which can also persist to memory
+// Constructor function for the BufferedStream object responsible for
+// maintaining a stream interface which can also persist to memory
// temporarily.
//
var BufferedStream = module.exports = function (limit) {
events.EventEmitter.call(this);
-
+
if (typeof limit === 'undefined') {
limit = Infinity;
}
-
+
this.limit = limit;
this.size = 0;
this.chunks = [];
@@ -43,9 +43,9 @@ BufferedStream.prototype.pipe = function () {
if (self.resume) {
self.resume();
}
-
+
var dest = stream.Stream.prototype.pipe.apply(self, arguments);
-
+
//
// just incase you are piping to two streams, do not emit data twice.
// note: you can pipe twice, but you need to pipe both streams in the same tick.
@@ -54,7 +54,7 @@ BufferedStream.prototype.pipe = function () {
if (this.piped) {
return dest;
}
-
+
process.nextTick(function () {
self.chunks.forEach(function (c) { self.emit('data', c) })
self.size = 0;
@@ -66,10 +66,10 @@ BufferedStream.prototype.pipe = function () {
}
else if (self.closed) {
self.emit('close');
- }
+ }
}
});
-
+
this.piped = true;
return dest;
@@ -80,7 +80,7 @@ BufferedStream.prototype.write = function (chunk) {
this.emit('data', chunk);
return;
}
-
+
this.chunks.push(chunk);
this.size += chunk.length;
if (this.limit < this.size) {
View
30 lib/core.js
@@ -1,5 +1,5 @@
/*
- * core.js: Core functionality for the Flatiron HTTP plugin.
+ * core.js: Core functionality for the Flatiron HTTP plugin.
*
* (C) 2011, Nodejitsu Inc.
* MIT LICENSE
@@ -12,30 +12,30 @@ var http = require('http'),
stream = require('stream'),
HttpStream = require('./http-stream'),
RoutingStream = require('./routing-stream');
-
+
var core = exports;
core.createServer = function (options) {
var isArray = Array.isArray(options.after);
-
+
if (!options) {
throw new Error('options is required to create a server');
}
-
+
function requestHandler(req, res) {
var routingStream = new RoutingStream({
before: options.before,
// without new after is a huge memory leak that pipes to every
// single open connection
- after: isArray &&
- options.after.map(function (a) {
- return new a;
+ after: isArray &&
+ options.after.map(function (a) {
+ return new a;
}),
response: res,
limit: options.limit,
headers: options.headers
});
-
+
routingStream.on('error', function (err) {
var fn = options.onError || core.errorHandler;
fn(err, routingStream, routingStream.target, function () {
@@ -44,24 +44,24 @@ core.createServer = function (options) {
});
req.pipe(routingStream);
}
-
+
if (options.https) {
if (!options.https.key || !options.https.cert) {
throw new Error('Both `options.https.key` and `options.https.cert` are required.');
}
-
+
var credentials = {
key: fs.readFileSync(options.https.key),
cert: fs.readFileSync(options.https.cert)
};
-
+
if (options.https.ca) {
credentials.ca = fs.readFileSync(options.https.ca);
}
-
+
return https.createServer(credentials, requestHandler);
- }
-
+ }
+
return http.createServer(requestHandler);
};
@@ -71,7 +71,7 @@ core.errorHandler = function error(err, req, res) {
(this.res || res).end(err.stack + "\n");
return;
}
-
+
(this.res || res).writeHead(404, {"Content-Type": "text/plain"});
(this.res || res).end("Not Found\n");
};
View
6 lib/http-stream.js
@@ -5,16 +5,16 @@
* MIT LICENSE
*
*/
-
+
var url = require('url'),
util = require('util'),
qs = require('qs'),
BufferedStream = require('./buffered-stream');
-
+
var HttpStream = module.exports = function (options) {
options = options || {};
BufferedStream.call(this, options.limit);
-
+
this.on('pipe', this.pipeState);
};
View
2 lib/index.js
@@ -5,7 +5,7 @@
* MIT LICENSE
*
*/
-
+
var union = exports;
//
View
6 lib/request-stream.js
@@ -5,16 +5,16 @@
* MIT LICENSE
*
*/
-
+
var url = require('url'),
util = require('util'),
qs = require('qs'),
HttpStream = require('./http-stream');
-
+
var RequestStream = module.exports = function (options) {
options = options || {};
HttpStream.call(this, options);
-
+
this.on('pipe', this.pipeRequest);
};
View
30 lib/response-stream.js
@@ -1,25 +1,25 @@
/*
- * response-stream.js: A Stream focused on writing any relevant information to
+ * response-stream.js: A Stream focused on writing any relevant information to
* a raw http.ServerResponse object.
*
* (C) 2011, Nodejitsu Inc.
* MIT LICENSE
*
*/
-
+
var util = require('util'),
HttpStream = require('./http-stream');
//
-// ### function RequestStream (options)
-//
-//
+// ### function RequestStream (options)
+//
+//
var ResponseStream = module.exports = function (options) {
var self = this;
options = options || {};
HttpStream.call(this, options);
-
+
this.writeable = true;
this.response = options.response;
@@ -71,12 +71,12 @@ ResponseStream.prototype.writeHead = function (statusCode, headers) {
this.response.setHeader(key, headers[key]);
}
}
-
+
this.response.statusCode = statusCode;
};
//
-// Create pass-thru for the necessary
+// Create pass-thru for the necessary
// `http.ServerResponse` methods.
//
['setHeader', 'getHeader', 'removeHeader', '_implicitHeader', 'addTrailers'].forEach(function (method) {
@@ -89,18 +89,18 @@ ResponseStream.prototype.json = function (obj) {
if (!this.response.writable) {
return;
}
-
+
if (typeof obj === 'number') {
this.response.statusCode = obj;
obj = arguments[1];
- }
-
+ }
+
this.modified = true;
-
+
if (!this.response._header && this.response.getHeader('content-type') !== 'application/json') {
this.response.setHeader('content-type', 'application/json');
}
-
+
this.end(obj ? JSON.stringify(obj) : '');
};
@@ -146,14 +146,14 @@ ResponseStream.prototype.end = function (data) {
if (data && this.writable) {
this.emit('data', data);
}
-
+
this.modified = true;
this.emit('end');
};
ResponseStream.prototype.write = function (data) {
this.modified = true;
-
+
if (this.writable) {
this.emit('data', data);
}
View
32 lib/routing-stream.js
@@ -6,20 +6,20 @@
* MIT LICENSE
*
*/
-
+
var util = require('util'),
union = require('./index'),
RequestStream = require('./request-stream'),
ResponseStream = require('./response-stream');
//
-// ### function RequestStream (options)
-//
-//
+// ### function RequestStream (options)
+//
+//
var RoutingStream = module.exports = function (options) {
options = options || {};
RequestStream.call(this, options);
-
+
this.before = options.before || [];
this.after = options.after || [];
this.response = options.response || options.res;
@@ -46,9 +46,9 @@ RoutingStream.prototype.route = function (req) {
// When a `RoutingStream` is piped to:
//
// 1. Setup the pipe-chain between the `after` middleware, the abstract response
- // and the concrete response.
- // 2. Attempt to dispatch to the `before` middleware, which represent things such as
- // favicon, static files, application routing.
+ // and the concrete response.
+ // 2. Attempt to dispatch to the `before` middleware, which represent things such as
+ // favicon, static files, application routing.
// 3. If no match is found then pipe to the 404Stream
//
var self = this,
@@ -57,8 +57,8 @@ RoutingStream.prototype.route = function (req) {
i;
// make sure data from req is piped on the `once` first call
- req.on('data', function () {
- self.emit.apply(self, ["data"].concat([].slice.call(arguments,0)));
+ req.on('data', function () {
+ self.emit.apply(self, ["data"].concat([].slice.call(arguments,0)));
});
//
@@ -68,7 +68,7 @@ RoutingStream.prototype.route = function (req) {
//
// 1. Setup the pipe-chain between the `after` middleware, the abstract response
- // and the concrete response.
+ // and the concrete response.
//
after = [this.target].concat(this.after, this.response);
for (i = 0; i < after.length - 1; i++) {
@@ -81,7 +81,7 @@ RoutingStream.prototype.route = function (req) {
// prevent multiple responses and memory leaks
after[i].on('error', this.onError);
}
-
+
//
// Helper function for dispatching to the 404 stream.
//
@@ -90,10 +90,10 @@ RoutingStream.prototype.route = function (req) {
error.status = 404;
self.onError(error);
}
-
+
//
- // 2. Attempt to dispatch to the `before` middleware, which represent things such as
- // favicon, static files, application routing.
+ // 2. Attempt to dispatch to the `before` middleware, which represent things such as
+ // favicon, static files, application routing.
//
(function dispatch(i) {
if (self.target.modified) {
@@ -119,7 +119,7 @@ RoutingStream.prototype.route = function (req) {
else {
self.before[i](self, self.target);
}
- })(-1);
+ })(-1);
};
RoutingStream.prototype.onError = function (err) {

0 comments on commit 908ff57

Please sign in to comment.