@@ -29,12 +29,14 @@ class PerMessageDeflate {
29
29
}
30
30
31
31
/**
32
- * Create extension parameters offer
32
+ * Create extension parameters offer.
33
33
*
34
+ * @return {Object } Extension parameters
34
35
* @public
35
36
*/
36
37
offer ( ) {
37
- var params = { } ;
38
+ const params = { } ;
39
+
38
40
if ( this . _options . serverNoContextTakeover ) {
39
41
params . server_no_context_takeover = true ;
40
42
}
@@ -49,12 +51,15 @@ class PerMessageDeflate {
49
51
} else if ( this . _options . clientMaxWindowBits == null ) {
50
52
params . client_max_window_bits = true ;
51
53
}
54
+
52
55
return params ;
53
56
}
54
57
55
58
/**
56
- * Accept extension offer
59
+ * Accept extension offer.
57
60
*
61
+ * @param {Array } paramsList Extension parameters
62
+ * @return {Object } Accepted configuration
58
63
* @public
59
64
*/
60
65
accept ( paramsList ) {
@@ -72,7 +77,7 @@ class PerMessageDeflate {
72
77
}
73
78
74
79
/**
75
- * Releases all resources used by the extension
80
+ * Releases all resources used by the extension.
76
81
*
77
82
* @public
78
83
*/
@@ -96,36 +101,45 @@ class PerMessageDeflate {
96
101
}
97
102
98
103
/**
99
- * Accept extension offer from client
104
+ * Accept extension offer from client.
100
105
*
106
+ * @param {Array } paramsList Extension parameters
107
+ * @return {Object } Accepted configuration
101
108
* @private
102
109
*/
103
110
acceptAsServer ( paramsList ) {
104
- var accepted = { } ;
105
- var result = paramsList . some ( ( params ) => {
106
- accepted = { } ;
107
- if ( this . _options . serverNoContextTakeover === false && params . server_no_context_takeover ) {
108
- return ;
109
- }
110
- if ( this . _options . serverMaxWindowBits === false && params . server_max_window_bits ) {
111
- return ;
112
- }
113
- if ( typeof this . _options . serverMaxWindowBits === 'number' &&
114
- typeof params . server_max_window_bits === 'number' &&
115
- this . _options . serverMaxWindowBits > params . server_max_window_bits ) {
116
- return ;
117
- }
118
- if ( typeof this . _options . clientMaxWindowBits === 'number' && ! params . client_max_window_bits ) {
111
+ const accepted = { } ;
112
+ const result = paramsList . some ( ( params ) => {
113
+ if ( (
114
+ this . _options . serverNoContextTakeover === false &&
115
+ params . server_no_context_takeover
116
+ ) || (
117
+ this . _options . serverMaxWindowBits === false &&
118
+ params . server_max_window_bits
119
+ ) || (
120
+ typeof this . _options . serverMaxWindowBits === 'number' &&
121
+ typeof params . server_max_window_bits === 'number' &&
122
+ this . _options . serverMaxWindowBits > params . server_max_window_bits
123
+ ) || (
124
+ typeof this . _options . clientMaxWindowBits === 'number' &&
125
+ ! params . client_max_window_bits
126
+ ) ) {
119
127
return ;
120
128
}
121
129
122
- if ( this . _options . serverNoContextTakeover || params . server_no_context_takeover ) {
130
+ if (
131
+ this . _options . serverNoContextTakeover ||
132
+ params . server_no_context_takeover
133
+ ) {
123
134
accepted . server_no_context_takeover = true ;
124
135
}
125
136
if ( this . _options . clientNoContextTakeover ) {
126
137
accepted . client_no_context_takeover = true ;
127
138
}
128
- if ( this . _options . clientNoContextTakeover !== false && params . client_no_context_takeover ) {
139
+ if (
140
+ this . _options . clientNoContextTakeover !== false &&
141
+ params . client_no_context_takeover
142
+ ) {
129
143
accepted . client_no_context_takeover = true ;
130
144
}
131
145
if ( typeof this . _options . serverMaxWindowBits === 'number' ) {
@@ -135,54 +149,70 @@ class PerMessageDeflate {
135
149
}
136
150
if ( typeof this . _options . clientMaxWindowBits === 'number' ) {
137
151
accepted . client_max_window_bits = this . _options . clientMaxWindowBits ;
138
- } else if ( this . _options . clientMaxWindowBits !== false && typeof params . client_max_window_bits === 'number' ) {
152
+ } else if (
153
+ this . _options . clientMaxWindowBits !== false &&
154
+ typeof params . client_max_window_bits === 'number'
155
+ ) {
139
156
accepted . client_max_window_bits = params . client_max_window_bits ;
140
157
}
141
158
return true ;
142
159
} ) ;
143
160
144
- if ( ! result ) {
145
- throw new Error ( `Doesn't support the offered configuration` ) ;
146
- }
161
+ if ( ! result ) throw new Error ( `Doesn't support the offered configuration` ) ;
147
162
148
163
return accepted ;
149
164
}
150
165
151
166
/**
152
- * Accept extension response from server
167
+ * Accept extension response from server.
153
168
*
169
+ * @param {Array } paramsList Extension parameters
170
+ * @return {Object } Accepted configuration
154
171
* @private
155
172
*/
156
173
acceptAsClient ( paramsList ) {
157
- var params = paramsList [ 0 ] ;
174
+ const params = paramsList [ 0 ] ;
175
+
158
176
if ( this . _options . clientNoContextTakeover != null ) {
159
- if ( this . _options . clientNoContextTakeover === false && params . client_no_context_takeover ) {
177
+ if (
178
+ this . _options . clientNoContextTakeover === false &&
179
+ params . client_no_context_takeover
180
+ ) {
160
181
throw new Error ( 'Invalid value for "client_no_context_takeover"' ) ;
161
182
}
162
183
}
163
184
if ( this . _options . clientMaxWindowBits != null ) {
164
- if ( this . _options . clientMaxWindowBits === false && params . client_max_window_bits ) {
185
+ if (
186
+ this . _options . clientMaxWindowBits === false &&
187
+ params . client_max_window_bits
188
+ ) {
165
189
throw new Error ( 'Invalid value for "client_max_window_bits"' ) ;
166
190
}
167
- if ( typeof this . _options . clientMaxWindowBits === 'number' &&
168
- ( ! params . client_max_window_bits || params . client_max_window_bits > this . _options . clientMaxWindowBits ) ) {
191
+ if (
192
+ typeof this . _options . clientMaxWindowBits === 'number' && (
193
+ ! params . client_max_window_bits ||
194
+ params . client_max_window_bits > this . _options . clientMaxWindowBits
195
+ ) ) {
169
196
throw new Error ( 'Invalid value for "client_max_window_bits"' ) ;
170
197
}
171
198
}
199
+
172
200
return params ;
173
201
}
174
202
175
203
/**
176
- * Normalize extensions parameters
204
+ * Normalize extensions parameters.
177
205
*
206
+ * @param {Array } paramsList Extension parameters
207
+ * @return {Array } Normalized extensions parameters
178
208
* @private
179
209
*/
180
210
normalizeParams ( paramsList ) {
181
211
return paramsList . map ( ( params ) => {
182
212
Object . keys ( params ) . forEach ( ( key ) => {
183
213
var value = params [ key ] ;
184
214
if ( value . length > 1 ) {
185
- throw new Error ( ' Multiple extension parameters for ' + key ) ;
215
+ throw new Error ( ` Multiple extension parameters for ${ key } ` ) ;
186
216
}
187
217
188
218
value = value [ 0 ] ;
@@ -283,8 +313,11 @@ class PerMessageDeflate {
283
313
}
284
314
285
315
/**
286
- * Compress message
316
+ * Compress data.
287
317
*
318
+ * @param {Buffer } data Data to compress
319
+ * @param {Boolean } fin Specifies whether or not this is the last fragment
320
+ * @param {Function } callback Callback
288
321
* @public
289
322
*/
290
323
compress ( data , fin , callback ) {
0 commit comments