Use Secure websockets if SslHandler is present in the ChannelPipeline. See #587
This commit is contained in:
parent
bd557a6330
commit
4353aa6794
|
@ -34,6 +34,11 @@
|
||||||
<artifactId>netty-codec</artifactId>
|
<artifactId>netty-codec</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>netty-handler</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,12 @@ import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||||
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.handler.codec.http.DefaultHttpResponse;
|
import io.netty.handler.codec.http.DefaultHttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpHeaders;
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
import io.netty.handler.codec.http.HttpRequest;
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
|
import io.netty.handler.ssl.SslHandler;
|
||||||
import io.netty.logging.InternalLogger;
|
import io.netty.logging.InternalLogger;
|
||||||
import io.netty.logging.InternalLoggerFactory;
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
|
@ -55,7 +57,7 @@ class WebSocketServerHandshakeHandler extends ChannelInboundMessageHandlerAdapte
|
||||||
}
|
}
|
||||||
|
|
||||||
final WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
|
final WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
|
||||||
getWebSocketLocation(req, websocketPath), subprotocols, allowExtensions);
|
getWebSocketLocation(ctx.pipeline(), req, websocketPath), subprotocols, allowExtensions);
|
||||||
final WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(req);
|
final WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(req);
|
||||||
if (handshaker == null) {
|
if (handshaker == null) {
|
||||||
wsFactory.sendUnsupportedWebSocketVersionResponse(ctx.channel());
|
wsFactory.sendUnsupportedWebSocketVersionResponse(ctx.channel());
|
||||||
|
@ -88,8 +90,13 @@ class WebSocketServerHandshakeHandler extends ChannelInboundMessageHandlerAdapte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getWebSocketLocation(HttpRequest req, String path) {
|
private static String getWebSocketLocation(ChannelPipeline cp, HttpRequest req, String path) {
|
||||||
return "ws://" + req.getHeader(HttpHeaders.Names.HOST) + path;
|
String protocol = "ws";
|
||||||
|
if (cp.get(SslHandler.class) != null) {
|
||||||
|
// SSL in use so use Secure WebSockets
|
||||||
|
protocol = "wss";
|
||||||
|
}
|
||||||
|
return protocol + "://" + req.getHeader(HttpHeaders.Names.HOST) + path;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user