Skip to content

Commit a7b53aa

Browse files
committed
Make WebSocketUpgradeHandler extensible in a controlled manner, backport #1446
1 parent a22041c commit a7b53aa

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

client/src/main/java/org/asynchttpclient/ws/WebSocketUpgradeHandler.java

+28-13
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,32 @@ public void bufferFrame(Runnable bufferedFrame) {
4848
bufferedFrames.add(bufferedFrame);
4949
}
5050

51-
@Override
52-
public final void onThrowable(Throwable t) {
53-
onFailure(t);
54-
}
51+
protected void onStatusReceived0(HttpResponseStatus responseStatus) throws Exception {}
5552

56-
public boolean touchSuccess() {
57-
boolean prev = onSuccessCalled;
58-
onSuccessCalled = true;
59-
return prev;
60-
}
53+
protected void onHeadersReceived0(HttpResponseHeaders headers) throws Exception {}
6154

62-
@Override
63-
public final State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
64-
return State.CONTINUE;
65-
}
55+
protected void onBodyPartReceived0(HttpResponseBodyPart bodyPart) throws Exception {}
56+
57+
protected void onCompleted0() throws Exception {}
58+
59+
protected void onThrowable0(Throwable t) {}
6660

6761
@Override
6862
public final State onStatusReceived(HttpResponseStatus responseStatus) throws Exception {
63+
onStatusReceived0(responseStatus);
6964
status = responseStatus.getStatusCode();
7065
return status == SWITCHING_PROTOCOLS ? State.UPGRADE : State.ABORT;
7166
}
7267

7368
@Override
7469
public final State onHeadersReceived(HttpResponseHeaders headers) throws Exception {
70+
onHeadersReceived0(headers);
71+
return State.CONTINUE;
72+
}
73+
74+
@Override
75+
public final State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
76+
onBodyPartReceived0(bodyPart);
7577
return State.CONTINUE;
7678
}
7779

@@ -85,9 +87,22 @@ public final WebSocket onCompleted() throws Exception {
8587
throw e;
8688
}
8789

90+
onCompleted0();
8891
return webSocket;
8992
}
9093

94+
@Override
95+
public final void onThrowable(Throwable t) {
96+
onThrowable0(t);
97+
onFailure(t);
98+
}
99+
100+
public boolean touchSuccess() {
101+
boolean prev = onSuccessCalled;
102+
onSuccessCalled = true;
103+
return prev;
104+
}
105+
91106
@Override
92107
public final void onSuccess(WebSocket webSocket) {
93108
this.webSocket = webSocket;

0 commit comments

Comments
 (0)