Skip to content

Commit 4f24664

Browse files
committed
[api] add draft for proxystream
1 parent cedc5c4 commit 4f24664

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

lib/caronte/streams/forward.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function ForwardStream() {
2525

2626
Writable.call(this);
2727

28-
this.once('pipe', function() { self.onPipe() });
28+
this.once('pipe', function(pipe) { self.onPipe(pipe) });
2929
this.once('finish', function() { self.onFinish() });
3030
}
3131

lib/caronte/streams/proxy.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
var Duplex = require('stream').Duplex,
2+
common = require('../common'),
3+
http = require('http'),
4+
https = require('https');
5+
16
function ProxyStream() {
7+
var self = this;
8+
9+
Duplex.call(this);
10+
11+
this.once('pipe', function(pipe) { self.onPipe(pipe); });
12+
this.once('finish', function() { self.onFinish(); });
13+
}
14+
15+
ProxyStream.prototype.onPipe = function(request) {
16+
var self = this;
17+
18+
this.proxyReq = (options.ssl ? https : http).request(
19+
common.setupOutgoing(options.ssl || {}, options, request)
20+
);
21+
22+
this.proxyReq.once('response', function(response) {
23+
self.onResponse(response);
24+
})
25+
this.proxyReq.on('error', function() {}); // XXX TODO: add error handling
26+
}
27+
28+
ProxyStream.prototype.onFinish = function() {
229

3-
}
30+
}
31+
32+
ProxyStream.prototype.onResponse = function() {
33+
34+
}
35+
36+
ProxyStream.prototype._read = function() {}
37+
38+
ProxyStream.prototype._write = function() {}
39+
40+
require('util').inherits(ForwardStream, Duplex);

0 commit comments

Comments
 (0)