| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bb780d2 commit 24dc57b
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -233,70 +233,14 @@ function httpSocketSetup(socket) { | |||
| 233 | 233 | socket.on('drain', ondrain); | |
| 234 | 234 | } | |
| 235 | 235 | ||
| 236 | + const tokenRegExp = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/; | ||
| 236 | 237 | /** | |
| 237 | 238 | * Verifies that the given val is a valid HTTP token | |
| 238 | 239 | * per the rules defined in RFC 7230 | |
| 239 | 240 | * See https://tools.ietf.org/html/rfc7230#section-3.2.6 | |
| 240 | - * | ||
| 241 | - * Allowed characters in an HTTP token: | ||
| 242 | - * ^_`a-z 94-122 | ||
| 243 | - * A-Z 65-90 | ||
| 244 | - * - 45 | ||
| 245 | - * 0-9 48-57 | ||
| 246 | - * ! 33 | ||
| 247 | - * #$%&' 35-39 | ||
| 248 | - * *+ 42-43 | ||
| 249 | - * . 46 | ||
| 250 | - * | 124 | ||
| 251 | - * ~ 126 | ||
| 252 | - * | ||
| 253 | - * This implementation of checkIsHttpToken() loops over the string instead of | ||
| 254 | - * using a regular expression since the former is up to 180% faster with v8 4.9 | ||
| 255 | - * depending on the string length (the shorter the string, the larger the | ||
| 256 | - * performance difference) | ||
| 257 | - * | ||
| 258 | - * Additionally, checkIsHttpToken() is currently designed to be inlinable by v8, | ||
| 259 | - * so take care when making changes to the implementation so that the source | ||
| 260 | - * code size does not exceed v8's default max_inlined_source_size setting. | ||
| 261 | - **/ | ||
| 262 | - var validTokens = [ | ||
| 263 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15 | ||
| 264 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31 | ||
| 265 | - 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, // 32 - 47 | ||
| 266 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 48 - 63 | ||
| 267 | - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 79 | ||
| 268 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, // 80 - 95 | ||
| 269 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111 | ||
| 270 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, // 112 - 127 | ||
| 271 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 128 ... | ||
| 272 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 273 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 274 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 275 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 276 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 277 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 278 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // ... 255 | ||
| 279 | - ]; | ||
| 241 | + **/ | ||
| 280 | 242 | function checkIsHttpToken(val) { | |
| 281 | - if (!validTokens[val.charCodeAt(0)]) | ||
| 282 | - return false; | ||
| 283 | - if (val.length < 2) | ||
| 284 | - return true; | ||
| 285 | - if (!validTokens[val.charCodeAt(1)]) | ||
| 286 | - return false; | ||
| 287 | - if (val.length < 3) | ||
| 288 | - return true; | ||
| 289 | - if (!validTokens[val.charCodeAt(2)]) | ||
| 290 | - return false; | ||
| 291 | - if (val.length < 4) | ||
| 292 | - return true; | ||
| 293 | - if (!validTokens[val.charCodeAt(3)]) | ||
| 294 | - return false; | ||
| 295 | - for (var i = 4; i < val.length; ++i) { | ||
| 296 | - if (!validTokens[val.charCodeAt(i)]) | ||
| 297 | - return false; | ||
| 298 | - } | ||
| 299 | - return true; | ||
| 243 | + return tokenRegExp.test(val); | ||
| 300 | 244 | } | |
| 301 | 245 | ||
| 302 | 246 | /** | |
| Back | FazBrowse Home | New Git URL |
0 commit comments