joyent_http_parser.nim 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2015 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. type
  10. csize = int
  11. HttpDataProc* = proc (a2: ptr HttpParser, at: cstring, length: csize): cint {.cdecl.}
  12. HttpProc* = proc (a2: ptr HttpParser): cint {.cdecl.}
  13. HttpMethod* = enum
  14. HTTP_DELETE = 0, HTTP_GET, HTTP_HEAD, HTTP_POST, HTTP_PUT, HTTP_CONNECT,
  15. HTTP_OPTIONS, HTTP_TRACE, HTTP_COPY, HTTP_LOCK, HTTP_MKCOL, HTTP_MOVE,
  16. HTTP_PROPFIND, HTTP_PROPPATCH, HTTP_UNLOCK, HTTP_REPORT, HTTP_MKACTIVITY,
  17. HTTP_CHECKOUT, HTTP_MERGE, HTTP_MSEARCH, HTTP_NOTIFY, HTTP_SUBSCRIBE,
  18. HTTP_UNSUBSCRIBE, HTTP_PATCH
  19. HttpParserType* = enum
  20. HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH
  21. ParserFlag* = enum
  22. F_CHUNKED = 1 shl 0,
  23. F_CONNECTION_KEEP_ALIVE = 1 shl 1,
  24. F_CONNECTION_CLOSE = 1 shl 2,
  25. F_TRAILING = 1 shl 3,
  26. F_UPGRADE = 1 shl 4,
  27. F_SKIPBODY = 1 shl 5
  28. HttpErrNo* = enum
  29. HPE_OK, HPE_CB_message_begin, HPE_CB_path, HPE_CB_query_string, HPE_CB_url,
  30. HPE_CB_fragment, HPE_CB_header_field, HPE_CB_header_value,
  31. HPE_CB_headers_complete, HPE_CB_body, HPE_CB_message_complete,
  32. HPE_INVALID_EOF_STATE, HPE_HEADER_OVERFLOW, HPE_CLOSED_CONNECTION,
  33. HPE_INVALID_VERSION, HPE_INVALID_STATUS, HPE_INVALID_METHOD,
  34. HPE_INVALID_URL, HPE_INVALID_HOST, HPE_INVALID_PORT, HPE_INVALID_PATH,
  35. HPE_INVALID_QUERY_STRING, HPE_INVALID_FRAGMENT, HPE_LF_EXPECTED,
  36. HPE_INVALID_HEADER_TOKEN, HPE_INVALID_CONTENT_LENGTH,
  37. HPE_INVALID_CHUNK_SIZE, HPE_INVALID_CONSTANT, HPE_INVALID_INTERNAL_STATE,
  38. HPE_STRICT, HPE_UNKNOWN
  39. HttpParser*{.pure, final, importc: "http_parser", header: "http_parser.h".} = object
  40. typ {.importc: "type".}: char
  41. flags {.importc: "flags".}: char
  42. state*{.importc: "state".}: char
  43. header_state*{.importc: "header_state".}: char
  44. index*{.importc: "index".}: char
  45. nread*{.importc: "nread".}: cint
  46. content_length*{.importc: "content_length".}: int64
  47. http_major*{.importc: "http_major".}: cshort
  48. http_minor*{.importc: "http_minor".}: cshort
  49. status_code*{.importc: "status_code".}: cshort
  50. http_method*{.importc: "method".}: cshort
  51. http_errno_bits {.importc: "http_errno".}: char
  52. upgrade {.importc: "upgrade".}: bool
  53. data*{.importc: "data".}: pointer
  54. HttpParserSettings*{.pure, final, importc: "http_parser_settings", header: "http_parser.h".} = object
  55. on_message_begin*{.importc: "on_message_begin".}: HttpProc
  56. on_url*{.importc: "on_url".}: HttpDataProc
  57. on_header_field*{.importc: "on_header_field".}: HttpDataProc
  58. on_header_value*{.importc: "on_header_value".}: HttpDataProc
  59. on_headers_complete*{.importc: "on_headers_complete".}: HttpProc
  60. on_body*{.importc: "on_body".}: HttpDataProc
  61. on_message_complete*{.importc: "on_message_complete".}: HttpProc
  62. {.deprecated: [THttpMethod: HttpMethod, THttpParserType: HttpParserType,
  63. TParserFlag: ParserFlag, THttpErrNo: HttpErrNo,
  64. THttpParser: HttpParser, THttpParserSettings: HttpParserSettings].}
  65. proc http_parser_init*(parser: var HttpParser, typ: HttpParserType){.
  66. importc: "http_parser_init", header: "http_parser.h".}
  67. proc http_parser_execute*(parser: var HttpParser,
  68. settings: var HttpParserSettings, data: cstring,
  69. len: csize): csize {.
  70. importc: "http_parser_execute", header: "http_parser.h".}
  71. proc http_should_keep_alive*(parser: var HttpParser): cint{.
  72. importc: "http_should_keep_alive", header: "http_parser.h".}
  73. proc http_method_str*(m: HttpMethod): cstring{.
  74. importc: "http_method_str", header: "http_parser.h".}
  75. proc http_errno_name*(err: HttpErrNo): cstring{.
  76. importc: "http_errno_name", header: "http_parser.h".}
  77. proc http_errno_description*(err: HttpErrNo): cstring{.
  78. importc: "http_errno_description", header: "http_parser.h".}