mirror of
https://github.com/jlengrand/vert.x.git
synced 2026-03-10 08:51:19 +00:00
Adjustements
This commit is contained in:
@@ -98,12 +98,6 @@ public interface ServerWebSocket extends WebSocketBase {
|
||||
@Nullable
|
||||
String query();
|
||||
|
||||
/**
|
||||
* @return the headers in the WebSocket handshake
|
||||
*/
|
||||
@CacheReturn
|
||||
MultiMap headers();
|
||||
|
||||
/**
|
||||
* Accept the WebSocket and terminate the WebSocket handshake.
|
||||
* <p/>
|
||||
|
||||
@@ -101,11 +101,11 @@ public interface WebSocketBase extends ReadStream<Buffer>, WriteStream<Buffer> {
|
||||
String closeReason();
|
||||
|
||||
/**
|
||||
* Returns the HTTP response headers during the websocket connection handler.
|
||||
* Returns the HTTP headers when the WebSocket is first obtained in the handler.
|
||||
* <p/>
|
||||
* After the completion handler callback has completed the response headers will be {@code null}
|
||||
* The headers will be {@code null} on subsequent interactions.
|
||||
*
|
||||
* @return the response headers
|
||||
* @return the headers
|
||||
*/
|
||||
MultiMap headers();
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ public class ServerWebSocketImpl extends WebSocketImplBase<ServerWebSocketImpl>
|
||||
private final String path;
|
||||
private final String query;
|
||||
private final WebSocketServerHandshaker handshaker;
|
||||
private final MultiMap headers;
|
||||
private HttpServerRequestImpl request;
|
||||
private Integer status;
|
||||
private Promise<Integer> handshakePromise;
|
||||
@@ -68,9 +67,10 @@ public class ServerWebSocketImpl extends WebSocketImplBase<ServerWebSocketImpl>
|
||||
this.uri = request.uri();
|
||||
this.path = request.path();
|
||||
this.query = request.query();
|
||||
this.headers = request.headers();
|
||||
this.request = request;
|
||||
this.handshaker = handshaker;
|
||||
|
||||
headers(request.headers());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,11 +88,6 @@ public class ServerWebSocketImpl extends WebSocketImplBase<ServerWebSocketImpl>
|
||||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiMap headers() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept() {
|
||||
if (tryHandshake(SC_SWITCHING_PROTOCOLS) != Boolean.TRUE) {
|
||||
|
||||
@@ -1057,34 +1057,26 @@ public class WebSocketTest extends VertxTestBase {
|
||||
|
||||
@Test
|
||||
// Test server accepting no compression
|
||||
public void testConnectWithWebsocketComressionDisabled() throws Exception {
|
||||
String path = "/some/path";
|
||||
Buffer buff = Buffer.buffer("AAA");
|
||||
public void testConnectWithWebSocketCompressionDisabled() throws Exception {
|
||||
String path = "/some/path";
|
||||
Buffer buff = Buffer.buffer("AAA");
|
||||
|
||||
// Server should have basic compression enabled by default,
|
||||
// client needs to ask for it
|
||||
server = vertx.createHttpServer(new HttpServerOptions()
|
||||
.setPort(DEFAULT_HTTP_PORT)
|
||||
.setPerFrameWebsocketCompressionSupported(false)
|
||||
.setPerMessageWebsocketCompressionSupported(false)
|
||||
).websocketHandler(ws -> {
|
||||
|
||||
assertEquals("upgrade", ws.headers().get("Connection"));
|
||||
assertNull(ws.headers().get("sec-websocket-extensions"));
|
||||
|
||||
ws.writeFrame(WebSocketFrame.binaryFrame(buff, true));
|
||||
});
|
||||
|
||||
|
||||
server.listen(ar -> {
|
||||
assertTrue(ar.succeeded());
|
||||
|
||||
HttpClientOptions options = new HttpClientOptions();
|
||||
|
||||
client = vertx.createHttpClient(options);
|
||||
|
||||
client.webSocket(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, path, onSuccess(ws -> {
|
||||
// Server should have basic compression enabled by default,
|
||||
// client needs to ask for it
|
||||
server = vertx.createHttpServer(new HttpServerOptions()
|
||||
.setPort(DEFAULT_HTTP_PORT)
|
||||
.setPerFrameWebsocketCompressionSupported(false)
|
||||
.setPerMessageWebsocketCompressionSupported(false)
|
||||
).websocketHandler(ws -> {
|
||||
assertEquals("upgrade", ws.headers().get("Connection"));
|
||||
assertNull(ws.headers().get("sec-websocket-extensions"));
|
||||
ws.writeFrame(WebSocketFrame.binaryFrame(buff, true));
|
||||
});
|
||||
|
||||
server.listen(onSuccess(s -> {
|
||||
HttpClientOptions options = new HttpClientOptions();
|
||||
client = vertx.createHttpClient(options);
|
||||
client.webSocket(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, path, onSuccess(ws -> {
|
||||
final Buffer received = Buffer.buffer();
|
||||
ws.handler(data -> {
|
||||
received.appendBuffer(data);
|
||||
@@ -1095,8 +1087,8 @@ public class WebSocketTest extends VertxTestBase {
|
||||
}
|
||||
});
|
||||
}));
|
||||
});
|
||||
await();
|
||||
}));
|
||||
await();
|
||||
}
|
||||
|
||||
private void testValidSubProtocol(WebsocketVersion version) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user