_cparser.pxd 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. from libc.stdint cimport uint16_t, uint32_t, uint64_t
  2. cdef extern from "../vendor/http-parser/http_parser.h":
  3. ctypedef int (*http_data_cb) (http_parser*,
  4. const char *at,
  5. size_t length) except -1
  6. ctypedef int (*http_cb) (http_parser*) except -1
  7. struct http_parser:
  8. unsigned int type
  9. unsigned int flags
  10. unsigned int state
  11. unsigned int header_state
  12. unsigned int index
  13. uint32_t nread
  14. uint64_t content_length
  15. unsigned short http_major
  16. unsigned short http_minor
  17. unsigned int status_code
  18. unsigned int method
  19. unsigned int http_errno
  20. unsigned int upgrade
  21. void *data
  22. struct http_parser_settings:
  23. http_cb on_message_begin
  24. http_data_cb on_url
  25. http_data_cb on_status
  26. http_data_cb on_header_field
  27. http_data_cb on_header_value
  28. http_cb on_headers_complete
  29. http_data_cb on_body
  30. http_cb on_message_complete
  31. http_cb on_chunk_header
  32. http_cb on_chunk_complete
  33. enum http_parser_type:
  34. HTTP_REQUEST,
  35. HTTP_RESPONSE,
  36. HTTP_BOTH
  37. enum http_errno:
  38. HPE_OK,
  39. HPE_CB_message_begin,
  40. HPE_CB_url,
  41. HPE_CB_header_field,
  42. HPE_CB_header_value,
  43. HPE_CB_headers_complete,
  44. HPE_CB_body,
  45. HPE_CB_message_complete,
  46. HPE_CB_status,
  47. HPE_CB_chunk_header,
  48. HPE_CB_chunk_complete,
  49. HPE_INVALID_EOF_STATE,
  50. HPE_HEADER_OVERFLOW,
  51. HPE_CLOSED_CONNECTION,
  52. HPE_INVALID_VERSION,
  53. HPE_INVALID_STATUS,
  54. HPE_INVALID_METHOD,
  55. HPE_INVALID_URL,
  56. HPE_INVALID_HOST,
  57. HPE_INVALID_PORT,
  58. HPE_INVALID_PATH,
  59. HPE_INVALID_QUERY_STRING,
  60. HPE_INVALID_FRAGMENT,
  61. HPE_LF_EXPECTED,
  62. HPE_INVALID_HEADER_TOKEN,
  63. HPE_INVALID_CONTENT_LENGTH,
  64. HPE_INVALID_CHUNK_SIZE,
  65. HPE_INVALID_CONSTANT,
  66. HPE_INVALID_INTERNAL_STATE,
  67. HPE_STRICT,
  68. HPE_PAUSED,
  69. HPE_UNKNOWN
  70. enum flags:
  71. F_CHUNKED,
  72. F_CONNECTION_KEEP_ALIVE,
  73. F_CONNECTION_CLOSE,
  74. F_CONNECTION_UPGRADE,
  75. F_TRAILING,
  76. F_UPGRADE,
  77. F_SKIPBODY,
  78. F_CONTENTLENGTH
  79. enum http_method:
  80. DELETE, GET, HEAD, POST, PUT, CONNECT, OPTIONS, TRACE, COPY,
  81. LOCK, MKCOL, MOVE, PROPFIND, PROPPATCH, SEARCH, UNLOCK, BIND,
  82. REBIND, UNBIND, ACL, REPORT, MKACTIVITY, CHECKOUT, MERGE,
  83. MSEARCH, NOTIFY, SUBSCRIBE, UNSUBSCRIBE, PATCH, PURGE, MKCALENDAR,
  84. LINK, UNLINK
  85. void http_parser_init(http_parser *parser, http_parser_type type)
  86. size_t http_parser_execute(http_parser *parser,
  87. const http_parser_settings *settings,
  88. const char *data,
  89. size_t len)
  90. int http_should_keep_alive(const http_parser *parser)
  91. void http_parser_settings_init(http_parser_settings *settings)
  92. const char *http_errno_name(http_errno err)
  93. const char *http_errno_description(http_errno err)
  94. const char *http_method_str(http_method m)
  95. # URL Parser
  96. enum http_parser_url_fields:
  97. UF_SCHEMA = 0,
  98. UF_HOST = 1,
  99. UF_PORT = 2,
  100. UF_PATH = 3,
  101. UF_QUERY = 4,
  102. UF_FRAGMENT = 5,
  103. UF_USERINFO = 6,
  104. UF_MAX = 7
  105. struct http_parser_url_field_data:
  106. uint16_t off
  107. uint16_t len
  108. struct http_parser_url:
  109. uint16_t field_set
  110. uint16_t port
  111. http_parser_url_field_data[<int>UF_MAX] field_data
  112. void http_parser_url_init(http_parser_url *u)
  113. int http_parser_parse_url(const char *buf,
  114. size_t buflen,
  115. int is_connect,
  116. http_parser_url *u)