Browse files

drop addHeader in favor of opts.headers

  • Loading branch information...
1 parent 642f62a commit 024af40baceba160e726f13cbb77da3e3e497bbc @substack committed Oct 10, 2011
Showing with 25 additions and 9 deletions.
  1. +18 −6 README.markdown
  2. +5 −0 example/forward.js
  3. +1 −1 package.json
  4. +1 −2 test/x_forwarded_for.js
View
24 README.markdown
@@ -66,24 +66,36 @@ req
The node http module request object.
-bounce(stream)
---------------
+bounce(stream, opts={})
+-----------------------
Call this function when you're ready to bounce the request to a stream.
The exact request that was received will be written to `stream` and future
incoming data will be piped to and from it.
-bounce(port), bounce(host, port)
---------------------------------
+You can specify header fields to insert into the request with `opts.headers`.
+
+For instance you might want to add an `"x-forwarded-for"` header:
+
+```javascript
+var bouncy = require('bouncy');
+
+bouncy(function (req, bounce) {
+ bounce(5000, { headers : 'x-forwarded-for' : req.socket.remoteAddress });
+}).listen(80);
+````
+
+bounce(port, ...), bounce(host, port, ...)
+------------------------------------------
These variants of `bounce()` are sugar for
`bounce(net.createConnection(port))`
and
`bounce(net.createConnection(port, host))`.
-var res = bounce.respond()
---------------------------
+bounce.respond()
+----------------
Return a new HTTP response object for the request.
This is useful if you need to write an error result.
View
5 example/forward.js
@@ -0,0 +1,5 @@
+var bouncy = require('bouncy');
+
+bouncy(function (req, bounce) {
+ bounce(8002, { headers : 'x-forwarded-for' : req.socket.remoteAddress });
+}).listen(8001);
View
2 package.json
@@ -1,7 +1,7 @@
{
"name" : "bouncy",
"description" : "Bounce HTTP requests around for a load balancer or http host router completely transparently",
- "version" : "0.0.5",
+ "version" : "0.1.0",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/bouncy.git"
View
3 test/x_forwarded_for.js
@@ -15,8 +15,7 @@ test('x-forwarded-for', function (t) {
var p1 = Math.floor(Math.random() * (Math.pow(2,16) - 1e4) + 1e4);
var s1 = bouncy(function (req, bounce) {
- bounce.addHeader('x-forwarded-for', '1.1.1.1');
- bounce(p0);
+ bounce(p0, { headers : { 'x-forwarded-for' : '1.1.1.1' } });
});
s1.listen(p1, connect);

0 comments on commit 024af40

Please sign in to comment.