Skip to content

Commit 2633532

Browse files
committed
Merge branch 'release/1.5.0'
2 parents c94f419 + 9a3beb4 commit 2633532

File tree

23 files changed

+701
-319
lines changed

23 files changed

+701
-319
lines changed

.github/workflows/ci-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
strategy:
1717
matrix:
18-
os: [ ubuntu-20.04, macos-13, windows-2019 ]
18+
os: [ ubuntu-24.04, macos-13, windows-2022 ]
1919
jdk: [ 8, 11, 17, 21 ]
2020
fail-fast: false
2121

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ callbacks codec (described below).
1414
* Websocket multiprotocol: for application servers, It provides transparent use of existing http1 websocket handlers to process both http1 and http2 websockets.
1515
Compatible with callbacks codec (described below).
1616

17-
[https://jauntsdn.com/post/netty-websocket-http2/](https://jauntsdn.com/post/netty-websocket-http2/)
17+
[https://jauntsdn.com/post/netty-websocket-http2/](https://jauntsdn.github.io/post/netty-websocket-http2/)
1818

1919
### much faster http1 codec
2020
Integration with [jauntsdn/netty-websocket-http1](https://github.com/jauntsdn/netty-websocket-http1) codec (callbacks codec) for websocket-http1
@@ -95,7 +95,7 @@ EchoWebSocketHandler http1WebSocketHandler = new EchoWebSocketHandler();
9595
Http2WebSocketClientHandshaker handShaker = Http2WebSocketClientHandshaker.create(channel);
9696
9797
Http2Headers headers =
98-
new DefaultHttp2Headers().set("user-agent", "jauntsdn-websocket-http2-client/1.3.0");
98+
new DefaultHttp2Headers().set("user-agent", "jauntsdn-websocket-http2-client/1.4.0");
9999
ChannelFuture handshakeFuture =
100100
/*http1 websocket handler*/
101101
handShaker.handshake("/echo", headers, new EchoWebSocketHandler());
@@ -320,7 +320,7 @@ repositories {
320320
}
321321
322322
dependencies {
323-
implementation 'com.jauntsdn.netty:netty-websocket-http2:1.3.0'
323+
implementation 'com.jauntsdn.netty:netty-websocket-http2:1.4.0'
324324
}
325325
```
326326

gradle.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
group=com.jauntsdn.netty
2-
version=1.4.0
2+
version=1.5.0
33

44
googleJavaFormatPluginVersion=0.9
55
dependencyManagementPluginVersion=1.1.0
66
gitPluginVersion=0.13.0
77
osDetectorPluginVersion=1.7.3
88
versionsPluginVersion=0.45.0
99

10-
nettyVersion=4.1.116.Final
11-
jauntNettyWebsocketHttp1=1.3.0
12-
nettyTcnativeVersion=2.0.69.Final
10+
nettyVersion=4.1.122.Final
11+
jauntNettyWebsocketHttp1=1.4.0
12+
nettyTcnativeVersion=2.0.72.Final
1313
hdrHistogramVersion=2.1.12
1414
slf4jVersion=1.7.36
1515
logbackVersion=1.2.13
1616
jsr305Version=3.0.2
1717

1818
junitVersion=5.11.4
19-
assertjVersion=3.27.0
19+
assertjVersion=3.27.3
2020

2121
org.gradle.parallel=true
2222
org.gradle.configureondemand=true

netty-websocket-http2-callbacks-codec/gradle.lockfile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ com.google.errorprone:javac-shaded:9+181-r4173-1=googleJavaFormat1.6
77
com.google.googlejavaformat:google-java-format:1.6=googleJavaFormat1.6
88
com.google.guava:guava:22.0=googleJavaFormat1.6
99
com.google.j2objc:j2objc-annotations:1.1=googleJavaFormat1.6
10-
com.jauntsdn.netty:netty-websocket-http1:1.3.0=compileClasspath
11-
io.netty:netty-buffer:4.1.116.Final=compileClasspath
12-
io.netty:netty-codec-http2:4.1.116.Final=compileClasspath
13-
io.netty:netty-codec-http:4.1.116.Final=compileClasspath
14-
io.netty:netty-codec:4.1.116.Final=compileClasspath
15-
io.netty:netty-common:4.1.116.Final=compileClasspath
16-
io.netty:netty-handler:4.1.116.Final=compileClasspath
17-
io.netty:netty-resolver:4.1.116.Final=compileClasspath
18-
io.netty:netty-transport-native-unix-common:4.1.116.Final=compileClasspath
19-
io.netty:netty-transport:4.1.116.Final=compileClasspath
10+
com.jauntsdn.netty:netty-websocket-http1:1.4.0=compileClasspath
11+
io.netty:netty-buffer:4.1.122.Final=compileClasspath
12+
io.netty:netty-codec-http2:4.1.122.Final=compileClasspath
13+
io.netty:netty-codec-http:4.1.122.Final=compileClasspath
14+
io.netty:netty-codec:4.1.122.Final=compileClasspath
15+
io.netty:netty-common:4.1.122.Final=compileClasspath
16+
io.netty:netty-handler:4.1.122.Final=compileClasspath
17+
io.netty:netty-resolver:4.1.122.Final=compileClasspath
18+
io.netty:netty-transport-native-unix-common:4.1.122.Final=compileClasspath
19+
io.netty:netty-transport:4.1.122.Final=compileClasspath
2020
org.codehaus.mojo:animal-sniffer-annotations:1.14=googleJavaFormat1.6
2121
empty=annotationProcessor

netty-websocket-http2-callbacks-codec/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/WebSocketCallbacksCodec.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.netty.handler.codec.http.websocketx.WebSocketDecoderConfig;
55
import io.netty.handler.codec.http.websocketx.WebSocketFrameDecoder;
66
import io.netty.handler.codec.http.websocketx.WebSocketFrameEncoder;
7+
import java.util.function.IntSupplier;
78

89
/** Provides integration with jauntsdn/netty-websocket-http1 - high performance websocket codec. */
910
public final class WebSocketCallbacksCodec implements Http1WebSocketCodec {
@@ -20,6 +21,11 @@ public WebSocketFrameEncoder encoder(boolean maskPayload) {
2021
return WebSocketProtocol.frameEncoder(maskPayload);
2122
}
2223

24+
@Override
25+
public WebSocketFrameEncoder encoder(boolean maskPayload, IntSupplier externalMask) {
26+
return WebSocketProtocol.frameEncoder(maskPayload, externalMask);
27+
}
28+
2329
@Override
2430
public WebSocketFrameDecoder decoder(WebSocketDecoderConfig config) {
2531
return WebSocketProtocol.frameDecoder(

netty-websocket-http2/gradle.lockfile

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ com.google.errorprone:javac-shaded:9+181-r4173-1=googleJavaFormat1.6
99
com.google.googlejavaformat:google-java-format:1.6=googleJavaFormat1.6
1010
com.google.guava:guava:22.0=googleJavaFormat1.6
1111
com.google.j2objc:j2objc-annotations:1.1=googleJavaFormat1.6
12-
com.jauntsdn.netty:netty-websocket-http1:1.3.0=testCompileClasspath,testRuntimeClasspath
13-
io.netty:netty-buffer:4.1.116.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
14-
io.netty:netty-codec-http2:4.1.116.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
15-
io.netty:netty-codec-http:4.1.116.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
16-
io.netty:netty-codec:4.1.116.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
17-
io.netty:netty-common:4.1.116.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
18-
io.netty:netty-handler:4.1.116.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
19-
io.netty:netty-resolver:4.1.116.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
20-
io.netty:netty-tcnative-boringssl-static:2.0.69.Final=testRuntimeClasspath
21-
io.netty:netty-tcnative-classes:2.0.69.Final=testRuntimeClasspath
22-
io.netty:netty-transport-native-unix-common:4.1.116.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
23-
io.netty:netty-transport:4.1.116.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
12+
com.jauntsdn.netty:netty-websocket-http1:1.4.0=testCompileClasspath,testRuntimeClasspath
13+
io.netty:netty-buffer:4.1.122.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
14+
io.netty:netty-codec-http2:4.1.122.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
15+
io.netty:netty-codec-http:4.1.122.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
16+
io.netty:netty-codec:4.1.122.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
17+
io.netty:netty-common:4.1.122.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
18+
io.netty:netty-handler:4.1.122.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
19+
io.netty:netty-resolver:4.1.122.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
20+
io.netty:netty-tcnative-boringssl-static:2.0.72.Final=testRuntimeClasspath
21+
io.netty:netty-tcnative-classes:2.0.72.Final=testRuntimeClasspath
22+
io.netty:netty-transport-native-unix-common:4.1.122.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
23+
io.netty:netty-transport:4.1.122.Final=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
2424
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testRuntimeClasspath
2525
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath
26-
org.assertj:assertj-core:3.27.0=testCompileClasspath,testRuntimeClasspath
26+
org.assertj:assertj-core:3.27.3=testCompileClasspath,testRuntimeClasspath
2727
org.codehaus.mojo:animal-sniffer-annotations:1.14=googleJavaFormat1.6
2828
org.junit.jupiter:junit-jupiter-api:5.11.4=testCompileClasspath,testRuntimeClasspath
2929
org.junit.jupiter:junit-jupiter-engine:5.11.4=testRuntimeClasspath

netty-websocket-http2/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/Http1WebSocketCodec.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@
2121
import io.netty.handler.codec.http.websocketx.WebSocketDecoderConfig;
2222
import io.netty.handler.codec.http.websocketx.WebSocketFrameDecoder;
2323
import io.netty.handler.codec.http.websocketx.WebSocketFrameEncoder;
24+
import java.util.function.IntSupplier;
2425

2526
public interface Http1WebSocketCodec {
2627

2728
WebSocketFrameEncoder encoder(boolean maskPayload);
2829

30+
default WebSocketFrameEncoder encoder(boolean maskPayload, IntSupplier externalMask) {
31+
return null;
32+
}
33+
2934
WebSocketFrameDecoder decoder(WebSocketDecoderConfig config);
3035

3136
default WebSocketFrameDecoder decoder(boolean maskPayload, WebSocketDecoderConfig config) {

netty-websocket-http2/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/Http2WebSocketChannel.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import java.util.concurrent.RejectedExecutionException;
6969
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
7070
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
71+
import java.util.function.IntSupplier;
7172
import javax.annotation.Nullable;
7273
import org.slf4j.Logger;
7374
import org.slf4j.LoggerFactory;
@@ -94,6 +95,7 @@ final class Http2WebSocketChannel extends DefaultAttributeMap
9495
private final ChannelPipeline pipeline;
9596
private final WebSocketsParent webSocketChannelParent;
9697
private final int websocketChannelSerial;
98+
private final String authority;
9799
private final String path;
98100
private final String subprotocol;
99101
private final ChannelPromise closePromise;
@@ -142,6 +144,7 @@ final class Http2WebSocketChannel extends DefaultAttributeMap
142144
Http2WebSocketChannel(
143145
WebSocketsParent webSocketChannelParent,
144146
int websocketChannelSerial,
147+
String authority,
145148
String path,
146149
String subprotocol,
147150
WebSocketDecoderConfig config,
@@ -153,6 +156,7 @@ final class Http2WebSocketChannel extends DefaultAttributeMap
153156
this.isHandshakeCompleted = true;
154157
this.webSocketChannelParent = webSocketChannelParent;
155158
this.websocketChannelSerial = websocketChannelSerial;
159+
this.authority = authority;
156160
this.path = path;
157161
this.subprotocol = subprotocol;
158162
this.decoderConfig = config;
@@ -185,12 +189,15 @@ final class Http2WebSocketChannel extends DefaultAttributeMap
185189
Http2WebSocketChannel(
186190
WebSocketsParent webSocketChannelParent,
187191
int websocketChannelSerial,
192+
String authority,
188193
String path,
189194
String subprotocol,
190195
Http1WebSocketCodec webSocketCodec,
196+
IntSupplier externalMask,
191197
ChannelHandler websocketHandler) {
192198
this.webSocketChannelParent = webSocketChannelParent;
193199
this.websocketChannelSerial = websocketChannelSerial;
200+
this.authority = authority;
194201
this.path = path;
195202
this.subprotocol = subprotocol;
196203
channelId = new Http2WebSocketChannelId(parent().id(), websocketChannelSerial);
@@ -200,7 +207,8 @@ final class Http2WebSocketChannel extends DefaultAttributeMap
200207

201208
closePromise = pl.newPromise();
202209
handshakePromise = pl.newPromise();
203-
handshakePromiseListener = new CompleteClientHandshake(preHandshakeHandler, webSocketCodec);
210+
handshakePromiseListener =
211+
new CompleteClientHandshake(preHandshakeHandler, webSocketCodec, externalMask);
204212
}
205213

206214
/*called on user thread, done outside constructor to not publish
@@ -217,11 +225,15 @@ Http2WebSocketChannel initialize() {
217225
class CompleteClientHandshake implements GenericFutureListener<ChannelFuture> {
218226
private final PreHandshakeHandler preHandshakeHandler;
219227
private final Http1WebSocketCodec webSocketCodec;
228+
private final IntSupplier externalMask;
220229

221230
public CompleteClientHandshake(
222-
PreHandshakeHandler preHandshakeHandler, Http1WebSocketCodec webSocketCodec) {
231+
PreHandshakeHandler preHandshakeHandler,
232+
Http1WebSocketCodec webSocketCodec,
233+
IntSupplier externalMask) {
223234
this.preHandshakeHandler = preHandshakeHandler;
224235
this.webSocketCodec = webSocketCodec;
236+
this.externalMask = externalMask;
225237
}
226238

227239
@Override
@@ -246,7 +258,10 @@ public void operationComplete(ChannelFuture future) {
246258
if (decoder == null) {
247259
decoder = codec.decoder(config);
248260
}
249-
WebSocketFrameEncoder encoder = codec.encoder(maskPayload);
261+
WebSocketFrameEncoder encoder = codec.encoder(maskPayload, externalMask);
262+
if (encoder == null) {
263+
encoder = codec.encoder(maskPayload);
264+
}
250265
if (comprEncoder != null && comprDecoder != null) {
251266
pl.addFirst(decoder, comprDecoder, encoder, comprEncoder);
252267
} else {
@@ -260,6 +275,10 @@ int serial() {
260275
return websocketChannelSerial;
261276
}
262277

278+
String authority() {
279+
return authority;
280+
}
281+
263282
String path() {
264283
return path;
265284
}
@@ -324,7 +343,8 @@ public int onDataRead(
324343
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) {
325344
pipeline()
326345
.fireUserEventTriggered(
327-
Http2WebSocketRemoteCloseEvent.reset(serial(), path, subprotocol, System.nanoTime()));
346+
Http2WebSocketRemoteCloseEvent.reset(
347+
serial(), authority, path, subprotocol, System.nanoTime()));
328348
streamClosed();
329349
}
330350

@@ -334,7 +354,7 @@ public void onGoAwayRead(
334354
pipeline()
335355
.fireUserEventTriggered(
336356
new Http2WebSocketEvent.Http2WebSocketRemoteGoAwayEvent(
337-
serial(), path, subprotocol, System.nanoTime(), errorCode));
357+
serial(), authority, path, subprotocol, System.nanoTime(), errorCode));
338358
streamClosed();
339359
}
340360

@@ -747,7 +767,7 @@ void fireChildRead(ByteBuf data, boolean endOfStream) {
747767
pipeline()
748768
.fireUserEventTriggered(
749769
Http2WebSocketRemoteCloseEvent.endStream(
750-
serial(), path, subprotocol, System.nanoTime()));
770+
serial(), authority, path, subprotocol, System.nanoTime()));
751771
}
752772
}
753773

netty-websocket-http2/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/Http2WebSocketClientBuilder.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import io.netty.handler.codec.http.websocketx.WebSocketDecoderConfig;
2020
import io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateClientExtensionHandshaker;
2121
import java.util.Objects;
22+
import java.util.function.IntSupplier;
23+
import javax.annotation.Nullable;
2224

2325
/** Builder for {@link Http2WebSocketClientHandler} */
2426
public final class Http2WebSocketClientBuilder {
@@ -33,6 +35,7 @@ public final class Http2WebSocketClientBuilder {
3335
private boolean isSingleWebSocketPerConnection;
3436
private boolean isMaskPayload = true;
3537
private boolean isNomaskingExtension;
38+
private IntSupplier externalMask;
3639

3740
Http2WebSocketClientBuilder() {}
3841

@@ -70,6 +73,16 @@ public Http2WebSocketClientBuilder maskPayload(boolean maskPayload) {
7073
return this;
7174
}
7275

76+
/**
77+
* @param externalMask generator for payload masking key, used if underlying http1 codec supports
78+
* It. May be null.
79+
* @return this {@link Http2WebSocketClientBuilder} instance
80+
*/
81+
public Http2WebSocketClientBuilder mask(@Nullable IntSupplier externalMask) {
82+
this.externalMask = externalMask;
83+
return this;
84+
}
85+
7386
/**
7487
* @param handshakeTimeoutMillis websocket handshake timeout. Must be positive
7588
* @return this {@link Http2WebSocketClientBuilder} instance
@@ -205,6 +218,7 @@ public Http2WebSocketClientHandler build() {
205218
config,
206219
maskPayload,
207220
isNomaskingExtension,
221+
externalMask,
208222
weight,
209223
handshakeTimeoutMillis,
210224
closedWebSocketRemoveTimeoutMillis,

netty-websocket-http2/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/Http2WebSocketClientHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.netty.handler.codec.http2.Http2Settings;
2828
import io.netty.handler.ssl.SslHandler;
2929
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
30+
import java.util.function.IntSupplier;
3031
import javax.annotation.Nullable;
3132

3233
/**
@@ -45,6 +46,7 @@ public final class Http2WebSocketClientHandler extends Http2WebSocketChannelHand
4546

4647
private final long handshakeTimeoutMillis;
4748
private final PerMessageDeflateClientExtensionHandshaker compressionHandshaker;
49+
private final IntSupplier externalMask;
4850
private final short streamWeight;
4951

5052
private CharSequence scheme;
@@ -58,6 +60,7 @@ public final class Http2WebSocketClientHandler extends Http2WebSocketChannelHand
5860
WebSocketDecoderConfig webSocketDecoderConfig,
5961
boolean isEncoderMaskPayload,
6062
boolean isNomaskingExtension,
63+
IntSupplier externalMask,
6164
short streamWeight,
6265
long handshakeTimeoutMillis,
6366
long closedWebSocketRemoveTimeoutMillis,
@@ -70,6 +73,7 @@ public final class Http2WebSocketClientHandler extends Http2WebSocketChannelHand
7073
isNomaskingExtension,
7174
closedWebSocketRemoveTimeoutMillis,
7275
isSingleWebSocketPerConnection);
76+
this.externalMask = externalMask;
7377
this.streamWeight = streamWeight;
7478
this.handshakeTimeoutMillis = handshakeTimeoutMillis;
7579
this.compressionHandshaker = compressionHandshaker;
@@ -105,6 +109,7 @@ public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings)
105109
settings.get(Http2WebSocketProtocol.SETTINGS_ENABLE_CONNECT_PROTOCOL);
106110
boolean supports =
107111
supportsWebSocket = extendedConnectEnabled != null && extendedConnectEnabled == 1;
112+
Http2WebSocketEvent.fireWebSocketSupported(webSocketsParent.context().channel(), supports);
108113
Http2WebSocketClientHandshaker listener = HANDSHAKER.get(this);
109114
if (listener != null) {
110115
supportsWebSocketCalled = true;
@@ -166,6 +171,7 @@ Http2WebSocketClientHandshaker handShaker() {
166171
config,
167172
isEncoderMaskPayload,
168173
nomaskingExtension,
174+
externalMask,
169175
streamWeight,
170176
scheme,
171177
handshakeTimeoutMillis,

0 commit comments

Comments
 (0)