uhpacktables.pp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. (*
  2. HPACK: Header Compression for HTTP/2 (rfc7541)
  3. ----------------------------------------------
  4. Pascal implementation of HTTP/2 headers send and receive process.
  5. Code based in Twitter's HPACK for java https://github.com/twitter/hpack
  6. History:
  7. 2016.04.21 - Initial development by Jose Mejuto
  8. Package source files
  9. uhpackapi.pas (this file)
  10. uhpack.pas
  11. uhpacktables.pas
  12. rfc7541.txt (rfc based on)
  13. License:
  14. See the file COPYING.FPC, included in this distribution,
  15. for details about the copyright.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. *)
  20. unit uhpacktables;
  21. interface
  22. const
  23. HPACK_HUFFMAN_CODES_LENGTH=257;
  24. HPackHuffmanCodes: array [0..HPACK_HUFFMAN_CODES_LENGTH-1] of DWORD =(
  25. $1ff8, $7fffd8, $fffffe2, $fffffe3, $fffffe4, $fffffe5, $fffffe6, $fffffe7,
  26. $fffffe8, $ffffea, $3ffffffc, $fffffe9, $fffffea, $3ffffffd, $fffffeb, $fffffec,
  27. $fffffed, $fffffee, $fffffef, $ffffff0, $ffffff1, $ffffff2, $3ffffffe, $ffffff3,
  28. $ffffff4, $ffffff5, $ffffff6, $ffffff7, $ffffff8, $ffffff9, $ffffffa, $ffffffb,
  29. $14, $3f8, $3f9, $ffa, $1ff9, $15, $f8, $7fa,
  30. $3fa, $3fb, $f9, $7fb, $fa, $16, $17, $18,
  31. $0, $1, $2, $19, $1a, $1b, $1c, $1d,
  32. $1e, $1f, $5c, $fb, $7ffc, $20, $ffb, $3fc,
  33. $1ffa, $21, $5d, $5e, $5f, $60, $61, $62,
  34. $63, $64, $65, $66, $67, $68, $69, $6a,
  35. $6b, $6c, $6d, $6e, $6f, $70, $71, $72,
  36. $fc, $73, $fd, $1ffb, $7fff0, $1ffc, $3ffc, $22,
  37. $7ffd, $3, $23, $4, $24, $5, $25, $26,
  38. $27, $6, $74, $75, $28, $29, $2a, $7,
  39. $2b, $76, $2c, $8, $9, $2d, $77, $78,
  40. $79, $7a, $7b, $7ffe, $7fc, $3ffd, $1ffd, $ffffffc,
  41. $fffe6, $3fffd2, $fffe7, $fffe8, $3fffd3, $3fffd4, $3fffd5, $7fffd9,
  42. $3fffd6, $7fffda, $7fffdb, $7fffdc, $7fffdd, $7fffde, $ffffeb, $7fffdf,
  43. $ffffec, $ffffed, $3fffd7, $7fffe0, $ffffee, $7fffe1, $7fffe2, $7fffe3,
  44. $7fffe4, $1fffdc, $3fffd8, $7fffe5, $3fffd9, $7fffe6, $7fffe7, $ffffef,
  45. $3fffda, $1fffdd, $fffe9, $3fffdb, $3fffdc, $7fffe8, $7fffe9, $1fffde,
  46. $7fffea, $3fffdd, $3fffde, $fffff0, $1fffdf, $3fffdf, $7fffeb, $7fffec,
  47. $1fffe0, $1fffe1, $3fffe0, $1fffe2, $7fffed, $3fffe1, $7fffee, $7fffef,
  48. $fffea, $3fffe2, $3fffe3, $3fffe4, $7ffff0, $3fffe5, $3fffe6, $7ffff1,
  49. $3ffffe0, $3ffffe1, $fffeb, $7fff1, $3fffe7, $7ffff2, $3fffe8, $1ffffec,
  50. $3ffffe2, $3ffffe3, $3ffffe4, $7ffffde, $7ffffdf, $3ffffe5, $fffff1, $1ffffed,
  51. $7fff2, $1fffe3, $3ffffe6, $7ffffe0, $7ffffe1, $3ffffe7, $7ffffe2, $fffff2,
  52. $1fffe4, $1fffe5, $3ffffe8, $3ffffe9, $ffffffd, $7ffffe3, $7ffffe4, $7ffffe5,
  53. $fffec, $fffff3, $fffed, $1fffe6, $3fffe9, $1fffe7, $1fffe8, $7ffff3,
  54. $3fffea, $3fffeb, $1ffffee, $1ffffef, $fffff4, $fffff5, $3ffffea, $7ffff4,
  55. $3ffffeb, $7ffffe6, $3ffffec, $3ffffed, $7ffffe7, $7ffffe8, $7ffffe9, $7ffffea,
  56. $7ffffeb, $ffffffe, $7ffffec, $7ffffed, $7ffffee, $7ffffef, $7fffff0, $3ffffee,
  57. $3fffffff // EOS
  58. );
  59. HPackHuffmanCodeLength: array [0..256] of byte =(
  60. 13, 23, 28, 28, 28, 28, 28, 28, 28, 24, 30, 28, 28, 30, 28, 28,
  61. 28, 28, 28, 28, 28, 28, 30, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  62. 6, 10, 10, 12, 13, 6, 8, 11, 10, 10, 8, 11, 8, 6, 6, 6,
  63. 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 8, 15, 6, 12, 10,
  64. 13, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  65. 7, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 13, 19, 13, 14, 6,
  66. 15, 5, 6, 5, 6, 5, 6, 6, 6, 5, 7, 7, 6, 6, 6, 5,
  67. 6, 7, 6, 5, 5, 6, 7, 7, 7, 7, 7, 15, 11, 14, 13, 28,
  68. 20, 22, 20, 20, 22, 22, 22, 23, 22, 23, 23, 23, 23, 23, 24, 23,
  69. 24, 24, 22, 23, 24, 23, 23, 23, 23, 21, 22, 23, 22, 23, 23, 24,
  70. 22, 21, 20, 22, 22, 23, 23, 21, 23, 22, 22, 24, 21, 22, 23, 23,
  71. 21, 21, 22, 21, 23, 22, 23, 23, 20, 22, 22, 22, 23, 22, 22, 23,
  72. 26, 26, 20, 19, 22, 23, 22, 25, 26, 26, 26, 27, 27, 26, 24, 25,
  73. 19, 21, 26, 27, 27, 26, 27, 24, 21, 21, 26, 26, 28, 27, 27, 27,
  74. 20, 24, 20, 21, 22, 21, 21, 23, 22, 22, 25, 25, 24, 24, 26, 23,
  75. 26, 27, 26, 26, 27, 27, 27, 27, 27, 28, 27, 27, 27, 27, 27, 26,
  76. 30 // EOS
  77. );
  78. HPACK_HUFFMAN_EOS: integer = 256;
  79. HPACK_HEADER_ENTRY_OVERHEAD = 32;
  80. type
  81. THPackIndexType=(
  82. eHPackINCREMENTAL, // Section 6.2.1. Literal Header Field with Incremental Indexing
  83. eHPackNONE, // Section 6.2.2. Literal Header Field without Indexing
  84. eHPackNEVER // Section 6.2.3. Literal Header Field never Indexed
  85. );
  86. THPackState =(
  87. READ_HEADER_REPRESENTATION,
  88. READ_MAX_DYNAMIC_TABLE_SIZE,
  89. READ_INDEXED_HEADER,
  90. READ_INDEXED_HEADER_NAME,
  91. READ_LITERAL_HEADER_NAME_LENGTH_PREFIX,
  92. READ_LITERAL_HEADER_NAME_LENGTH,
  93. READ_LITERAL_HEADER_NAME,
  94. SKIP_LITERAL_HEADER_NAME,
  95. READ_LITERAL_HEADER_VALUE_LENGTH_PREFIX,
  96. READ_LITERAL_HEADER_VALUE_LENGTH,
  97. READ_LITERAL_HEADER_VALUE,
  98. SKIP_LITERAL_HEADER_VALUE
  99. );
  100. implementation
  101. end.