1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.http.websocketx;
17
18 import io.netty.util.internal.ObjectUtil;
19
20
21
22
23 public final class WebSocketDecoderConfig {
24
25 static final WebSocketDecoderConfig DEFAULT =
26 new WebSocketDecoderConfig(65536, true, false, false, true, true);
27
28 private final int maxFramePayloadLength;
29 private final boolean expectMaskedFrames;
30 private final boolean allowMaskMismatch;
31 private final boolean allowExtensions;
32 private final boolean closeOnProtocolViolation;
33 private final boolean withUTF8Validator;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 private WebSocketDecoderConfig(int maxFramePayloadLength, boolean expectMaskedFrames, boolean allowMaskMismatch,
57 boolean allowExtensions, boolean closeOnProtocolViolation,
58 boolean withUTF8Validator) {
59 this.maxFramePayloadLength = maxFramePayloadLength;
60 this.expectMaskedFrames = expectMaskedFrames;
61 this.allowMaskMismatch = allowMaskMismatch;
62 this.allowExtensions = allowExtensions;
63 this.closeOnProtocolViolation = closeOnProtocolViolation;
64 this.withUTF8Validator = withUTF8Validator;
65 }
66
67 public int maxFramePayloadLength() {
68 return maxFramePayloadLength;
69 }
70
71 public boolean expectMaskedFrames() {
72 return expectMaskedFrames;
73 }
74
75 public boolean allowMaskMismatch() {
76 return allowMaskMismatch;
77 }
78
79 public boolean allowExtensions() {
80 return allowExtensions;
81 }
82
83 public boolean closeOnProtocolViolation() {
84 return closeOnProtocolViolation;
85 }
86
87 public boolean withUTF8Validator() {
88 return withUTF8Validator;
89 }
90
91 @Override
92 public String toString() {
93 return "WebSocketDecoderConfig" +
94 " [maxFramePayloadLength=" + maxFramePayloadLength +
95 ", expectMaskedFrames=" + expectMaskedFrames +
96 ", allowMaskMismatch=" + allowMaskMismatch +
97 ", allowExtensions=" + allowExtensions +
98 ", closeOnProtocolViolation=" + closeOnProtocolViolation +
99 ", withUTF8Validator=" + withUTF8Validator +
100 "]";
101 }
102
103 public Builder toBuilder() {
104 return new Builder(this);
105 }
106
107 public static Builder newBuilder() {
108 return new Builder(DEFAULT);
109 }
110
111 public static final class Builder {
112 private int maxFramePayloadLength;
113 private boolean expectMaskedFrames;
114 private boolean allowMaskMismatch;
115 private boolean allowExtensions;
116 private boolean closeOnProtocolViolation;
117 private boolean withUTF8Validator;
118
119 private Builder(WebSocketDecoderConfig decoderConfig) {
120 ObjectUtil.checkNotNull(decoderConfig, "decoderConfig");
121 maxFramePayloadLength = decoderConfig.maxFramePayloadLength();
122 expectMaskedFrames = decoderConfig.expectMaskedFrames();
123 allowMaskMismatch = decoderConfig.allowMaskMismatch();
124 allowExtensions = decoderConfig.allowExtensions();
125 closeOnProtocolViolation = decoderConfig.closeOnProtocolViolation();
126 withUTF8Validator = decoderConfig.withUTF8Validator();
127 }
128
129 public Builder maxFramePayloadLength(int maxFramePayloadLength) {
130 this.maxFramePayloadLength = maxFramePayloadLength;
131 return this;
132 }
133
134 public Builder expectMaskedFrames(boolean expectMaskedFrames) {
135 this.expectMaskedFrames = expectMaskedFrames;
136 return this;
137 }
138
139 public Builder allowMaskMismatch(boolean allowMaskMismatch) {
140 this.allowMaskMismatch = allowMaskMismatch;
141 return this;
142 }
143
144 public Builder allowExtensions(boolean allowExtensions) {
145 this.allowExtensions = allowExtensions;
146 return this;
147 }
148
149 public Builder closeOnProtocolViolation(boolean closeOnProtocolViolation) {
150 this.closeOnProtocolViolation = closeOnProtocolViolation;
151 return this;
152 }
153
154 public Builder withUTF8Validator(boolean withUTF8Validator) {
155 this.withUTF8Validator = withUTF8Validator;
156 return this;
157 }
158
159 public WebSocketDecoderConfig build() {
160 return new WebSocketDecoderConfig(
161 maxFramePayloadLength, expectMaskedFrames, allowMaskMismatch,
162 allowExtensions, closeOnProtocolViolation, withUTF8Validator);
163 }
164 }
165 }