1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.codec.http.websocketx.extensions.compression;
17
18 import io.netty5.handler.codec.http.websocketx.BinaryWebSocketFrame;
19 import io.netty5.handler.codec.http.websocketx.ContinuationWebSocketFrame;
20 import io.netty5.handler.codec.http.websocketx.TextWebSocketFrame;
21 import io.netty5.handler.codec.http.websocketx.WebSocketFrame;
22 import io.netty5.handler.codec.http.websocketx.extensions.WebSocketExtension;
23 import io.netty5.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter;
24
25
26
27
28 class PerFrameDeflateEncoder extends DeflateEncoder {
29
30
31
32
33
34
35
36
37 PerFrameDeflateEncoder(int compressionLevel, int windowSize, boolean noContext) {
38 super(compressionLevel, windowSize, noContext, WebSocketExtensionFilter.NEVER_SKIP);
39 }
40
41
42
43
44
45
46
47
48
49 PerFrameDeflateEncoder(int compressionLevel, int windowSize, boolean noContext,
50 WebSocketExtensionFilter extensionEncoderFilter) {
51 super(compressionLevel, windowSize, noContext, extensionEncoderFilter);
52 }
53
54 @Override
55 public boolean acceptOutboundMessage(Object msg) throws Exception {
56 if (!super.acceptOutboundMessage(msg)) {
57 return false;
58 }
59
60 WebSocketFrame wsFrame = (WebSocketFrame) msg;
61 if (extensionEncoderFilter().mustSkip(wsFrame)) {
62 return false;
63 }
64
65 return (msg instanceof TextWebSocketFrame || msg instanceof BinaryWebSocketFrame ||
66 msg instanceof ContinuationWebSocketFrame) &&
67 wsFrame.binaryData().readableBytes() > 0 &&
68 (wsFrame.rsv() & WebSocketExtension.RSV1) == 0;
69 }
70
71 @Override
72 protected int rsv(WebSocketFrame msg) {
73 return msg.rsv() | WebSocketExtension.RSV1;
74 }
75
76 @Override
77 protected boolean removeFrameTail(WebSocketFrame msg) {
78 return true;
79 }
80
81 }