Permalink
Browse files

forgot to put the example in the readme

  • Loading branch information...
1 parent 8c2546e commit e5c3561cc36695dd6184ec7620f5de1a3ce76807 @substack committed Sep 23, 2012
Showing with 30 additions and 0 deletions.
  1. +30 −0 readme.markdown
View
@@ -6,6 +6,36 @@ Turn (req,res) pairs into a single readable/writable stream.
# example
+``` js
+var httpDuplex = require('http-duplex');
+var http = require('http');
+var fs = require('fs');
+
+var server = http.createServer(function (req, res) {
+ var dup = httpDuplex(req, res);
+ console.log(dup.method + ' ' + dup.url);
+
+ dup.setHeader('content-type', 'text/plain');
+
+ if (dup.method === 'POST') {
+ dup.pipe(process.stdout, { end : false });
+ dup.on('end', function () {
+ dup.end('ok\n');
+ });
+ }
+ else fs.createReadStream(__filename).pipe(dup)
+});
+
+server.listen(8484);
+```
+
+```
+$ curl -s http://localhost:8484 | tail -n1
+server.listen(8484);
+$ curl -sd 'beep boop' http://localhost:8484
+ok
+```
+
# methods
``` js

0 comments on commit e5c3561

Please sign in to comment.