gen-static-table.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. var utils = require('./utils');
  2. var table = `
  3. 1 :authority
  4. 2 :method GET
  5. 3 :method POST
  6. 4 :path /
  7. 5 :path /index.html
  8. 6 :scheme http
  9. 7 :scheme https
  10. 8 :status 200
  11. 9 :status 204
  12. 10 :status 206
  13. 11 :status 304
  14. 12 :status 400
  15. 13 :status 404
  16. 14 :status 500
  17. 15 accept-charset
  18. 16 accept-encoding gzip, deflate
  19. 17 accept-language
  20. 18 accept-ranges
  21. 19 accept
  22. 20 access-control-allow-origin
  23. 21 age
  24. 22 allow
  25. 23 authorization
  26. 24 cache-control
  27. 25 content-disposition
  28. 26 content-encoding
  29. 27 content-language
  30. 28 content-length
  31. 29 content-location
  32. 30 content-range
  33. 31 content-type
  34. 32 cookie
  35. 33 date
  36. 34 etag
  37. 35 expect
  38. 36 expires
  39. 37 from
  40. 38 host
  41. 39 if-match
  42. 40 if-modified-since
  43. 41 if-none-match
  44. 42 if-range
  45. 43 if-unmodified-since
  46. 44 last-modified
  47. 45 link
  48. 46 location
  49. 47 max-forwards
  50. 48 proxy-authenticate
  51. 49 proxy-authorization
  52. 50 range
  53. 51 referer
  54. 52 refresh
  55. 53 retry-after
  56. 54 server
  57. 55 set-cookie
  58. 56 strict-transport-security
  59. 57 transfer-encoding
  60. 58 user-agent
  61. 59 vary
  62. 60 via
  63. 61 www-authenticate
  64. `;
  65. var out = [];
  66. table.split('\n').filter(function(line) {
  67. return line;
  68. }).forEach(function(line) {
  69. var columns = line.split(/\t/g);
  70. var name = columns[1];
  71. var value = columns[2];
  72. var nameSize = Buffer.byteLength(name);
  73. var valueSize = Buffer.byteLength(value);
  74. out.push({
  75. name: name,
  76. value: value,
  77. nameSize: nameSize,
  78. totalSize: nameSize + valueSize + 32
  79. });
  80. });
  81. console.log('exports.table = ' + JSON.stringify(out, false, 2) + ';');
  82. var map = {};
  83. table.split('\n').filter(function(line) {
  84. return line;
  85. }).forEach(function(line) {
  86. var columns = line.split(/\t/g);
  87. var name = columns[1];
  88. var value = columns[2];
  89. var index = columns[0] | 0;
  90. if (!map[name]) {
  91. map[name] = {
  92. index: index,
  93. values: {}
  94. };
  95. }
  96. map[name].values[value] = index;
  97. });
  98. console.log('exports.map = ' + JSON.stringify(map, false, 2) + ';');