3
3
package websocket
4
4
5
5
import (
6
- "compress/flate"
6
+ "strconv"
7
+
8
+ "github.com/klauspost/compress/flate"
9
+
7
10
"io"
8
11
"sync"
9
12
)
@@ -53,12 +56,18 @@ func (m CompressionMode) opts() *compressionOptions {
53
56
return & compressionOptions {
54
57
clientNoContextTakeover : m == CompressionNoContextTakeover ,
55
58
serverNoContextTakeover : m == CompressionNoContextTakeover ,
59
+
60
+ serverMaxWindowBits : 0 ,
61
+ clientMaxWindowBits : 0 ,
56
62
}
57
63
}
58
64
59
65
type compressionOptions struct {
60
66
clientNoContextTakeover bool
61
67
serverNoContextTakeover bool
68
+
69
+ serverMaxWindowBits int
70
+ clientMaxWindowBits int
62
71
}
63
72
64
73
func (copts * compressionOptions ) String () string {
@@ -69,6 +78,11 @@ func (copts *compressionOptions) String() string {
69
78
if copts .serverNoContextTakeover {
70
79
s += "; server_no_context_takeover"
71
80
}
81
+
82
+ if copts .clientMaxWindowBits != 0 {
83
+ s += "; client_max_window_bits=" + strconv .Itoa (copts .clientMaxWindowBits )
84
+ }
85
+
72
86
return s
73
87
}
74
88
@@ -147,20 +161,24 @@ func putFlateReader(fr io.Reader) {
147
161
flateReaderPool .Put (fr )
148
162
}
149
163
150
- var flateWriterPool sync.Pool
164
+ var flateWriterPool [ 16 ] sync.Pool
151
165
152
- func getFlateWriter (w io.Writer ) * flate.Writer {
153
- fw , ok := flateWriterPool .Get ().(* flate.Writer )
166
+ func getFlateWriter (w io.Writer , bits int ) * flate.Writer {
167
+ fw , ok := flateWriterPool [ bits ] .Get ().(* flate.Writer )
154
168
if ! ok {
155
- fw , _ = flate .NewWriter (w , flate .BestSpeed )
169
+ if bits == 0 {
170
+ fw , _ = flate .NewWriter (w , flate .BestCompression )
171
+ } else {
172
+ fw , _ = flate .NewWriterWindow (w , 1 << bits )
173
+ }
156
174
return fw
157
175
}
158
176
fw .Reset (w )
159
177
return fw
160
178
}
161
179
162
- func putFlateWriter (w * flate.Writer ) {
163
- flateWriterPool .Put (w )
180
+ func putFlateWriter (w * flate.Writer , bits int ) {
181
+ flateWriterPool [ bits ] .Put (w )
164
182
}
165
183
166
184
type slidingWindow struct {
0 commit comments