Skip to content

Commit

Permalink
print error message when handshaking failed
Browse files Browse the repository at this point in the history
  • Loading branch information
wkgcass committed Jun 13, 2020
1 parent 9bc07c4 commit cf7f697
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public void connected(ConnectableConnectionHandlerContext ctx) {
@Override
public void readable(ConnectionHandlerContext ctx) {
CommonProcess.parseUpgradeResp(ctx, httpRespParser,
/* fail */() -> {
Logger.error(LogType.CONN_ERROR, "handshake for the pool failed");
/* fail */msg -> {
Logger.error(LogType.CONN_ERROR, "handshake for the pool failed: " + msg);
cb.connectionError((ConnectableConnection) ctx.connection);
},
/* succ */() -> {
Expand Down Expand Up @@ -205,7 +205,7 @@ public void connected(ConnectableConnectionHandlerContext ctx) {
public void readable(ConnectionHandlerContext ctx) {
if (step == 1) {
CommonProcess.parseUpgradeResp(ctx, httpRespParser,
/* fail */ () -> utilAlertFail(ctx),
/* fail */ msg -> utilAlertFail(ctx),
/* succ */ () -> {
// remove the parser
httpRespParser = null;
Expand Down Expand Up @@ -592,13 +592,13 @@ static void sendUpgrade(ConnectableConnectionHandlerContext ctx, String domainOf
}

static void parseUpgradeResp(ConnectionHandlerContext ctx, HttpRespParser httpRespParser,
Runnable failCallback, Runnable successCallback) {
Consumer<String> failCallback, Runnable successCallback) {
// http
int res = httpRespParser.feed(ctx.connection.getInBuffer());
if (res != 0) {
String errMsg = httpRespParser.getErrorMessage();
if (errMsg != null) {
failCallback.run();
failCallback.accept(errMsg);
} // otherwise // want more data
return;
}
Expand All @@ -609,12 +609,12 @@ static void parseUpgradeResp(ConnectionHandlerContext ctx, HttpRespParser httpRe
// status code should be 101
if (resp.statusCode != 101) {
// the server refused to upgrade to WebSocket
failCallback.run();
failCallback.accept("statusCode " + resp.statusCode + " not 101");
return;
}
// check headers
if (!WebSocksUtils.checkUpgradeToWebSocketHeaders(resp.headers, true)) {
failCallback.run();
failCallback.accept("invalid headers");
return;
}

Expand Down

0 comments on commit cf7f697

Please sign in to comment.