Skip to content

Commit

Permalink
fix batch 2
Browse files Browse the repository at this point in the history
  • Loading branch information
wzy1935 committed Aug 8, 2024
1 parent b5fae19 commit 6873522
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Please check the {@link io.vertx.httpproxy.interceptors.BodyTransformer} for oth

==== WebSocket interceptor

You can use WebSocket interceptor to wrap a interceptor to let it allow WebSocket handling:
You can use WebSocket interceptor to wrap an interceptor to let it allow WebSocket handling:

[source,java]
----
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/vertx/tests/WebSocketCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public void testWsWithCache(TestContext ctx) {
latch.complete();
}));
});
ws2.write(Buffer.buffer("v2"));
ws2.write(Buffer.buffer("v2")); // second WebSocket, send and reply "v2"
}));
}));
});
ws1.write(Buffer.buffer("v1"));
ws1.write(Buffer.buffer("v1")); // first WebSocket, send and reply "v1"
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ private SocketAddress backend(TestContext ctx, Async async) {
});
}

/**
* The interceptor adds a suffix to the uri. If uri is changed by the interceptor, it calls a hit.
*
* @param ctx the test context
* @param interceptor the added interceptor
* @param httpHit if interceptor changes the regular HTTP packet
* @param wsHit if interceptor changes the WebSocket packet
*/
private void testWithInterceptor(TestContext ctx, ProxyInterceptor interceptor, boolean httpHit, boolean wsHit) {
Async latch = ctx.async(4);
SocketAddress backend = backend(ctx, latch);
Expand Down Expand Up @@ -77,18 +85,21 @@ public void testNotInterceptor(TestContext ctx) {

@Test
public void testNotApplySocket(TestContext ctx) {
// this interceptor only applies to regular HTTP traffic
ProxyInterceptor interceptor = PathInterceptor.changePath(x -> x + "/updated");
testWithInterceptor(ctx, interceptor, true, false);
}

@Test
public void testWithSocketInterceptor(TestContext ctx) {
// this interceptor applies to both regular HTTP traffic and WebSocket handshake
ProxyInterceptor interceptor = WebSocketInterceptor.allow(PathInterceptor.changePath(x -> x + "/updated"));
testWithInterceptor(ctx, interceptor, true, true);
}

@Test
public void testOnlyHitSocket(TestContext ctx) {
// this interceptor only applies to WebSocket handshake
ProxyInterceptor interceptor = new ProxyInterceptor() {
@Override
public Future<ProxyResponse> handleProxyRequest(ProxyContext context) {
Expand Down

0 comments on commit 6873522

Please sign in to comment.