Created
May 31, 2013 08:57
-
-
Save timoxley/5683728 to your computer and use it in GitHub Desktop.
trying to pipe net stream through http auth then back out as a net stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var net = require('net') | |
| var http = require('http') | |
| var auth = require('../') | |
| var server = net.createServer(function(socket) { | |
| socket.pipe(auth()).pipe(remoteConnection) | |
| }).listen(8081) | |
| var remoteServer = http.createServer(function(req, res) { | |
| console.log('remote!') | |
| res.end('Success') | |
| }).listen(9009) | |
| var remoteConnection = net.connect(9009) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var http = require('http') | |
| var net = require('net') | |
| var auth = require('http-auth') | |
| var httpDuplex = require('http-duplex') | |
| var through = require('through') | |
| var basic = auth({ | |
| authRealm : "Private area.", | |
| // username is mia, password is supergirl. | |
| authList : ['mia:{SHA}x511ncXd+4fOnYAotcGPFD0peYo='] | |
| }); | |
| var server = http.createServer() | |
| server.listen(7337) | |
| module.exports = function() { | |
| function handleRequest(req, res) { | |
| // Apply authentication to server. | |
| basic.apply(req, res, function(username) { | |
| // Your request handling logic goes there | |
| httpDuplex(req, res).pipe(stream) | |
| }) | |
| } | |
| stream = net.connect(7337, function() { | |
| server.once('request', handleRequest) | |
| }) | |
| return stream | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment