constants.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SPECIAL_HEADERS = exports.HEADER_STATE = exports.MINOR = exports.MAJOR = exports.CONNECTION_TOKEN_CHARS = exports.HEADER_CHARS = exports.TOKEN = exports.STRICT_TOKEN = exports.HEX = exports.URL_CHAR = exports.STRICT_URL_CHAR = exports.USERINFO_CHARS = exports.MARK = exports.ALPHANUM = exports.NUM = exports.HEX_MAP = exports.NUM_MAP = exports.ALPHA = exports.FINISH = exports.H_METHOD_MAP = exports.METHOD_MAP = exports.METHODS_RTSP = exports.METHODS_ICE = exports.METHODS_HTTP = exports.METHODS = exports.LENIENT_FLAGS = exports.FLAGS = exports.TYPE = exports.ERROR = void 0;
  4. const utils_1 = require("./utils");
  5. // C headers
  6. var ERROR;
  7. (function (ERROR) {
  8. ERROR[ERROR["OK"] = 0] = "OK";
  9. ERROR[ERROR["INTERNAL"] = 1] = "INTERNAL";
  10. ERROR[ERROR["STRICT"] = 2] = "STRICT";
  11. ERROR[ERROR["LF_EXPECTED"] = 3] = "LF_EXPECTED";
  12. ERROR[ERROR["UNEXPECTED_CONTENT_LENGTH"] = 4] = "UNEXPECTED_CONTENT_LENGTH";
  13. ERROR[ERROR["CLOSED_CONNECTION"] = 5] = "CLOSED_CONNECTION";
  14. ERROR[ERROR["INVALID_METHOD"] = 6] = "INVALID_METHOD";
  15. ERROR[ERROR["INVALID_URL"] = 7] = "INVALID_URL";
  16. ERROR[ERROR["INVALID_CONSTANT"] = 8] = "INVALID_CONSTANT";
  17. ERROR[ERROR["INVALID_VERSION"] = 9] = "INVALID_VERSION";
  18. ERROR[ERROR["INVALID_HEADER_TOKEN"] = 10] = "INVALID_HEADER_TOKEN";
  19. ERROR[ERROR["INVALID_CONTENT_LENGTH"] = 11] = "INVALID_CONTENT_LENGTH";
  20. ERROR[ERROR["INVALID_CHUNK_SIZE"] = 12] = "INVALID_CHUNK_SIZE";
  21. ERROR[ERROR["INVALID_STATUS"] = 13] = "INVALID_STATUS";
  22. ERROR[ERROR["INVALID_EOF_STATE"] = 14] = "INVALID_EOF_STATE";
  23. ERROR[ERROR["INVALID_TRANSFER_ENCODING"] = 15] = "INVALID_TRANSFER_ENCODING";
  24. ERROR[ERROR["CB_MESSAGE_BEGIN"] = 16] = "CB_MESSAGE_BEGIN";
  25. ERROR[ERROR["CB_HEADERS_COMPLETE"] = 17] = "CB_HEADERS_COMPLETE";
  26. ERROR[ERROR["CB_MESSAGE_COMPLETE"] = 18] = "CB_MESSAGE_COMPLETE";
  27. ERROR[ERROR["CB_CHUNK_HEADER"] = 19] = "CB_CHUNK_HEADER";
  28. ERROR[ERROR["CB_CHUNK_COMPLETE"] = 20] = "CB_CHUNK_COMPLETE";
  29. ERROR[ERROR["PAUSED"] = 21] = "PAUSED";
  30. ERROR[ERROR["PAUSED_UPGRADE"] = 22] = "PAUSED_UPGRADE";
  31. ERROR[ERROR["PAUSED_H2_UPGRADE"] = 23] = "PAUSED_H2_UPGRADE";
  32. ERROR[ERROR["USER"] = 24] = "USER";
  33. })(ERROR = exports.ERROR || (exports.ERROR = {}));
  34. var TYPE;
  35. (function (TYPE) {
  36. TYPE[TYPE["BOTH"] = 0] = "BOTH";
  37. TYPE[TYPE["REQUEST"] = 1] = "REQUEST";
  38. TYPE[TYPE["RESPONSE"] = 2] = "RESPONSE";
  39. })(TYPE = exports.TYPE || (exports.TYPE = {}));
  40. var FLAGS;
  41. (function (FLAGS) {
  42. FLAGS[FLAGS["CONNECTION_KEEP_ALIVE"] = 1] = "CONNECTION_KEEP_ALIVE";
  43. FLAGS[FLAGS["CONNECTION_CLOSE"] = 2] = "CONNECTION_CLOSE";
  44. FLAGS[FLAGS["CONNECTION_UPGRADE"] = 4] = "CONNECTION_UPGRADE";
  45. FLAGS[FLAGS["CHUNKED"] = 8] = "CHUNKED";
  46. FLAGS[FLAGS["UPGRADE"] = 16] = "UPGRADE";
  47. FLAGS[FLAGS["CONTENT_LENGTH"] = 32] = "CONTENT_LENGTH";
  48. FLAGS[FLAGS["SKIPBODY"] = 64] = "SKIPBODY";
  49. FLAGS[FLAGS["TRAILING"] = 128] = "TRAILING";
  50. // 1 << 8 is unused
  51. FLAGS[FLAGS["TRANSFER_ENCODING"] = 512] = "TRANSFER_ENCODING";
  52. })(FLAGS = exports.FLAGS || (exports.FLAGS = {}));
  53. var LENIENT_FLAGS;
  54. (function (LENIENT_FLAGS) {
  55. LENIENT_FLAGS[LENIENT_FLAGS["HEADERS"] = 1] = "HEADERS";
  56. LENIENT_FLAGS[LENIENT_FLAGS["CHUNKED_LENGTH"] = 2] = "CHUNKED_LENGTH";
  57. LENIENT_FLAGS[LENIENT_FLAGS["KEEP_ALIVE"] = 4] = "KEEP_ALIVE";
  58. })(LENIENT_FLAGS = exports.LENIENT_FLAGS || (exports.LENIENT_FLAGS = {}));
  59. var METHODS;
  60. (function (METHODS) {
  61. METHODS[METHODS["DELETE"] = 0] = "DELETE";
  62. METHODS[METHODS["GET"] = 1] = "GET";
  63. METHODS[METHODS["HEAD"] = 2] = "HEAD";
  64. METHODS[METHODS["POST"] = 3] = "POST";
  65. METHODS[METHODS["PUT"] = 4] = "PUT";
  66. /* pathological */
  67. METHODS[METHODS["CONNECT"] = 5] = "CONNECT";
  68. METHODS[METHODS["OPTIONS"] = 6] = "OPTIONS";
  69. METHODS[METHODS["TRACE"] = 7] = "TRACE";
  70. /* WebDAV */
  71. METHODS[METHODS["COPY"] = 8] = "COPY";
  72. METHODS[METHODS["LOCK"] = 9] = "LOCK";
  73. METHODS[METHODS["MKCOL"] = 10] = "MKCOL";
  74. METHODS[METHODS["MOVE"] = 11] = "MOVE";
  75. METHODS[METHODS["PROPFIND"] = 12] = "PROPFIND";
  76. METHODS[METHODS["PROPPATCH"] = 13] = "PROPPATCH";
  77. METHODS[METHODS["SEARCH"] = 14] = "SEARCH";
  78. METHODS[METHODS["UNLOCK"] = 15] = "UNLOCK";
  79. METHODS[METHODS["BIND"] = 16] = "BIND";
  80. METHODS[METHODS["REBIND"] = 17] = "REBIND";
  81. METHODS[METHODS["UNBIND"] = 18] = "UNBIND";
  82. METHODS[METHODS["ACL"] = 19] = "ACL";
  83. /* subversion */
  84. METHODS[METHODS["REPORT"] = 20] = "REPORT";
  85. METHODS[METHODS["MKACTIVITY"] = 21] = "MKACTIVITY";
  86. METHODS[METHODS["CHECKOUT"] = 22] = "CHECKOUT";
  87. METHODS[METHODS["MERGE"] = 23] = "MERGE";
  88. /* upnp */
  89. METHODS[METHODS["M-SEARCH"] = 24] = "M-SEARCH";
  90. METHODS[METHODS["NOTIFY"] = 25] = "NOTIFY";
  91. METHODS[METHODS["SUBSCRIBE"] = 26] = "SUBSCRIBE";
  92. METHODS[METHODS["UNSUBSCRIBE"] = 27] = "UNSUBSCRIBE";
  93. /* RFC-5789 */
  94. METHODS[METHODS["PATCH"] = 28] = "PATCH";
  95. METHODS[METHODS["PURGE"] = 29] = "PURGE";
  96. /* CalDAV */
  97. METHODS[METHODS["MKCALENDAR"] = 30] = "MKCALENDAR";
  98. /* RFC-2068, section 19.6.1.2 */
  99. METHODS[METHODS["LINK"] = 31] = "LINK";
  100. METHODS[METHODS["UNLINK"] = 32] = "UNLINK";
  101. /* icecast */
  102. METHODS[METHODS["SOURCE"] = 33] = "SOURCE";
  103. /* RFC-7540, section 11.6 */
  104. METHODS[METHODS["PRI"] = 34] = "PRI";
  105. /* RFC-2326 RTSP */
  106. METHODS[METHODS["DESCRIBE"] = 35] = "DESCRIBE";
  107. METHODS[METHODS["ANNOUNCE"] = 36] = "ANNOUNCE";
  108. METHODS[METHODS["SETUP"] = 37] = "SETUP";
  109. METHODS[METHODS["PLAY"] = 38] = "PLAY";
  110. METHODS[METHODS["PAUSE"] = 39] = "PAUSE";
  111. METHODS[METHODS["TEARDOWN"] = 40] = "TEARDOWN";
  112. METHODS[METHODS["GET_PARAMETER"] = 41] = "GET_PARAMETER";
  113. METHODS[METHODS["SET_PARAMETER"] = 42] = "SET_PARAMETER";
  114. METHODS[METHODS["REDIRECT"] = 43] = "REDIRECT";
  115. METHODS[METHODS["RECORD"] = 44] = "RECORD";
  116. /* RAOP */
  117. METHODS[METHODS["FLUSH"] = 45] = "FLUSH";
  118. })(METHODS = exports.METHODS || (exports.METHODS = {}));
  119. exports.METHODS_HTTP = [
  120. METHODS.DELETE,
  121. METHODS.GET,
  122. METHODS.HEAD,
  123. METHODS.POST,
  124. METHODS.PUT,
  125. METHODS.CONNECT,
  126. METHODS.OPTIONS,
  127. METHODS.TRACE,
  128. METHODS.COPY,
  129. METHODS.LOCK,
  130. METHODS.MKCOL,
  131. METHODS.MOVE,
  132. METHODS.PROPFIND,
  133. METHODS.PROPPATCH,
  134. METHODS.SEARCH,
  135. METHODS.UNLOCK,
  136. METHODS.BIND,
  137. METHODS.REBIND,
  138. METHODS.UNBIND,
  139. METHODS.ACL,
  140. METHODS.REPORT,
  141. METHODS.MKACTIVITY,
  142. METHODS.CHECKOUT,
  143. METHODS.MERGE,
  144. METHODS['M-SEARCH'],
  145. METHODS.NOTIFY,
  146. METHODS.SUBSCRIBE,
  147. METHODS.UNSUBSCRIBE,
  148. METHODS.PATCH,
  149. METHODS.PURGE,
  150. METHODS.MKCALENDAR,
  151. METHODS.LINK,
  152. METHODS.UNLINK,
  153. METHODS.PRI,
  154. // TODO(indutny): should we allow it with HTTP?
  155. METHODS.SOURCE,
  156. ];
  157. exports.METHODS_ICE = [
  158. METHODS.SOURCE,
  159. ];
  160. exports.METHODS_RTSP = [
  161. METHODS.OPTIONS,
  162. METHODS.DESCRIBE,
  163. METHODS.ANNOUNCE,
  164. METHODS.SETUP,
  165. METHODS.PLAY,
  166. METHODS.PAUSE,
  167. METHODS.TEARDOWN,
  168. METHODS.GET_PARAMETER,
  169. METHODS.SET_PARAMETER,
  170. METHODS.REDIRECT,
  171. METHODS.RECORD,
  172. METHODS.FLUSH,
  173. // For AirPlay
  174. METHODS.GET,
  175. METHODS.POST,
  176. ];
  177. exports.METHOD_MAP = utils_1.enumToMap(METHODS);
  178. exports.H_METHOD_MAP = {};
  179. Object.keys(exports.METHOD_MAP).forEach((key) => {
  180. if (/^H/.test(key)) {
  181. exports.H_METHOD_MAP[key] = exports.METHOD_MAP[key];
  182. }
  183. });
  184. var FINISH;
  185. (function (FINISH) {
  186. FINISH[FINISH["SAFE"] = 0] = "SAFE";
  187. FINISH[FINISH["SAFE_WITH_CB"] = 1] = "SAFE_WITH_CB";
  188. FINISH[FINISH["UNSAFE"] = 2] = "UNSAFE";
  189. })(FINISH = exports.FINISH || (exports.FINISH = {}));
  190. exports.ALPHA = [];
  191. for (let i = 'A'.charCodeAt(0); i <= 'Z'.charCodeAt(0); i++) {
  192. // Upper case
  193. exports.ALPHA.push(String.fromCharCode(i));
  194. // Lower case
  195. exports.ALPHA.push(String.fromCharCode(i + 0x20));
  196. }
  197. exports.NUM_MAP = {
  198. 0: 0, 1: 1, 2: 2, 3: 3, 4: 4,
  199. 5: 5, 6: 6, 7: 7, 8: 8, 9: 9,
  200. };
  201. exports.HEX_MAP = {
  202. 0: 0, 1: 1, 2: 2, 3: 3, 4: 4,
  203. 5: 5, 6: 6, 7: 7, 8: 8, 9: 9,
  204. A: 0XA, B: 0XB, C: 0XC, D: 0XD, E: 0XE, F: 0XF,
  205. a: 0xa, b: 0xb, c: 0xc, d: 0xd, e: 0xe, f: 0xf,
  206. };
  207. exports.NUM = [
  208. '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  209. ];
  210. exports.ALPHANUM = exports.ALPHA.concat(exports.NUM);
  211. exports.MARK = ['-', '_', '.', '!', '~', '*', '\'', '(', ')'];
  212. exports.USERINFO_CHARS = exports.ALPHANUM
  213. .concat(exports.MARK)
  214. .concat(['%', ';', ':', '&', '=', '+', '$', ',']);
  215. // TODO(indutny): use RFC
  216. exports.STRICT_URL_CHAR = [
  217. '!', '"', '$', '%', '&', '\'',
  218. '(', ')', '*', '+', ',', '-', '.', '/',
  219. ':', ';', '<', '=', '>',
  220. '@', '[', '\\', ']', '^', '_',
  221. '`',
  222. '{', '|', '}', '~',
  223. ].concat(exports.ALPHANUM);
  224. exports.URL_CHAR = exports.STRICT_URL_CHAR
  225. .concat(['\t', '\f']);
  226. // All characters with 0x80 bit set to 1
  227. for (let i = 0x80; i <= 0xff; i++) {
  228. exports.URL_CHAR.push(i);
  229. }
  230. exports.HEX = exports.NUM.concat(['a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F']);
  231. /* Tokens as defined by rfc 2616. Also lowercases them.
  232. * token = 1*<any CHAR except CTLs or separators>
  233. * separators = "(" | ")" | "<" | ">" | "@"
  234. * | "," | ";" | ":" | "\" | <">
  235. * | "/" | "[" | "]" | "?" | "="
  236. * | "{" | "}" | SP | HT
  237. */
  238. exports.STRICT_TOKEN = [
  239. '!', '#', '$', '%', '&', '\'',
  240. '*', '+', '-', '.',
  241. '^', '_', '`',
  242. '|', '~',
  243. ].concat(exports.ALPHANUM);
  244. exports.TOKEN = exports.STRICT_TOKEN.concat([' ']);
  245. /*
  246. * Verify that a char is a valid visible (printable) US-ASCII
  247. * character or %x80-FF
  248. */
  249. exports.HEADER_CHARS = ['\t'];
  250. for (let i = 32; i <= 255; i++) {
  251. if (i !== 127) {
  252. exports.HEADER_CHARS.push(i);
  253. }
  254. }
  255. // ',' = \x44
  256. exports.CONNECTION_TOKEN_CHARS = exports.HEADER_CHARS.filter((c) => c !== 44);
  257. exports.MAJOR = exports.NUM_MAP;
  258. exports.MINOR = exports.MAJOR;
  259. var HEADER_STATE;
  260. (function (HEADER_STATE) {
  261. HEADER_STATE[HEADER_STATE["GENERAL"] = 0] = "GENERAL";
  262. HEADER_STATE[HEADER_STATE["CONNECTION"] = 1] = "CONNECTION";
  263. HEADER_STATE[HEADER_STATE["CONTENT_LENGTH"] = 2] = "CONTENT_LENGTH";
  264. HEADER_STATE[HEADER_STATE["TRANSFER_ENCODING"] = 3] = "TRANSFER_ENCODING";
  265. HEADER_STATE[HEADER_STATE["UPGRADE"] = 4] = "UPGRADE";
  266. HEADER_STATE[HEADER_STATE["CONNECTION_KEEP_ALIVE"] = 5] = "CONNECTION_KEEP_ALIVE";
  267. HEADER_STATE[HEADER_STATE["CONNECTION_CLOSE"] = 6] = "CONNECTION_CLOSE";
  268. HEADER_STATE[HEADER_STATE["CONNECTION_UPGRADE"] = 7] = "CONNECTION_UPGRADE";
  269. HEADER_STATE[HEADER_STATE["TRANSFER_ENCODING_CHUNKED"] = 8] = "TRANSFER_ENCODING_CHUNKED";
  270. })(HEADER_STATE = exports.HEADER_STATE || (exports.HEADER_STATE = {}));
  271. exports.SPECIAL_HEADERS = {
  272. 'connection': HEADER_STATE.CONNECTION,
  273. 'content-length': HEADER_STATE.CONTENT_LENGTH,
  274. 'proxy-connection': HEADER_STATE.CONNECTION,
  275. 'transfer-encoding': HEADER_STATE.TRANSFER_ENCODING,
  276. 'upgrade': HEADER_STATE.UPGRADE,
  277. };
  278. //# sourceMappingURL=constants.js.map