Skip to content

Commit 6df7fbd

Browse files
committed
create function to handle upstream data
1 parent 229b914 commit 6df7fbd

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

tcp-proxy.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,7 @@ TcpProxy.prototype.handleClient = function(proxySocket) {
126126
proxySocket: proxySocket
127127
};
128128
proxySocket.on("data", function(data) {
129-
if (context.connected) {
130-
context.serviceSocket.write(
131-
self.intercept(self.options.upstream, context, data));
132-
} else {
133-
context.buffers[context.buffers.length] =
134-
self.intercept(self.options.upstream, context, data);
135-
if (context.serviceSocket === undefined) {
136-
self.createServiceSocket(context);
137-
}
138-
}
129+
self.handleUpstreamData(context, data);
139130
});
140131
proxySocket.on("close", function(hadError) {
141132
delete self.proxySockets[uniqueKey(proxySocket)];
@@ -148,6 +139,20 @@ TcpProxy.prototype.handleClient = function(proxySocket) {
148139
});
149140
};
150141

142+
TcpProxy.prototype.handleUpstreamData = function(context, data) {
143+
var self = this;
144+
if (context.connected) {
145+
context.serviceSocket.write(
146+
self.intercept(self.options.upstream, context, data));
147+
} else {
148+
context.buffers[context.buffers.length] =
149+
self.intercept(self.options.upstream, context, data);
150+
if (context.serviceSocket === undefined) {
151+
self.createServiceSocket(context);
152+
}
153+
}
154+
};
155+
151156
TcpProxy.prototype.createServiceSocket = function(context) {
152157
var self = this;
153158
var i = self.getServiceHostIndex(context.proxySocket);

0 commit comments

Comments
 (0)