forked from eclipse-vertx/vert.x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issues with the new handshake API.
- Loading branch information
Showing
4 changed files
with
21 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import io.vertx.core.*; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.http.*; | ||
import io.vertx.core.impl.future.FutureImpl; | ||
import io.vertx.core.internal.ContextInternal; | ||
import io.vertx.core.net.HostAndPort; | ||
import io.vertx.core.net.SocketAddress; | ||
|
@@ -33,6 +34,7 @@ | |
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.RejectedExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; | ||
|
@@ -43,14 +45,15 @@ | |
* | ||
* @author <a href="mailto:[email protected]">Julien Viet</a> | ||
*/ | ||
public class ServerWebSocketHandshaker implements ServerWebSocketHandshake, ServerWebSocket { | ||
public class ServerWebSocketHandshaker extends FutureImpl<ServerWebSocket> implements ServerWebSocketHandshake, ServerWebSocket { | ||
|
||
private final Http1xServerRequest request; | ||
private final HttpServerOptions options; | ||
private final WebSocketServerHandshaker handshaker; | ||
private boolean done; | ||
|
||
public ServerWebSocketHandshaker(Http1xServerRequest request, WebSocketServerHandshaker handshaker, HttpServerOptions options) { | ||
super(request.context); | ||
this.request = request; | ||
this.handshaker = handshaker; | ||
this.options = options; | ||
|
@@ -93,7 +96,6 @@ public Future<ServerWebSocket> accept() { | |
try { | ||
ws = acceptHandshake(); | ||
} catch (Exception e) { | ||
e.printStackTrace(System.out); | ||
return rejectHandshake(BAD_REQUEST.code()) | ||
.transform(ar -> { | ||
if (ar.succeeded()) { | ||
|
@@ -104,7 +106,8 @@ public Future<ServerWebSocket> accept() { | |
} | ||
}); | ||
} | ||
return request.context.succeededFuture(ws); | ||
tryComplete(ws); | ||
return this; | ||
} | ||
|
||
@Override | ||
|
@@ -116,6 +119,7 @@ public Future<Void> reject(int sc) { | |
} | ||
done = true; | ||
} | ||
tryFail(new RejectedExecutionException()); // Not great but for now OK | ||
return rejectHandshake(sc); | ||
} | ||
|
||
|