Use predefined HttpResponseStatus constant instead of hardcoded 101 code

Motivation:

#7269 removed an unnecessary instanciation for verifying WebSocket
handshake status code.
But it uses a hardcoded status code value for 101 instead of using the
intended `HttpResponseStatus#SWITCHING_PROTOCOLS` constant.

Modidication:

Compare actual `HttpResponseStatus` against predefined constant. Note
that `HttpResponseStatus#equals` is implemented in respect with the RFC
(only honor code, not text) so it’s intended to be used this way.

Result:

Cleaner code, use intended constant instead of hard coded value.
This commit is contained in:
Stephane Landelle 2017-10-02 09:19:23 +02:00 committed by Norman Maurer
parent bb1833f22c
commit 940f15f0d2

View File

@ -24,6 +24,7 @@ import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.HttpVersion;
import io.netty.util.AsciiString; import io.netty.util.AsciiString;
@ -177,7 +178,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
*/ */
@Override @Override
protected void verify(FullHttpResponse response) { protected void verify(FullHttpResponse response) {
if (response.status().code() != 101) { if (!response.status().equals(HttpResponseStatus.SWITCHING_PROTOCOLS)) {
throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.status()); throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.status());
} }