Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

using parse_args, passing most of the bounce_url tests now

  • Loading branch information...
commit 97640a7192b25796a24bf805c280d2b47182fa74 1 parent 80059a6
James Halliday authored
Showing with 25 additions and 14 deletions.
  1. +14 −2 index.js
  2. +11 −12 lib/parse_args.js
16 index.js
View
@@ -1,17 +1,29 @@
var http = require('http');
var through = require('through');
+var parseArgs = require('./lib/parse_args.js');
module.exports = function (cb) {
var server = http.createServer();
server.on('connection', function (stream) {
- var src = stream._bouncySource = through();
+ var src = stream._bouncyStream = through();
src.pause();
stream.pipe(src);
});
server.on('request', function (req, res) {
- var src = req.connection._bouncySource;
+ var src = req.connection._bouncyStream;
var bounce = function (dst) {
+ if (!dst || typeof dst.pipe !== 'function') {
+ dst = parseArgs(arguments);
+ }
+
+ function destroy () {
+ src.destroy();
+ dst.destroy();
+ }
+ src.on('error', destroy);
+ dst.on('error', destroy);
+
src.pipe(dst).pipe(req.connection);
src.resume();
};
23 lib/parse_args.js
View
@@ -36,17 +36,16 @@ module.exports = function (args) {
}
}
- if (!opts.stream) {
- if (opts.unix) {
- opts.stream = net.connect(opts.unix);
- }
- else if (opts.host && opts.port) {
- opts.stream = net.connect(opts.port, opts.host);
- }
- else if (opts.port) {
- opts.stream = net.connect(opts.port);
- }
+ if (opts.stream) {
+ return opts.stream;
+ }
+ else if (opts.unix) {
+ return net.connect(opts.unix);
+ }
+ else if (opts.host && opts.port) {
+ return net.connect(opts.port, opts.host);
+ }
+ else if (opts.port) {
+ return net.connect(opts.port);
}
-
- return opts;
}
Please sign in to comment.
Something went wrong with that request. Please try again.