Skip to content

Commit

Permalink
Improve WebSocket upgrade failure message
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Oct 1, 2021
1 parent fb9d397 commit 8810a4c
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
package io.vertx.core.http.impl;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
Expand Down Expand Up @@ -42,6 +43,7 @@
import io.vertx.core.http.impl.headers.HeadersAdaptor;

import java.net.URI;
import java.nio.charset.StandardCharsets;

import static io.netty.handler.codec.http.websocketx.WebSocketVersion.V00;
import static io.netty.handler.codec.http.websocketx.WebSocketVersion.V07;
Expand Down Expand Up @@ -112,7 +114,12 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
private Future<HeadersAdaptor> handshakeComplete(FullHttpResponse response) {
int sc = response.status().code();
if (sc != 101) {
UpgradeRejectedException failure = new UpgradeRejectedException("WebSocket connection attempt returned HTTP status code " + sc, sc);
String msg = "WebSocket upgrade failure: " + sc;
ByteBuf content = response.content();
if (content != null && content.readableBytes() > 0) {
msg += " (" + content.toString(StandardCharsets.UTF_8) + ")";
}
UpgradeRejectedException failure = new UpgradeRejectedException(msg, sc);
return Future.failedFuture(failure);
} else {
try {
Expand Down

0 comments on commit 8810a4c

Please sign in to comment.