Skip to content

Commit

Permalink
Set expectWebsockets to true for now to prevent other failures. Also …
Browse files Browse the repository at this point in the history
…add new test
  • Loading branch information
purplefox committed Jun 19, 2015
1 parent bfffa41 commit c800941
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/main/java/io/vertx/core/http/impl/HttpServerImpl.java
Expand Up @@ -90,7 +90,7 @@ public class HttpServerImpl implements HttpServer, Closeable, MetricsProvider {
private HttpServerImpl actualServer;
private ContextImpl listenContext;
private HttpServerMetrics metrics;
private boolean expectingWebsockets = false;
private boolean expectingWebsockets = true;

public HttpServerImpl(VertxInternal vertx, HttpServerOptions options) {
this.options = new HttpServerOptions(options);
Expand Down Expand Up @@ -212,7 +212,7 @@ protected void initChannel(Channel ch) throws Exception {
if (options.getIdleTimeout() > 0) {
pipeline.addLast("idle", new IdleStateHandler(0, 0, options.getIdleTimeout()));
}
pipeline.addLast("handler", new ServerHandler(vertx));
pipeline.addLast("handler", new ServerHandler());
}
});

Expand Down Expand Up @@ -430,7 +430,7 @@ private void executeCloseDone(final ContextImpl closeContext, final Handler<Asyn
public class ServerHandler extends VertxHttpHandler<ServerConnection> {
private boolean closeFrameSent;

public ServerHandler(VertxInternal vertx) {
public ServerHandler() {
super(HttpServerImpl.this.connectionMap);
}

Expand Down
32 changes: 27 additions & 5 deletions src/test/java/io/vertx/test/core/WebsocketTest.java
Expand Up @@ -1050,14 +1050,34 @@ public void testClearClientHandlersOnEnd() {

@Test
public void testUpgrade() {
testUpgrade(false);
}

@Test
public void testUpgradeDelayed() {
testUpgrade(true);
}

private void testUpgrade(boolean delayed) {
String path = "/some/path";
server = vertx.createHttpServer(new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT));
server.requestHandler(request -> {
ServerWebSocket ws = request.upgrade();
ws.handler(buff -> {
ws.write(Buffer.buffer("helloworld"));
ws.close();
});
Runnable runner = () -> {
ServerWebSocket ws = request.upgrade();
ws.handler(buff -> {
ws.write(Buffer.buffer("helloworld"));
ws.close();
});
};
if (delayed) {
// This tests the case where the last http content comes of the request (its not full) comes in
// before the upgrade has happened and before HttpServerImpl.expectWebsockets is true
vertx.runOnContext(v -> {
runner.run();
});
} else {
runner.run();
}
});
server.listen(ar -> {
assertTrue(ar.succeeded());
Expand All @@ -1077,6 +1097,8 @@ public void testUpgrade() {
await();
}



@Test
public void testUpgradeInvalidRequest() {
server = vertx.createHttpServer(new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT));
Expand Down

0 comments on commit c800941

Please sign in to comment.