llhttp.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. #ifndef INCLUDE_LLHTTP_H_
  2. #define INCLUDE_LLHTTP_H_
  3. #define LLHTTP_VERSION_MAJOR 9
  4. #define LLHTTP_VERSION_MINOR 2
  5. #define LLHTTP_VERSION_PATCH 1
  6. #ifndef INCLUDE_LLHTTP_ITSELF_H_
  7. #define INCLUDE_LLHTTP_ITSELF_H_
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #include <stdint.h>
  12. typedef struct llhttp__internal_s llhttp__internal_t;
  13. struct llhttp__internal_s {
  14. int32_t _index;
  15. void* _span_pos0;
  16. void* _span_cb0;
  17. int32_t error;
  18. const char* reason;
  19. const char* error_pos;
  20. void* data;
  21. void* _current;
  22. uint64_t content_length;
  23. uint8_t type;
  24. uint8_t method;
  25. uint8_t http_major;
  26. uint8_t http_minor;
  27. uint8_t header_state;
  28. uint16_t lenient_flags;
  29. uint8_t upgrade;
  30. uint8_t finish;
  31. uint16_t flags;
  32. uint16_t status_code;
  33. uint8_t initial_message_completed;
  34. void* settings;
  35. };
  36. int llhttp__internal_init(llhttp__internal_t* s);
  37. int llhttp__internal_execute(llhttp__internal_t* s, const char* p, const char* endp);
  38. #ifdef __cplusplus
  39. } /* extern "C" */
  40. #endif
  41. #endif /* INCLUDE_LLHTTP_ITSELF_H_ */
  42. #ifndef LLLLHTTP_C_HEADERS_
  43. #define LLLLHTTP_C_HEADERS_
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. enum llhttp_errno {
  48. HPE_OK = 0,
  49. HPE_INTERNAL = 1,
  50. HPE_STRICT = 2,
  51. HPE_CR_EXPECTED = 25,
  52. HPE_LF_EXPECTED = 3,
  53. HPE_UNEXPECTED_CONTENT_LENGTH = 4,
  54. HPE_UNEXPECTED_SPACE = 30,
  55. HPE_CLOSED_CONNECTION = 5,
  56. HPE_INVALID_METHOD = 6,
  57. HPE_INVALID_URL = 7,
  58. HPE_INVALID_CONSTANT = 8,
  59. HPE_INVALID_VERSION = 9,
  60. HPE_INVALID_HEADER_TOKEN = 10,
  61. HPE_INVALID_CONTENT_LENGTH = 11,
  62. HPE_INVALID_CHUNK_SIZE = 12,
  63. HPE_INVALID_STATUS = 13,
  64. HPE_INVALID_EOF_STATE = 14,
  65. HPE_INVALID_TRANSFER_ENCODING = 15,
  66. HPE_CB_MESSAGE_BEGIN = 16,
  67. HPE_CB_HEADERS_COMPLETE = 17,
  68. HPE_CB_MESSAGE_COMPLETE = 18,
  69. HPE_CB_CHUNK_HEADER = 19,
  70. HPE_CB_CHUNK_COMPLETE = 20,
  71. HPE_PAUSED = 21,
  72. HPE_PAUSED_UPGRADE = 22,
  73. HPE_PAUSED_H2_UPGRADE = 23,
  74. HPE_USER = 24,
  75. HPE_CB_URL_COMPLETE = 26,
  76. HPE_CB_STATUS_COMPLETE = 27,
  77. HPE_CB_METHOD_COMPLETE = 32,
  78. HPE_CB_VERSION_COMPLETE = 33,
  79. HPE_CB_HEADER_FIELD_COMPLETE = 28,
  80. HPE_CB_HEADER_VALUE_COMPLETE = 29,
  81. HPE_CB_CHUNK_EXTENSION_NAME_COMPLETE = 34,
  82. HPE_CB_CHUNK_EXTENSION_VALUE_COMPLETE = 35,
  83. HPE_CB_RESET = 31
  84. };
  85. typedef enum llhttp_errno llhttp_errno_t;
  86. enum llhttp_flags {
  87. F_CONNECTION_KEEP_ALIVE = 0x1,
  88. F_CONNECTION_CLOSE = 0x2,
  89. F_CONNECTION_UPGRADE = 0x4,
  90. F_CHUNKED = 0x8,
  91. F_UPGRADE = 0x10,
  92. F_CONTENT_LENGTH = 0x20,
  93. F_SKIPBODY = 0x40,
  94. F_TRAILING = 0x80,
  95. F_TRANSFER_ENCODING = 0x200
  96. };
  97. typedef enum llhttp_flags llhttp_flags_t;
  98. enum llhttp_lenient_flags {
  99. LENIENT_HEADERS = 0x1,
  100. LENIENT_CHUNKED_LENGTH = 0x2,
  101. LENIENT_KEEP_ALIVE = 0x4,
  102. LENIENT_TRANSFER_ENCODING = 0x8,
  103. LENIENT_VERSION = 0x10,
  104. LENIENT_DATA_AFTER_CLOSE = 0x20,
  105. LENIENT_OPTIONAL_LF_AFTER_CR = 0x40,
  106. LENIENT_OPTIONAL_CRLF_AFTER_CHUNK = 0x80,
  107. LENIENT_OPTIONAL_CR_BEFORE_LF = 0x100,
  108. LENIENT_SPACES_AFTER_CHUNK_SIZE = 0x200
  109. };
  110. typedef enum llhttp_lenient_flags llhttp_lenient_flags_t;
  111. enum llhttp_type {
  112. HTTP_BOTH = 0,
  113. HTTP_REQUEST = 1,
  114. HTTP_RESPONSE = 2
  115. };
  116. typedef enum llhttp_type llhttp_type_t;
  117. enum llhttp_finish {
  118. HTTP_FINISH_SAFE = 0,
  119. HTTP_FINISH_SAFE_WITH_CB = 1,
  120. HTTP_FINISH_UNSAFE = 2
  121. };
  122. typedef enum llhttp_finish llhttp_finish_t;
  123. enum llhttp_method {
  124. HTTP_DELETE = 0,
  125. HTTP_GET = 1,
  126. HTTP_HEAD = 2,
  127. HTTP_POST = 3,
  128. HTTP_PUT = 4,
  129. HTTP_CONNECT = 5,
  130. HTTP_OPTIONS = 6,
  131. HTTP_TRACE = 7,
  132. HTTP_COPY = 8,
  133. HTTP_LOCK = 9,
  134. HTTP_MKCOL = 10,
  135. HTTP_MOVE = 11,
  136. HTTP_PROPFIND = 12,
  137. HTTP_PROPPATCH = 13,
  138. HTTP_SEARCH = 14,
  139. HTTP_UNLOCK = 15,
  140. HTTP_BIND = 16,
  141. HTTP_REBIND = 17,
  142. HTTP_UNBIND = 18,
  143. HTTP_ACL = 19,
  144. HTTP_REPORT = 20,
  145. HTTP_MKACTIVITY = 21,
  146. HTTP_CHECKOUT = 22,
  147. HTTP_MERGE = 23,
  148. HTTP_MSEARCH = 24,
  149. HTTP_NOTIFY = 25,
  150. HTTP_SUBSCRIBE = 26,
  151. HTTP_UNSUBSCRIBE = 27,
  152. HTTP_PATCH = 28,
  153. HTTP_PURGE = 29,
  154. HTTP_MKCALENDAR = 30,
  155. HTTP_LINK = 31,
  156. HTTP_UNLINK = 32,
  157. HTTP_SOURCE = 33,
  158. HTTP_PRI = 34,
  159. HTTP_DESCRIBE = 35,
  160. HTTP_ANNOUNCE = 36,
  161. HTTP_SETUP = 37,
  162. HTTP_PLAY = 38,
  163. HTTP_PAUSE = 39,
  164. HTTP_TEARDOWN = 40,
  165. HTTP_GET_PARAMETER = 41,
  166. HTTP_SET_PARAMETER = 42,
  167. HTTP_REDIRECT = 43,
  168. HTTP_RECORD = 44,
  169. HTTP_FLUSH = 45,
  170. HTTP_QUERY = 46
  171. };
  172. typedef enum llhttp_method llhttp_method_t;
  173. enum llhttp_status {
  174. HTTP_STATUS_CONTINUE = 100,
  175. HTTP_STATUS_SWITCHING_PROTOCOLS = 101,
  176. HTTP_STATUS_PROCESSING = 102,
  177. HTTP_STATUS_EARLY_HINTS = 103,
  178. HTTP_STATUS_RESPONSE_IS_STALE = 110,
  179. HTTP_STATUS_REVALIDATION_FAILED = 111,
  180. HTTP_STATUS_DISCONNECTED_OPERATION = 112,
  181. HTTP_STATUS_HEURISTIC_EXPIRATION = 113,
  182. HTTP_STATUS_MISCELLANEOUS_WARNING = 199,
  183. HTTP_STATUS_OK = 200,
  184. HTTP_STATUS_CREATED = 201,
  185. HTTP_STATUS_ACCEPTED = 202,
  186. HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION = 203,
  187. HTTP_STATUS_NO_CONTENT = 204,
  188. HTTP_STATUS_RESET_CONTENT = 205,
  189. HTTP_STATUS_PARTIAL_CONTENT = 206,
  190. HTTP_STATUS_MULTI_STATUS = 207,
  191. HTTP_STATUS_ALREADY_REPORTED = 208,
  192. HTTP_STATUS_TRANSFORMATION_APPLIED = 214,
  193. HTTP_STATUS_IM_USED = 226,
  194. HTTP_STATUS_MISCELLANEOUS_PERSISTENT_WARNING = 299,
  195. HTTP_STATUS_MULTIPLE_CHOICES = 300,
  196. HTTP_STATUS_MOVED_PERMANENTLY = 301,
  197. HTTP_STATUS_FOUND = 302,
  198. HTTP_STATUS_SEE_OTHER = 303,
  199. HTTP_STATUS_NOT_MODIFIED = 304,
  200. HTTP_STATUS_USE_PROXY = 305,
  201. HTTP_STATUS_SWITCH_PROXY = 306,
  202. HTTP_STATUS_TEMPORARY_REDIRECT = 307,
  203. HTTP_STATUS_PERMANENT_REDIRECT = 308,
  204. HTTP_STATUS_BAD_REQUEST = 400,
  205. HTTP_STATUS_UNAUTHORIZED = 401,
  206. HTTP_STATUS_PAYMENT_REQUIRED = 402,
  207. HTTP_STATUS_FORBIDDEN = 403,
  208. HTTP_STATUS_NOT_FOUND = 404,
  209. HTTP_STATUS_METHOD_NOT_ALLOWED = 405,
  210. HTTP_STATUS_NOT_ACCEPTABLE = 406,
  211. HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED = 407,
  212. HTTP_STATUS_REQUEST_TIMEOUT = 408,
  213. HTTP_STATUS_CONFLICT = 409,
  214. HTTP_STATUS_GONE = 410,
  215. HTTP_STATUS_LENGTH_REQUIRED = 411,
  216. HTTP_STATUS_PRECONDITION_FAILED = 412,
  217. HTTP_STATUS_PAYLOAD_TOO_LARGE = 413,
  218. HTTP_STATUS_URI_TOO_LONG = 414,
  219. HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE = 415,
  220. HTTP_STATUS_RANGE_NOT_SATISFIABLE = 416,
  221. HTTP_STATUS_EXPECTATION_FAILED = 417,
  222. HTTP_STATUS_IM_A_TEAPOT = 418,
  223. HTTP_STATUS_PAGE_EXPIRED = 419,
  224. HTTP_STATUS_ENHANCE_YOUR_CALM = 420,
  225. HTTP_STATUS_MISDIRECTED_REQUEST = 421,
  226. HTTP_STATUS_UNPROCESSABLE_ENTITY = 422,
  227. HTTP_STATUS_LOCKED = 423,
  228. HTTP_STATUS_FAILED_DEPENDENCY = 424,
  229. HTTP_STATUS_TOO_EARLY = 425,
  230. HTTP_STATUS_UPGRADE_REQUIRED = 426,
  231. HTTP_STATUS_PRECONDITION_REQUIRED = 428,
  232. HTTP_STATUS_TOO_MANY_REQUESTS = 429,
  233. HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE_UNOFFICIAL = 430,
  234. HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
  235. HTTP_STATUS_LOGIN_TIMEOUT = 440,
  236. HTTP_STATUS_NO_RESPONSE = 444,
  237. HTTP_STATUS_RETRY_WITH = 449,
  238. HTTP_STATUS_BLOCKED_BY_PARENTAL_CONTROL = 450,
  239. HTTP_STATUS_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
  240. HTTP_STATUS_CLIENT_CLOSED_LOAD_BALANCED_REQUEST = 460,
  241. HTTP_STATUS_INVALID_X_FORWARDED_FOR = 463,
  242. HTTP_STATUS_REQUEST_HEADER_TOO_LARGE = 494,
  243. HTTP_STATUS_SSL_CERTIFICATE_ERROR = 495,
  244. HTTP_STATUS_SSL_CERTIFICATE_REQUIRED = 496,
  245. HTTP_STATUS_HTTP_REQUEST_SENT_TO_HTTPS_PORT = 497,
  246. HTTP_STATUS_INVALID_TOKEN = 498,
  247. HTTP_STATUS_CLIENT_CLOSED_REQUEST = 499,
  248. HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
  249. HTTP_STATUS_NOT_IMPLEMENTED = 501,
  250. HTTP_STATUS_BAD_GATEWAY = 502,
  251. HTTP_STATUS_SERVICE_UNAVAILABLE = 503,
  252. HTTP_STATUS_GATEWAY_TIMEOUT = 504,
  253. HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED = 505,
  254. HTTP_STATUS_VARIANT_ALSO_NEGOTIATES = 506,
  255. HTTP_STATUS_INSUFFICIENT_STORAGE = 507,
  256. HTTP_STATUS_LOOP_DETECTED = 508,
  257. HTTP_STATUS_BANDWIDTH_LIMIT_EXCEEDED = 509,
  258. HTTP_STATUS_NOT_EXTENDED = 510,
  259. HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511,
  260. HTTP_STATUS_WEB_SERVER_UNKNOWN_ERROR = 520,
  261. HTTP_STATUS_WEB_SERVER_IS_DOWN = 521,
  262. HTTP_STATUS_CONNECTION_TIMEOUT = 522,
  263. HTTP_STATUS_ORIGIN_IS_UNREACHABLE = 523,
  264. HTTP_STATUS_TIMEOUT_OCCURED = 524,
  265. HTTP_STATUS_SSL_HANDSHAKE_FAILED = 525,
  266. HTTP_STATUS_INVALID_SSL_CERTIFICATE = 526,
  267. HTTP_STATUS_RAILGUN_ERROR = 527,
  268. HTTP_STATUS_SITE_IS_OVERLOADED = 529,
  269. HTTP_STATUS_SITE_IS_FROZEN = 530,
  270. HTTP_STATUS_IDENTITY_PROVIDER_AUTHENTICATION_ERROR = 561,
  271. HTTP_STATUS_NETWORK_READ_TIMEOUT = 598,
  272. HTTP_STATUS_NETWORK_CONNECT_TIMEOUT = 599
  273. };
  274. typedef enum llhttp_status llhttp_status_t;
  275. #define HTTP_ERRNO_MAP(XX) \
  276. XX(0, OK, OK) \
  277. XX(1, INTERNAL, INTERNAL) \
  278. XX(2, STRICT, STRICT) \
  279. XX(25, CR_EXPECTED, CR_EXPECTED) \
  280. XX(3, LF_EXPECTED, LF_EXPECTED) \
  281. XX(4, UNEXPECTED_CONTENT_LENGTH, UNEXPECTED_CONTENT_LENGTH) \
  282. XX(30, UNEXPECTED_SPACE, UNEXPECTED_SPACE) \
  283. XX(5, CLOSED_CONNECTION, CLOSED_CONNECTION) \
  284. XX(6, INVALID_METHOD, INVALID_METHOD) \
  285. XX(7, INVALID_URL, INVALID_URL) \
  286. XX(8, INVALID_CONSTANT, INVALID_CONSTANT) \
  287. XX(9, INVALID_VERSION, INVALID_VERSION) \
  288. XX(10, INVALID_HEADER_TOKEN, INVALID_HEADER_TOKEN) \
  289. XX(11, INVALID_CONTENT_LENGTH, INVALID_CONTENT_LENGTH) \
  290. XX(12, INVALID_CHUNK_SIZE, INVALID_CHUNK_SIZE) \
  291. XX(13, INVALID_STATUS, INVALID_STATUS) \
  292. XX(14, INVALID_EOF_STATE, INVALID_EOF_STATE) \
  293. XX(15, INVALID_TRANSFER_ENCODING, INVALID_TRANSFER_ENCODING) \
  294. XX(16, CB_MESSAGE_BEGIN, CB_MESSAGE_BEGIN) \
  295. XX(17, CB_HEADERS_COMPLETE, CB_HEADERS_COMPLETE) \
  296. XX(18, CB_MESSAGE_COMPLETE, CB_MESSAGE_COMPLETE) \
  297. XX(19, CB_CHUNK_HEADER, CB_CHUNK_HEADER) \
  298. XX(20, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \
  299. XX(21, PAUSED, PAUSED) \
  300. XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \
  301. XX(23, PAUSED_H2_UPGRADE, PAUSED_H2_UPGRADE) \
  302. XX(24, USER, USER) \
  303. XX(26, CB_URL_COMPLETE, CB_URL_COMPLETE) \
  304. XX(27, CB_STATUS_COMPLETE, CB_STATUS_COMPLETE) \
  305. XX(32, CB_METHOD_COMPLETE, CB_METHOD_COMPLETE) \
  306. XX(33, CB_VERSION_COMPLETE, CB_VERSION_COMPLETE) \
  307. XX(28, CB_HEADER_FIELD_COMPLETE, CB_HEADER_FIELD_COMPLETE) \
  308. XX(29, CB_HEADER_VALUE_COMPLETE, CB_HEADER_VALUE_COMPLETE) \
  309. XX(34, CB_CHUNK_EXTENSION_NAME_COMPLETE, CB_CHUNK_EXTENSION_NAME_COMPLETE) \
  310. XX(35, CB_CHUNK_EXTENSION_VALUE_COMPLETE, CB_CHUNK_EXTENSION_VALUE_COMPLETE) \
  311. XX(31, CB_RESET, CB_RESET) \
  312. #define HTTP_METHOD_MAP(XX) \
  313. XX(0, DELETE, DELETE) \
  314. XX(1, GET, GET) \
  315. XX(2, HEAD, HEAD) \
  316. XX(3, POST, POST) \
  317. XX(4, PUT, PUT) \
  318. XX(5, CONNECT, CONNECT) \
  319. XX(6, OPTIONS, OPTIONS) \
  320. XX(7, TRACE, TRACE) \
  321. XX(8, COPY, COPY) \
  322. XX(9, LOCK, LOCK) \
  323. XX(10, MKCOL, MKCOL) \
  324. XX(11, MOVE, MOVE) \
  325. XX(12, PROPFIND, PROPFIND) \
  326. XX(13, PROPPATCH, PROPPATCH) \
  327. XX(14, SEARCH, SEARCH) \
  328. XX(15, UNLOCK, UNLOCK) \
  329. XX(16, BIND, BIND) \
  330. XX(17, REBIND, REBIND) \
  331. XX(18, UNBIND, UNBIND) \
  332. XX(19, ACL, ACL) \
  333. XX(20, REPORT, REPORT) \
  334. XX(21, MKACTIVITY, MKACTIVITY) \
  335. XX(22, CHECKOUT, CHECKOUT) \
  336. XX(23, MERGE, MERGE) \
  337. XX(24, MSEARCH, M-SEARCH) \
  338. XX(25, NOTIFY, NOTIFY) \
  339. XX(26, SUBSCRIBE, SUBSCRIBE) \
  340. XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
  341. XX(28, PATCH, PATCH) \
  342. XX(29, PURGE, PURGE) \
  343. XX(30, MKCALENDAR, MKCALENDAR) \
  344. XX(31, LINK, LINK) \
  345. XX(32, UNLINK, UNLINK) \
  346. XX(33, SOURCE, SOURCE) \
  347. XX(46, QUERY, QUERY) \
  348. #define RTSP_METHOD_MAP(XX) \
  349. XX(1, GET, GET) \
  350. XX(3, POST, POST) \
  351. XX(6, OPTIONS, OPTIONS) \
  352. XX(35, DESCRIBE, DESCRIBE) \
  353. XX(36, ANNOUNCE, ANNOUNCE) \
  354. XX(37, SETUP, SETUP) \
  355. XX(38, PLAY, PLAY) \
  356. XX(39, PAUSE, PAUSE) \
  357. XX(40, TEARDOWN, TEARDOWN) \
  358. XX(41, GET_PARAMETER, GET_PARAMETER) \
  359. XX(42, SET_PARAMETER, SET_PARAMETER) \
  360. XX(43, REDIRECT, REDIRECT) \
  361. XX(44, RECORD, RECORD) \
  362. XX(45, FLUSH, FLUSH) \
  363. #define HTTP_ALL_METHOD_MAP(XX) \
  364. XX(0, DELETE, DELETE) \
  365. XX(1, GET, GET) \
  366. XX(2, HEAD, HEAD) \
  367. XX(3, POST, POST) \
  368. XX(4, PUT, PUT) \
  369. XX(5, CONNECT, CONNECT) \
  370. XX(6, OPTIONS, OPTIONS) \
  371. XX(7, TRACE, TRACE) \
  372. XX(8, COPY, COPY) \
  373. XX(9, LOCK, LOCK) \
  374. XX(10, MKCOL, MKCOL) \
  375. XX(11, MOVE, MOVE) \
  376. XX(12, PROPFIND, PROPFIND) \
  377. XX(13, PROPPATCH, PROPPATCH) \
  378. XX(14, SEARCH, SEARCH) \
  379. XX(15, UNLOCK, UNLOCK) \
  380. XX(16, BIND, BIND) \
  381. XX(17, REBIND, REBIND) \
  382. XX(18, UNBIND, UNBIND) \
  383. XX(19, ACL, ACL) \
  384. XX(20, REPORT, REPORT) \
  385. XX(21, MKACTIVITY, MKACTIVITY) \
  386. XX(22, CHECKOUT, CHECKOUT) \
  387. XX(23, MERGE, MERGE) \
  388. XX(24, MSEARCH, M-SEARCH) \
  389. XX(25, NOTIFY, NOTIFY) \
  390. XX(26, SUBSCRIBE, SUBSCRIBE) \
  391. XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
  392. XX(28, PATCH, PATCH) \
  393. XX(29, PURGE, PURGE) \
  394. XX(30, MKCALENDAR, MKCALENDAR) \
  395. XX(31, LINK, LINK) \
  396. XX(32, UNLINK, UNLINK) \
  397. XX(33, SOURCE, SOURCE) \
  398. XX(34, PRI, PRI) \
  399. XX(35, DESCRIBE, DESCRIBE) \
  400. XX(36, ANNOUNCE, ANNOUNCE) \
  401. XX(37, SETUP, SETUP) \
  402. XX(38, PLAY, PLAY) \
  403. XX(39, PAUSE, PAUSE) \
  404. XX(40, TEARDOWN, TEARDOWN) \
  405. XX(41, GET_PARAMETER, GET_PARAMETER) \
  406. XX(42, SET_PARAMETER, SET_PARAMETER) \
  407. XX(43, REDIRECT, REDIRECT) \
  408. XX(44, RECORD, RECORD) \
  409. XX(45, FLUSH, FLUSH) \
  410. XX(46, QUERY, QUERY) \
  411. #define HTTP_STATUS_MAP(XX) \
  412. XX(100, CONTINUE, CONTINUE) \
  413. XX(101, SWITCHING_PROTOCOLS, SWITCHING_PROTOCOLS) \
  414. XX(102, PROCESSING, PROCESSING) \
  415. XX(103, EARLY_HINTS, EARLY_HINTS) \
  416. XX(110, RESPONSE_IS_STALE, RESPONSE_IS_STALE) \
  417. XX(111, REVALIDATION_FAILED, REVALIDATION_FAILED) \
  418. XX(112, DISCONNECTED_OPERATION, DISCONNECTED_OPERATION) \
  419. XX(113, HEURISTIC_EXPIRATION, HEURISTIC_EXPIRATION) \
  420. XX(199, MISCELLANEOUS_WARNING, MISCELLANEOUS_WARNING) \
  421. XX(200, OK, OK) \
  422. XX(201, CREATED, CREATED) \
  423. XX(202, ACCEPTED, ACCEPTED) \
  424. XX(203, NON_AUTHORITATIVE_INFORMATION, NON_AUTHORITATIVE_INFORMATION) \
  425. XX(204, NO_CONTENT, NO_CONTENT) \
  426. XX(205, RESET_CONTENT, RESET_CONTENT) \
  427. XX(206, PARTIAL_CONTENT, PARTIAL_CONTENT) \
  428. XX(207, MULTI_STATUS, MULTI_STATUS) \
  429. XX(208, ALREADY_REPORTED, ALREADY_REPORTED) \
  430. XX(214, TRANSFORMATION_APPLIED, TRANSFORMATION_APPLIED) \
  431. XX(226, IM_USED, IM_USED) \
  432. XX(299, MISCELLANEOUS_PERSISTENT_WARNING, MISCELLANEOUS_PERSISTENT_WARNING) \
  433. XX(300, MULTIPLE_CHOICES, MULTIPLE_CHOICES) \
  434. XX(301, MOVED_PERMANENTLY, MOVED_PERMANENTLY) \
  435. XX(302, FOUND, FOUND) \
  436. XX(303, SEE_OTHER, SEE_OTHER) \
  437. XX(304, NOT_MODIFIED, NOT_MODIFIED) \
  438. XX(305, USE_PROXY, USE_PROXY) \
  439. XX(306, SWITCH_PROXY, SWITCH_PROXY) \
  440. XX(307, TEMPORARY_REDIRECT, TEMPORARY_REDIRECT) \
  441. XX(308, PERMANENT_REDIRECT, PERMANENT_REDIRECT) \
  442. XX(400, BAD_REQUEST, BAD_REQUEST) \
  443. XX(401, UNAUTHORIZED, UNAUTHORIZED) \
  444. XX(402, PAYMENT_REQUIRED, PAYMENT_REQUIRED) \
  445. XX(403, FORBIDDEN, FORBIDDEN) \
  446. XX(404, NOT_FOUND, NOT_FOUND) \
  447. XX(405, METHOD_NOT_ALLOWED, METHOD_NOT_ALLOWED) \
  448. XX(406, NOT_ACCEPTABLE, NOT_ACCEPTABLE) \
  449. XX(407, PROXY_AUTHENTICATION_REQUIRED, PROXY_AUTHENTICATION_REQUIRED) \
  450. XX(408, REQUEST_TIMEOUT, REQUEST_TIMEOUT) \
  451. XX(409, CONFLICT, CONFLICT) \
  452. XX(410, GONE, GONE) \
  453. XX(411, LENGTH_REQUIRED, LENGTH_REQUIRED) \
  454. XX(412, PRECONDITION_FAILED, PRECONDITION_FAILED) \
  455. XX(413, PAYLOAD_TOO_LARGE, PAYLOAD_TOO_LARGE) \
  456. XX(414, URI_TOO_LONG, URI_TOO_LONG) \
  457. XX(415, UNSUPPORTED_MEDIA_TYPE, UNSUPPORTED_MEDIA_TYPE) \
  458. XX(416, RANGE_NOT_SATISFIABLE, RANGE_NOT_SATISFIABLE) \
  459. XX(417, EXPECTATION_FAILED, EXPECTATION_FAILED) \
  460. XX(418, IM_A_TEAPOT, IM_A_TEAPOT) \
  461. XX(419, PAGE_EXPIRED, PAGE_EXPIRED) \
  462. XX(420, ENHANCE_YOUR_CALM, ENHANCE_YOUR_CALM) \
  463. XX(421, MISDIRECTED_REQUEST, MISDIRECTED_REQUEST) \
  464. XX(422, UNPROCESSABLE_ENTITY, UNPROCESSABLE_ENTITY) \
  465. XX(423, LOCKED, LOCKED) \
  466. XX(424, FAILED_DEPENDENCY, FAILED_DEPENDENCY) \
  467. XX(425, TOO_EARLY, TOO_EARLY) \
  468. XX(426, UPGRADE_REQUIRED, UPGRADE_REQUIRED) \
  469. XX(428, PRECONDITION_REQUIRED, PRECONDITION_REQUIRED) \
  470. XX(429, TOO_MANY_REQUESTS, TOO_MANY_REQUESTS) \
  471. XX(430, REQUEST_HEADER_FIELDS_TOO_LARGE_UNOFFICIAL, REQUEST_HEADER_FIELDS_TOO_LARGE_UNOFFICIAL) \
  472. XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, REQUEST_HEADER_FIELDS_TOO_LARGE) \
  473. XX(440, LOGIN_TIMEOUT, LOGIN_TIMEOUT) \
  474. XX(444, NO_RESPONSE, NO_RESPONSE) \
  475. XX(449, RETRY_WITH, RETRY_WITH) \
  476. XX(450, BLOCKED_BY_PARENTAL_CONTROL, BLOCKED_BY_PARENTAL_CONTROL) \
  477. XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, UNAVAILABLE_FOR_LEGAL_REASONS) \
  478. XX(460, CLIENT_CLOSED_LOAD_BALANCED_REQUEST, CLIENT_CLOSED_LOAD_BALANCED_REQUEST) \
  479. XX(463, INVALID_X_FORWARDED_FOR, INVALID_X_FORWARDED_FOR) \
  480. XX(494, REQUEST_HEADER_TOO_LARGE, REQUEST_HEADER_TOO_LARGE) \
  481. XX(495, SSL_CERTIFICATE_ERROR, SSL_CERTIFICATE_ERROR) \
  482. XX(496, SSL_CERTIFICATE_REQUIRED, SSL_CERTIFICATE_REQUIRED) \
  483. XX(497, HTTP_REQUEST_SENT_TO_HTTPS_PORT, HTTP_REQUEST_SENT_TO_HTTPS_PORT) \
  484. XX(498, INVALID_TOKEN, INVALID_TOKEN) \
  485. XX(499, CLIENT_CLOSED_REQUEST, CLIENT_CLOSED_REQUEST) \
  486. XX(500, INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR) \
  487. XX(501, NOT_IMPLEMENTED, NOT_IMPLEMENTED) \
  488. XX(502, BAD_GATEWAY, BAD_GATEWAY) \
  489. XX(503, SERVICE_UNAVAILABLE, SERVICE_UNAVAILABLE) \
  490. XX(504, GATEWAY_TIMEOUT, GATEWAY_TIMEOUT) \
  491. XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP_VERSION_NOT_SUPPORTED) \
  492. XX(506, VARIANT_ALSO_NEGOTIATES, VARIANT_ALSO_NEGOTIATES) \
  493. XX(507, INSUFFICIENT_STORAGE, INSUFFICIENT_STORAGE) \
  494. XX(508, LOOP_DETECTED, LOOP_DETECTED) \
  495. XX(509, BANDWIDTH_LIMIT_EXCEEDED, BANDWIDTH_LIMIT_EXCEEDED) \
  496. XX(510, NOT_EXTENDED, NOT_EXTENDED) \
  497. XX(511, NETWORK_AUTHENTICATION_REQUIRED, NETWORK_AUTHENTICATION_REQUIRED) \
  498. XX(520, WEB_SERVER_UNKNOWN_ERROR, WEB_SERVER_UNKNOWN_ERROR) \
  499. XX(521, WEB_SERVER_IS_DOWN, WEB_SERVER_IS_DOWN) \
  500. XX(522, CONNECTION_TIMEOUT, CONNECTION_TIMEOUT) \
  501. XX(523, ORIGIN_IS_UNREACHABLE, ORIGIN_IS_UNREACHABLE) \
  502. XX(524, TIMEOUT_OCCURED, TIMEOUT_OCCURED) \
  503. XX(525, SSL_HANDSHAKE_FAILED, SSL_HANDSHAKE_FAILED) \
  504. XX(526, INVALID_SSL_CERTIFICATE, INVALID_SSL_CERTIFICATE) \
  505. XX(527, RAILGUN_ERROR, RAILGUN_ERROR) \
  506. XX(529, SITE_IS_OVERLOADED, SITE_IS_OVERLOADED) \
  507. XX(530, SITE_IS_FROZEN, SITE_IS_FROZEN) \
  508. XX(561, IDENTITY_PROVIDER_AUTHENTICATION_ERROR, IDENTITY_PROVIDER_AUTHENTICATION_ERROR) \
  509. XX(598, NETWORK_READ_TIMEOUT, NETWORK_READ_TIMEOUT) \
  510. XX(599, NETWORK_CONNECT_TIMEOUT, NETWORK_CONNECT_TIMEOUT) \
  511. #ifdef __cplusplus
  512. } /* extern "C" */
  513. #endif
  514. #endif /* LLLLHTTP_C_HEADERS_ */
  515. #ifndef INCLUDE_LLHTTP_API_H_
  516. #define INCLUDE_LLHTTP_API_H_
  517. #ifdef __cplusplus
  518. extern "C" {
  519. #endif
  520. #include <stddef.h>
  521. #if defined(__wasm__)
  522. #define LLHTTP_EXPORT __attribute__((visibility("default")))
  523. #elif defined(_WIN32)
  524. #define LLHTTP_EXPORT __declspec(dllexport)
  525. #else
  526. #define LLHTTP_EXPORT
  527. #endif
  528. typedef llhttp__internal_t llhttp_t;
  529. typedef struct llhttp_settings_s llhttp_settings_t;
  530. typedef int (*llhttp_data_cb)(llhttp_t*, const char *at, size_t length);
  531. typedef int (*llhttp_cb)(llhttp_t*);
  532. struct llhttp_settings_s {
  533. /* Possible return values 0, -1, `HPE_PAUSED` */
  534. llhttp_cb on_message_begin;
  535. /* Possible return values 0, -1, HPE_USER */
  536. llhttp_data_cb on_url;
  537. llhttp_data_cb on_status;
  538. llhttp_data_cb on_method;
  539. llhttp_data_cb on_version;
  540. llhttp_data_cb on_header_field;
  541. llhttp_data_cb on_header_value;
  542. llhttp_data_cb on_chunk_extension_name;
  543. llhttp_data_cb on_chunk_extension_value;
  544. /* Possible return values:
  545. * 0 - Proceed normally
  546. * 1 - Assume that request/response has no body, and proceed to parsing the
  547. * next message
  548. * 2 - Assume absence of body (as above) and make `llhttp_execute()` return
  549. * `HPE_PAUSED_UPGRADE`
  550. * -1 - Error
  551. * `HPE_PAUSED`
  552. */
  553. llhttp_cb on_headers_complete;
  554. /* Possible return values 0, -1, HPE_USER */
  555. llhttp_data_cb on_body;
  556. /* Possible return values 0, -1, `HPE_PAUSED` */
  557. llhttp_cb on_message_complete;
  558. llhttp_cb on_url_complete;
  559. llhttp_cb on_status_complete;
  560. llhttp_cb on_method_complete;
  561. llhttp_cb on_version_complete;
  562. llhttp_cb on_header_field_complete;
  563. llhttp_cb on_header_value_complete;
  564. llhttp_cb on_chunk_extension_name_complete;
  565. llhttp_cb on_chunk_extension_value_complete;
  566. /* When on_chunk_header is called, the current chunk length is stored
  567. * in parser->content_length.
  568. * Possible return values 0, -1, `HPE_PAUSED`
  569. */
  570. llhttp_cb on_chunk_header;
  571. llhttp_cb on_chunk_complete;
  572. llhttp_cb on_reset;
  573. };
  574. /* Initialize the parser with specific type and user settings.
  575. *
  576. * NOTE: lifetime of `settings` has to be at least the same as the lifetime of
  577. * the `parser` here. In practice, `settings` has to be either a static
  578. * variable or be allocated with `malloc`, `new`, etc.
  579. */
  580. LLHTTP_EXPORT
  581. void llhttp_init(llhttp_t* parser, llhttp_type_t type,
  582. const llhttp_settings_t* settings);
  583. LLHTTP_EXPORT
  584. llhttp_t* llhttp_alloc(llhttp_type_t type);
  585. LLHTTP_EXPORT
  586. void llhttp_free(llhttp_t* parser);
  587. LLHTTP_EXPORT
  588. uint8_t llhttp_get_type(llhttp_t* parser);
  589. LLHTTP_EXPORT
  590. uint8_t llhttp_get_http_major(llhttp_t* parser);
  591. LLHTTP_EXPORT
  592. uint8_t llhttp_get_http_minor(llhttp_t* parser);
  593. LLHTTP_EXPORT
  594. uint8_t llhttp_get_method(llhttp_t* parser);
  595. LLHTTP_EXPORT
  596. int llhttp_get_status_code(llhttp_t* parser);
  597. LLHTTP_EXPORT
  598. uint8_t llhttp_get_upgrade(llhttp_t* parser);
  599. /* Reset an already initialized parser back to the start state, preserving the
  600. * existing parser type, callback settings, user data, and lenient flags.
  601. */
  602. LLHTTP_EXPORT
  603. void llhttp_reset(llhttp_t* parser);
  604. /* Initialize the settings object */
  605. LLHTTP_EXPORT
  606. void llhttp_settings_init(llhttp_settings_t* settings);
  607. /* Parse full or partial request/response, invoking user callbacks along the
  608. * way.
  609. *
  610. * If any of `llhttp_data_cb` returns errno not equal to `HPE_OK` - the parsing
  611. * interrupts, and such errno is returned from `llhttp_execute()`. If
  612. * `HPE_PAUSED` was used as a errno, the execution can be resumed with
  613. * `llhttp_resume()` call.
  614. *
  615. * In a special case of CONNECT/Upgrade request/response `HPE_PAUSED_UPGRADE`
  616. * is returned after fully parsing the request/response. If the user wishes to
  617. * continue parsing, they need to invoke `llhttp_resume_after_upgrade()`.
  618. *
  619. * NOTE: if this function ever returns a non-pause type error, it will continue
  620. * to return the same error upon each successive call up until `llhttp_init()`
  621. * is called.
  622. */
  623. LLHTTP_EXPORT
  624. llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
  625. /* This method should be called when the other side has no further bytes to
  626. * send (e.g. shutdown of readable side of the TCP connection.)
  627. *
  628. * Requests without `Content-Length` and other messages might require treating
  629. * all incoming bytes as the part of the body, up to the last byte of the
  630. * connection. This method will invoke `on_message_complete()` callback if the
  631. * request was terminated safely. Otherwise a error code would be returned.
  632. */
  633. LLHTTP_EXPORT
  634. llhttp_errno_t llhttp_finish(llhttp_t* parser);
  635. /* Returns `1` if the incoming message is parsed until the last byte, and has
  636. * to be completed by calling `llhttp_finish()` on EOF
  637. */
  638. LLHTTP_EXPORT
  639. int llhttp_message_needs_eof(const llhttp_t* parser);
  640. /* Returns `1` if there might be any other messages following the last that was
  641. * successfully parsed.
  642. */
  643. LLHTTP_EXPORT
  644. int llhttp_should_keep_alive(const llhttp_t* parser);
  645. /* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set
  646. * appropriate error reason.
  647. *
  648. * Important: do not call this from user callbacks! User callbacks must return
  649. * `HPE_PAUSED` if pausing is required.
  650. */
  651. LLHTTP_EXPORT
  652. void llhttp_pause(llhttp_t* parser);
  653. /* Might be called to resume the execution after the pause in user's callback.
  654. * See `llhttp_execute()` above for details.
  655. *
  656. * Call this only if `llhttp_execute()` returns `HPE_PAUSED`.
  657. */
  658. LLHTTP_EXPORT
  659. void llhttp_resume(llhttp_t* parser);
  660. /* Might be called to resume the execution after the pause in user's callback.
  661. * See `llhttp_execute()` above for details.
  662. *
  663. * Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE`
  664. */
  665. LLHTTP_EXPORT
  666. void llhttp_resume_after_upgrade(llhttp_t* parser);
  667. /* Returns the latest return error */
  668. LLHTTP_EXPORT
  669. llhttp_errno_t llhttp_get_errno(const llhttp_t* parser);
  670. /* Returns the verbal explanation of the latest returned error.
  671. *
  672. * Note: User callback should set error reason when returning the error. See
  673. * `llhttp_set_error_reason()` for details.
  674. */
  675. LLHTTP_EXPORT
  676. const char* llhttp_get_error_reason(const llhttp_t* parser);
  677. /* Assign verbal description to the returned error. Must be called in user
  678. * callbacks right before returning the errno.
  679. *
  680. * Note: `HPE_USER` error code might be useful in user callbacks.
  681. */
  682. LLHTTP_EXPORT
  683. void llhttp_set_error_reason(llhttp_t* parser, const char* reason);
  684. /* Returns the pointer to the last parsed byte before the returned error. The
  685. * pointer is relative to the `data` argument of `llhttp_execute()`.
  686. *
  687. * Note: this method might be useful for counting the number of parsed bytes.
  688. */
  689. LLHTTP_EXPORT
  690. const char* llhttp_get_error_pos(const llhttp_t* parser);
  691. /* Returns textual name of error code */
  692. LLHTTP_EXPORT
  693. const char* llhttp_errno_name(llhttp_errno_t err);
  694. /* Returns textual name of HTTP method */
  695. LLHTTP_EXPORT
  696. const char* llhttp_method_name(llhttp_method_t method);
  697. /* Returns textual name of HTTP status */
  698. LLHTTP_EXPORT
  699. const char* llhttp_status_name(llhttp_status_t status);
  700. /* Enables/disables lenient header value parsing (disabled by default).
  701. *
  702. * Lenient parsing disables header value token checks, extending llhttp's
  703. * protocol support to highly non-compliant clients/server. No
  704. * `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when
  705. * lenient parsing is "on".
  706. *
  707. * **Enabling this flag can pose a security issue since you will be exposed to
  708. * request smuggling attacks. USE WITH CAUTION!**
  709. */
  710. LLHTTP_EXPORT
  711. void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
  712. /* Enables/disables lenient handling of conflicting `Transfer-Encoding` and
  713. * `Content-Length` headers (disabled by default).
  714. *
  715. * Normally `llhttp` would error when `Transfer-Encoding` is present in
  716. * conjunction with `Content-Length`. This error is important to prevent HTTP
  717. * request smuggling, but may be less desirable for small number of cases
  718. * involving legacy servers.
  719. *
  720. * **Enabling this flag can pose a security issue since you will be exposed to
  721. * request smuggling attacks. USE WITH CAUTION!**
  722. */
  723. LLHTTP_EXPORT
  724. void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
  725. /* Enables/disables lenient handling of `Connection: close` and HTTP/1.0
  726. * requests responses.
  727. *
  728. * Normally `llhttp` would error on (in strict mode) or discard (in loose mode)
  729. * the HTTP request/response after the request/response with `Connection: close`
  730. * and `Content-Length`. This is important to prevent cache poisoning attacks,
  731. * but might interact badly with outdated and insecure clients. With this flag
  732. * the extra request/response will be parsed normally.
  733. *
  734. * **Enabling this flag can pose a security issue since you will be exposed to
  735. * poisoning attacks. USE WITH CAUTION!**
  736. */
  737. LLHTTP_EXPORT
  738. void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled);
  739. /* Enables/disables lenient handling of `Transfer-Encoding` header.
  740. *
  741. * Normally `llhttp` would error when a `Transfer-Encoding` has `chunked` value
  742. * and another value after it (either in a single header or in multiple
  743. * headers whose value are internally joined using `, `).
  744. * This is mandated by the spec to reliably determine request body size and thus
  745. * avoid request smuggling.
  746. * With this flag the extra value will be parsed normally.
  747. *
  748. * **Enabling this flag can pose a security issue since you will be exposed to
  749. * request smuggling attacks. USE WITH CAUTION!**
  750. */
  751. LLHTTP_EXPORT
  752. void llhttp_set_lenient_transfer_encoding(llhttp_t* parser, int enabled);
  753. /* Enables/disables lenient handling of HTTP version.
  754. *
  755. * Normally `llhttp` would error when the HTTP version in the request or status line
  756. * is not `0.9`, `1.0`, `1.1` or `2.0`.
  757. * With this flag the invalid value will be parsed normally.
  758. *
  759. * **Enabling this flag can pose a security issue since you will allow unsupported
  760. * HTTP versions. USE WITH CAUTION!**
  761. */
  762. LLHTTP_EXPORT
  763. void llhttp_set_lenient_version(llhttp_t* parser, int enabled);
  764. /* Enables/disables lenient handling of additional data received after a message ends
  765. * and keep-alive is disabled.
  766. *
  767. * Normally `llhttp` would error when additional unexpected data is received if the message
  768. * contains the `Connection` header with `close` value.
  769. * With this flag the extra data will discarded without throwing an error.
  770. *
  771. * **Enabling this flag can pose a security issue since you will be exposed to
  772. * poisoning attacks. USE WITH CAUTION!**
  773. */
  774. LLHTTP_EXPORT
  775. void llhttp_set_lenient_data_after_close(llhttp_t* parser, int enabled);
  776. /* Enables/disables lenient handling of incomplete CRLF sequences.
  777. *
  778. * Normally `llhttp` would error when a CR is not followed by LF when terminating the
  779. * request line, the status line, the headers or a chunk header.
  780. * With this flag only a CR is required to terminate such sections.
  781. *
  782. * **Enabling this flag can pose a security issue since you will be exposed to
  783. * request smuggling attacks. USE WITH CAUTION!**
  784. */
  785. LLHTTP_EXPORT
  786. void llhttp_set_lenient_optional_lf_after_cr(llhttp_t* parser, int enabled);
  787. /*
  788. * Enables/disables lenient handling of line separators.
  789. *
  790. * Normally `llhttp` would error when a LF is not preceded by CR when terminating the
  791. * request line, the status line, the headers, a chunk header or a chunk data.
  792. * With this flag only a LF is required to terminate such sections.
  793. *
  794. * **Enabling this flag can pose a security issue since you will be exposed to
  795. * request smuggling attacks. USE WITH CAUTION!**
  796. */
  797. LLHTTP_EXPORT
  798. void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled);
  799. /* Enables/disables lenient handling of chunks not separated via CRLF.
  800. *
  801. * Normally `llhttp` would error when after a chunk data a CRLF is missing before
  802. * starting a new chunk.
  803. * With this flag the new chunk can start immediately after the previous one.
  804. *
  805. * **Enabling this flag can pose a security issue since you will be exposed to
  806. * request smuggling attacks. USE WITH CAUTION!**
  807. */
  808. LLHTTP_EXPORT
  809. void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled);
  810. /* Enables/disables lenient handling of spaces after chunk size.
  811. *
  812. * Normally `llhttp` would error when after a chunk size is followed by one or more
  813. * spaces are present instead of a CRLF or `;`.
  814. * With this flag this check is disabled.
  815. *
  816. * **Enabling this flag can pose a security issue since you will be exposed to
  817. * request smuggling attacks. USE WITH CAUTION!**
  818. */
  819. LLHTTP_EXPORT
  820. void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled);
  821. #ifdef __cplusplus
  822. } /* extern "C" */
  823. #endif
  824. #endif /* INCLUDE_LLHTTP_API_H_ */
  825. #endif /* INCLUDE_LLHTTP_H_ */