Skip to content

Commit 9ff9e38

Browse files
authored
Merge pull request #248 from consideRatio/inline-docs-and-potential-fixes
Emit proxyRequestWs events correctly, and some inline docs
2 parents 562b253 + b635d86 commit 9ff9e38

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lib/configproxy.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,11 @@ class ConfigurableProxy extends EventEmitter {
496496
handleProxy(kind, req, res) {
497497
// proxy any request
498498
var that = this;
499+
500+
// handleProxy is invoked by handleProxyWeb and handleProxyWs, which pass
501+
// different arguments to handleProxy.
502+
// - handleProxyWeb: args = [req, res]
503+
// - handleProxyWs: args = [req, socket, head]
499504
var args = Array.prototype.slice.call(arguments, 1);
500505

501506
// get the proxy target
@@ -505,7 +510,12 @@ class ConfigurableProxy extends EventEmitter {
505510
return;
506511
}
507512

508-
that.emit("proxyRequest", req, res);
513+
if (kind === "web") {
514+
that.emit("proxyRequest", req, res);
515+
}
516+
else {
517+
that.emit("proxyRequestWs", req, res, args[2]);
518+
}
509519
var prefix = match.prefix;
510520
var target = match.target;
511521
that.log.debug("PROXY %s %s to %s", kind.toUpperCase(), req.url, target);
@@ -528,7 +538,9 @@ class ConfigurableProxy extends EventEmitter {
528538
that.handleProxyError(503, kind, req, res, e);
529539
});
530540

531-
// dispatch the actual method
541+
// dispatch the actual method, either:
542+
// - proxy.web(req, res, options, errorHandler)
543+
// - proxy.ws(req, socket, head, options, errorHandler)
532544
that.proxy[kind].apply(that.proxy, args);
533545

534546
// update timestamp on any request/reply data as well (this includes websocket data)
@@ -545,10 +557,10 @@ class ConfigurableProxy extends EventEmitter {
545557
});
546558
}
547559

548-
handleProxyWs(req, res, head) {
560+
handleProxyWs(req, socket, head) {
549561
// Proxy a websocket request
550562
this.statsd.increment("requests.ws", 1);
551-
return this.handleProxy("ws", req, res, head);
563+
return this.handleProxy("ws", req, socket, head);
552564
}
553565

554566
handleProxyWeb(req, res) {

0 commit comments

Comments
 (0)