Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

.respond() for convenience

  • Loading branch information...
commit 8a6510245e65f1ab66dc44c7776dd86ba7bfe349 1 parent e9d4e03
@substack authored
Showing with 13 additions and 6 deletions.
  1. +1 −1  bench/bouncy.js
  2. +1 −3 bin/bouncy.js
  3. +11 −2 index.js
View
2  bench/bouncy.js
@@ -1,4 +1,4 @@
-var bouncy = require('bouncy');
+var bouncy = require('../');
module.exports = function (port) {
return bouncy(function (req, bounce) { bounce(port) });
View
4 bin/bouncy.js
@@ -8,7 +8,6 @@ if (!configFile || !port) {
var fs = require('fs');
var config = JSON.parse(fs.readFileSync(configFile));
-var ServerResponse = require('http').ServerResponse;
var bouncy = require('bouncy');
bouncy(function (req, bounce) {
@@ -33,8 +32,7 @@ bouncy(function (req, bounce) {
bounce(route);
}
else {
- var res = new ServerResponse(req);
- res.assignSocket(req.socket);
+ var res = bounce.respond();
res.statusCode = 404;
res.write('no such host');
res.end();
View
13 index.js
@@ -1,4 +1,5 @@
var http = require('http');
+var ServerResponse = http.ServerResponse;
var parsers = http.parsers;
var net = require('net');
@@ -33,7 +34,7 @@ var handler = bouncy.handler = function (cb, c) {
req.socket.pause();
}
- cb(req, function (stream, y) {
+ var bounce = function (stream, y) {
if (!stream || !stream.write) {
stream = parseArgs(stream, y);
}
@@ -61,7 +62,15 @@ var handler = bouncy.handler = function (cb, c) {
stream.pipe(c);
req.resume();
}
- });
+ };
+
+ bounce.respond = function () {
+ var res = new ServerResponse(req);
+ res.assignSocket(req.socket);
+ return res;
+ };
+
+ cb(req, bounce);
};
c.on('data', function onData (buf) {
Please sign in to comment.
Something went wrong with that request. Please try again.