Skip to content

Commit f3561d6

Browse files
authored
Merge pull request #138 from mkurz/merge_main_into_2.0.x
Merge main into 2.0.x
2 parents 1c7245e + da35f50 commit f3561d6

File tree

6 files changed

+102
-36
lines changed

6 files changed

+102
-36
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "maven"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "monthly"

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- 2.0.x
7+
push:
8+
branches:
9+
- 2.0.x
10+
11+
jobs:
12+
build:
13+
strategy:
14+
matrix:
15+
java: [ '8', '11', '17' ]
16+
os: [ 'ubuntu-latest' ]
17+
runs-on: ${{ matrix.os }}
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Set up JDK
21+
uses: actions/setup-java@v3
22+
with:
23+
java-version: ${{ matrix.java }}
24+
distribution: 'temurin'
25+
cache: 'maven'
26+
- name: Build
27+
run: mvn --no-transfer-progress -B clean package

.travis.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Netty Reactive Streams
22

3-
[![Build Status](https://travis-ci.org/playframework/netty-reactive-streams.svg?branch=main)](https://travis-ci.org/playframework/netty-reactive-streams)
3+
[![Build Status](https://travis-ci.org/playframework/netty-reactive-streams.svg?branch=2.0.x)](https://travis-ci.org/playframework/netty-reactive-streams)
44

55
This provides a reactive streams implementation for Netty. Essentially it comes in the form of two channel handlers, one that publishes inbound messages received on a channel to a `Publisher`, and another that writes messages received by a `Subscriber` outbound.
66

netty-reactive-streams-http/src/test/java/com/typesafe/netty/http/WebSocketsTest.java

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import io.netty.channel.socket.nio.NioSocketChannel;
1616
import io.netty.handler.codec.http.*;
1717
import io.netty.handler.codec.http.websocketx.*;
18+
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler;
19+
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler;
1820
import io.netty.util.ReferenceCountUtil;
1921
import org.reactivestreams.Processor;
2022
import org.testng.annotations.AfterClass;
@@ -41,8 +43,12 @@ public class WebSocketsTest {
4143
private BlockingQueue<Object> clientEvents = new LinkedBlockingQueue<>();
4244
private int port;
4345

44-
@Test
45-
public void simpleWebSocket() throws Exception {
46+
/**
47+
* Note: withCompression and withoutExtensions will not work as compression requires Extensions.
48+
* @param withCompression Enable Compression for this test
49+
* @param withExtensions Enable WebSocket Extensions on the handshaker
50+
*/
51+
private void simpleWebSocket(final boolean withCompression, final boolean withExtensions) throws Exception {
4652
start(new AutoReadHandler() {
4753
@Override
4854
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
@@ -68,13 +74,13 @@ public WebSocketFrame apply(WebSocketFrame msg) throws Exception {
6874

6975
ctx.writeAndFlush(new DefaultWebSocketHttpResponse(request.protocolVersion(),
7076
HttpResponseStatus.valueOf(200), processor,
71-
new WebSocketServerHandshakerFactory("ws://127.0.0.1/" + port + "/", null, false)
77+
new WebSocketServerHandshakerFactory("ws://127.0.0.1/" + port + "/", null, withExtensions)
7278
));
7379
}
7480
}
75-
});
81+
}, withCompression);
7682

77-
makeWebSocketRequest();
83+
makeWebSocketRequest(withCompression, withExtensions);
7884
assertNoMessages();
7985
client.writeAndFlush(new TextWebSocketFrame("hello"));
8086
assertEquals(readTextFrame(), "echo hello");
@@ -106,6 +112,21 @@ public WebSocketFrame apply(WebSocketFrame msg) throws Exception {
106112
assertNoMessages();
107113
}
108114

115+
@Test
116+
public void simpleWebSocketWithCompressionAndExtensions() throws Exception {
117+
simpleWebSocket(true, true);
118+
}
119+
120+
@Test
121+
public void simpleWebSocketWithoutCompressionWithoutExtensions() throws Exception {
122+
simpleWebSocket(false, false);
123+
}
124+
125+
@Test
126+
public void simpleWebSocketWithoutCompressionWithExtensions() throws Exception {
127+
simpleWebSocket(false, true);
128+
}
129+
109130
@Test
110131
public void rejectWebSocket() throws Exception {
111132
start(new AutoReadHandler() {
@@ -166,6 +187,10 @@ public void closeChannels() throws InterruptedException {
166187
}
167188

168189
private void start(final ChannelHandler handler) throws InterruptedException {
190+
start(handler, false);
191+
}
192+
193+
private void start(final ChannelHandler handler, final boolean enableCompression) throws InterruptedException {
169194
ServerBootstrap bootstrap = new ServerBootstrap();
170195
bootstrap.group(eventLoop)
171196
.channel(NioServerSocketChannel.class)
@@ -179,8 +204,14 @@ protected void initChannel(SocketChannel ch) throws Exception {
179204
pipeline.addLast(
180205
new HttpRequestDecoder(),
181206
new HttpResponseEncoder()
182-
).addLast("serverStreamsHandler", new HttpStreamsServerHandler())
183-
.addLast(handler);
207+
);
208+
209+
if (enableCompression) {
210+
pipeline.addLast(new WebSocketServerCompressionHandler());
211+
}
212+
pipeline
213+
.addLast("serverStreamsHandler", new HttpStreamsServerHandler())
214+
.addLast(handler);
184215
}
185216
});
186217

@@ -197,8 +228,11 @@ protected void initChannel(SocketChannel ch) throws Exception {
197228
protected void initChannel(SocketChannel ch) throws Exception {
198229
final ChannelPipeline pipeline = ch.pipeline();
199230

200-
pipeline.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192))
201-
.addLast(new AutoReadHandler() {
231+
pipeline.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192));
232+
233+
if (enableCompression) pipeline.addLast(WebSocketClientCompressionHandler.INSTANCE);
234+
235+
pipeline.addLast(new AutoReadHandler() {
202236
// Store a reference to the current client events
203237
BlockingQueue<Object> events = clientEvents;
204238
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
@@ -211,12 +245,20 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
211245
this.client = client.remoteAddress(serverBindChannel.localAddress()).connect().await().channel();
212246
}
213247

214-
private void makeWebSocketRequest() throws InterruptedException {
248+
private void makeWebSocketRequest(final boolean withCompression, final boolean withExtensions) throws InterruptedException {
215249
WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(
216250
URI.create("ws://127.0.0.1:" + port + "/"),
217-
WebSocketVersion.V13, null, false, new DefaultHttpHeaders());
251+
WebSocketVersion.V13, null, withExtensions, new DefaultHttpHeaders());
218252
handshaker.handshake(client);
219253
FullHttpResponse response = receiveFullResponse();
254+
HttpHeaders headers = response.headers();
255+
if (withCompression) {
256+
assertTrue(headers.contains("sec-websocket-extensions"));
257+
assertEquals(headers.get("sec-websocket-extensions"), "permessage-deflate");
258+
} else {
259+
assertTrue(!headers.contains("sec-websocket-extensions") ||
260+
!headers.get("sec-websocket-extensions").contains("permessage-deflate"));
261+
}
220262
handshaker.finishHandshake(client, response);
221263
}
222264

pom.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<dependency>
7272
<groupId>org.testng</groupId>
7373
<artifactId>testng</artifactId>
74-
<version>7.0.0</version>
74+
<version>7.5</version>
7575
<scope>test</scope>
7676
</dependency>
7777
<dependency>
@@ -84,19 +84,19 @@
8484
</dependencyManagement>
8585

8686
<properties>
87-
<netty.version>4.1.52.Final</netty.version>
87+
<netty.version>4.1.75.Final</netty.version>
8888
<reactive-streams.version>1.0.3</reactive-streams.version>
89-
<akka-stream.version>2.6.10</akka-stream.version>
90-
<maven-bundle-plugin.version>3.5.1</maven-bundle-plugin.version>
91-
<maven-jar-plugin.version>3.1.0</maven-jar-plugin.version>
89+
<akka-stream.version>2.6.19</akka-stream.version>
90+
<maven-bundle-plugin.version>5.1.4</maven-bundle-plugin.version>
91+
<maven-jar-plugin.version>3.2.2</maven-jar-plugin.version>
9292
</properties>
9393

9494
<build>
9595
<plugins>
9696
<plugin>
9797
<groupId>org.apache.maven.plugins</groupId>
9898
<artifactId>maven-compiler-plugin</artifactId>
99-
<version>3.8.1</version>
99+
<version>3.10.1</version>
100100
<configuration>
101101
<source>1.7</source>
102102
<target>1.7</target>
@@ -105,7 +105,7 @@
105105
<plugin>
106106
<groupId>org.sonatype.plugins</groupId>
107107
<artifactId>nexus-staging-maven-plugin</artifactId>
108-
<version>1.6.7</version>
108+
<version>1.6.12</version>
109109
<extensions>true</extensions>
110110
<configuration>
111111
<serverId>ossrh</serverId>
@@ -116,7 +116,7 @@
116116
<plugin>
117117
<groupId>org.apache.maven.plugins</groupId>
118118
<artifactId>maven-release-plugin</artifactId>
119-
<version>2.5</version>
119+
<version>2.5.3</version>
120120
<configuration>
121121
<autoVersionSubmodules>true</autoVersionSubmodules>
122122
<useReleaseProfile>false</useReleaseProfile>
@@ -159,7 +159,7 @@
159159
<plugin>
160160
<groupId>org.apache.maven.plugins</groupId>
161161
<artifactId>maven-source-plugin</artifactId>
162-
<version>3.0.1</version>
162+
<version>3.2.1</version>
163163
<executions>
164164
<execution>
165165
<id>attach-sources</id>
@@ -172,7 +172,7 @@
172172
<plugin>
173173
<groupId>org.apache.maven.plugins</groupId>
174174
<artifactId>maven-javadoc-plugin</artifactId>
175-
<version>2.9.1</version>
175+
<version>3.3.2</version>
176176
<executions>
177177
<execution>
178178
<id>attach-javadocs</id>
@@ -185,7 +185,7 @@
185185
<plugin>
186186
<groupId>org.apache.maven.plugins</groupId>
187187
<artifactId>maven-gpg-plugin</artifactId>
188-
<version>1.6</version>
188+
<version>3.0.1</version>
189189
<executions>
190190
<execution>
191191
<id>sign-artifacts</id>

0 commit comments

Comments
 (0)