123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 'use strict';
-
-
-
-
-
-
-
-
-
-
-
-
-
- const tokenChars = [
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0
- ];
-
-
- function isValidStatusCode(code) {
- return (
- (code >= 1000 &&
- code <= 1014 &&
- code !== 1004 &&
- code !== 1005 &&
- code !== 1006) ||
- (code >= 3000 && code <= 4999)
- );
- }
-
-
- function _isValidUTF8(buf) {
- const len = buf.length;
- let i = 0;
-
- while (i < len) {
- if ((buf[i] & 0x80) === 0) {
-
- i++;
- } else if ((buf[i] & 0xe0) === 0xc0) {
-
- if (
- i + 1 === len ||
- (buf[i + 1] & 0xc0) !== 0x80 ||
- (buf[i] & 0xfe) === 0xc0
- ) {
- return false;
- }
-
- i += 2;
- } else if ((buf[i] & 0xf0) === 0xe0) {
-
- if (
- i + 2 >= len ||
- (buf[i + 1] & 0xc0) !== 0x80 ||
- (buf[i + 2] & 0xc0) !== 0x80 ||
- (buf[i] === 0xe0 && (buf[i + 1] & 0xe0) === 0x80) ||
- (buf[i] === 0xed && (buf[i + 1] & 0xe0) === 0xa0)
- ) {
- return false;
- }
-
- i += 3;
- } else if ((buf[i] & 0xf8) === 0xf0) {
-
- if (
- i + 3 >= len ||
- (buf[i + 1] & 0xc0) !== 0x80 ||
- (buf[i + 2] & 0xc0) !== 0x80 ||
- (buf[i + 3] & 0xc0) !== 0x80 ||
- (buf[i] === 0xf0 && (buf[i + 1] & 0xf0) === 0x80) ||
- (buf[i] === 0xf4 && buf[i + 1] > 0x8f) ||
- buf[i] > 0xf4
- ) {
- return false;
- }
-
- i += 4;
- } else {
- return false;
- }
- }
-
- return true;
- }
-
- try {
- const isValidUTF8 = require('utf-8-validate');
-
- module.exports = {
- isValidStatusCode,
- isValidUTF8(buf) {
- return buf.length < 150 ? _isValidUTF8(buf) : isValidUTF8(buf);
- },
- tokenChars
- };
- } catch (e) {
- module.exports = {
- isValidStatusCode,
- isValidUTF8: _isValidUTF8,
- tokenChars
- };
- }
|