protocol-quic 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (343) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/ngtcp2/AUTHORS +44 -0
  4. data/ext/ngtcp2/CMakeLists.txt +431 -0
  5. data/ext/ngtcp2/CMakeOptions.txt +17 -0
  6. data/ext/ngtcp2/COPYING +22 -0
  7. data/ext/ngtcp2/ChangeLog +0 -0
  8. data/ext/ngtcp2/Makefile.am +60 -0
  9. data/ext/ngtcp2/NEWS +0 -0
  10. data/ext/ngtcp2/README +1 -0
  11. data/ext/ngtcp2/README.rst +258 -0
  12. data/ext/ngtcp2/ci/build_boringssl.sh +10 -0
  13. data/ext/ngtcp2/ci/build_nghttp3.sh +9 -0
  14. data/ext/ngtcp2/ci/build_openssl1.sh +8 -0
  15. data/ext/ngtcp2/ci/build_openssl1_cross.sh +9 -0
  16. data/ext/ngtcp2/ci/build_openssl3.sh +8 -0
  17. data/ext/ngtcp2/ci/build_picotls.sh +26 -0
  18. data/ext/ngtcp2/ci/build_wolfssl.sh +9 -0
  19. data/ext/ngtcp2/ci/gen-certificate.sh +8 -0
  20. data/ext/ngtcp2/cmake/ExtractValidFlags.cmake +31 -0
  21. data/ext/ngtcp2/cmake/FindCUnit.cmake +40 -0
  22. data/ext/ngtcp2/cmake/FindJemalloc.cmake +40 -0
  23. data/ext/ngtcp2/cmake/FindLibev.cmake +38 -0
  24. data/ext/ngtcp2/cmake/FindLibnghttp3.cmake +41 -0
  25. data/ext/ngtcp2/cmake/Findwolfssl.cmake +41 -0
  26. data/ext/ngtcp2/cmake/Version.cmake +11 -0
  27. data/ext/ngtcp2/cmakeconfig.h.in +36 -0
  28. data/ext/ngtcp2/configure.ac +755 -0
  29. data/ext/ngtcp2/crypto/CMakeLists.txt +56 -0
  30. data/ext/ngtcp2/crypto/Makefile.am +49 -0
  31. data/ext/ngtcp2/crypto/boringssl/CMakeLists.txt +64 -0
  32. data/ext/ngtcp2/crypto/boringssl/Makefile.am +39 -0
  33. data/ext/ngtcp2/crypto/boringssl/boringssl.c +630 -0
  34. data/ext/ngtcp2/crypto/boringssl/libngtcp2_crypto_boringssl.pc.in +33 -0
  35. data/ext/ngtcp2/crypto/gnutls/CMakeLists.txt +86 -0
  36. data/ext/ngtcp2/crypto/gnutls/Makefile.am +43 -0
  37. data/ext/ngtcp2/crypto/gnutls/gnutls.c +644 -0
  38. data/ext/ngtcp2/crypto/gnutls/libngtcp2_crypto_gnutls.pc.in +33 -0
  39. data/ext/ngtcp2/crypto/includes/CMakeLists.txt +56 -0
  40. data/ext/ngtcp2/crypto/includes/Makefile.am +45 -0
  41. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto.h +893 -0
  42. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_boringssl.h +104 -0
  43. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_gnutls.h +107 -0
  44. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h +132 -0
  45. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_picotls.h +246 -0
  46. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_wolfssl.h +106 -0
  47. data/ext/ngtcp2/crypto/openssl/CMakeLists.txt +86 -0
  48. data/ext/ngtcp2/crypto/openssl/Makefile.am +43 -0
  49. data/ext/ngtcp2/crypto/openssl/libngtcp2_crypto_openssl.pc.in +33 -0
  50. data/ext/ngtcp2/crypto/openssl/openssl.c +807 -0
  51. data/ext/ngtcp2/crypto/picotls/CMakeLists.txt +65 -0
  52. data/ext/ngtcp2/crypto/picotls/Makefile.am +39 -0
  53. data/ext/ngtcp2/crypto/picotls/libngtcp2_crypto_picotls.pc.in +33 -0
  54. data/ext/ngtcp2/crypto/picotls/picotls.c +707 -0
  55. data/ext/ngtcp2/crypto/shared.c +1431 -0
  56. data/ext/ngtcp2/crypto/shared.h +350 -0
  57. data/ext/ngtcp2/crypto/wolfssl/CMakeLists.txt +84 -0
  58. data/ext/ngtcp2/crypto/wolfssl/Makefile.am +43 -0
  59. data/ext/ngtcp2/crypto/wolfssl/libngtcp2_crypto_wolfssl.pc.in +33 -0
  60. data/ext/ngtcp2/crypto/wolfssl/wolfssl.c +534 -0
  61. data/ext/ngtcp2/doc/Makefile.am +65 -0
  62. data/ext/ngtcp2/doc/make.bat +35 -0
  63. data/ext/ngtcp2/doc/mkapiref.py +356 -0
  64. data/ext/ngtcp2/doc/source/conf.py.in +94 -0
  65. data/ext/ngtcp2/doc/source/index.rst +22 -0
  66. data/ext/ngtcp2/doc/source/programmers-guide.rst +476 -0
  67. data/ext/ngtcp2/docker/Dockerfile +39 -0
  68. data/ext/ngtcp2/examples/CMakeLists.txt +361 -0
  69. data/ext/ngtcp2/examples/Makefile.am +228 -0
  70. data/ext/ngtcp2/examples/client.cc +3049 -0
  71. data/ext/ngtcp2/examples/client.h +192 -0
  72. data/ext/ngtcp2/examples/client_base.cc +202 -0
  73. data/ext/ngtcp2/examples/client_base.h +213 -0
  74. data/ext/ngtcp2/examples/debug.cc +298 -0
  75. data/ext/ngtcp2/examples/debug.h +124 -0
  76. data/ext/ngtcp2/examples/examplestest.cc +84 -0
  77. data/ext/ngtcp2/examples/gtlssimpleclient.c +720 -0
  78. data/ext/ngtcp2/examples/h09client.cc +2601 -0
  79. data/ext/ngtcp2/examples/h09client.h +196 -0
  80. data/ext/ngtcp2/examples/h09server.cc +3024 -0
  81. data/ext/ngtcp2/examples/h09server.h +237 -0
  82. data/ext/ngtcp2/examples/http.cc +138 -0
  83. data/ext/ngtcp2/examples/http.h +44 -0
  84. data/ext/ngtcp2/examples/network.h +80 -0
  85. data/ext/ngtcp2/examples/server.cc +3731 -0
  86. data/ext/ngtcp2/examples/server.h +256 -0
  87. data/ext/ngtcp2/examples/server_base.cc +58 -0
  88. data/ext/ngtcp2/examples/server_base.h +195 -0
  89. data/ext/ngtcp2/examples/shared.cc +385 -0
  90. data/ext/ngtcp2/examples/shared.h +96 -0
  91. data/ext/ngtcp2/examples/simpleclient.c +683 -0
  92. data/ext/ngtcp2/examples/template.h +71 -0
  93. data/ext/ngtcp2/examples/tests/README.rst +60 -0
  94. data/ext/ngtcp2/examples/tests/__init__.py +0 -0
  95. data/ext/ngtcp2/examples/tests/config.ini.in +32 -0
  96. data/ext/ngtcp2/examples/tests/conftest.py +28 -0
  97. data/ext/ngtcp2/examples/tests/ngtcp2test/__init__.py +6 -0
  98. data/ext/ngtcp2/examples/tests/ngtcp2test/certs.py +476 -0
  99. data/ext/ngtcp2/examples/tests/ngtcp2test/client.py +187 -0
  100. data/ext/ngtcp2/examples/tests/ngtcp2test/env.py +191 -0
  101. data/ext/ngtcp2/examples/tests/ngtcp2test/log.py +101 -0
  102. data/ext/ngtcp2/examples/tests/ngtcp2test/server.py +137 -0
  103. data/ext/ngtcp2/examples/tests/ngtcp2test/tls.py +983 -0
  104. data/ext/ngtcp2/examples/tests/test_01_handshake.py +30 -0
  105. data/ext/ngtcp2/examples/tests/test_02_resume.py +46 -0
  106. data/ext/ngtcp2/examples/tests/test_03_earlydata.py +56 -0
  107. data/ext/ngtcp2/examples/tests/test_04_clientcert.py +57 -0
  108. data/ext/ngtcp2/examples/tests/test_05_ciphers.py +46 -0
  109. data/ext/ngtcp2/examples/tls_client_context.h +52 -0
  110. data/ext/ngtcp2/examples/tls_client_context_boringssl.cc +126 -0
  111. data/ext/ngtcp2/examples/tls_client_context_boringssl.h +49 -0
  112. data/ext/ngtcp2/examples/tls_client_context_gnutls.cc +74 -0
  113. data/ext/ngtcp2/examples/tls_client_context_gnutls.h +50 -0
  114. data/ext/ngtcp2/examples/tls_client_context_openssl.cc +137 -0
  115. data/ext/ngtcp2/examples/tls_client_context_openssl.h +49 -0
  116. data/ext/ngtcp2/examples/tls_client_context_picotls.cc +158 -0
  117. data/ext/ngtcp2/examples/tls_client_context_picotls.h +53 -0
  118. data/ext/ngtcp2/examples/tls_client_context_wolfssl.cc +177 -0
  119. data/ext/ngtcp2/examples/tls_client_context_wolfssl.h +51 -0
  120. data/ext/ngtcp2/examples/tls_client_session.h +52 -0
  121. data/ext/ngtcp2/examples/tls_client_session_boringssl.cc +110 -0
  122. data/ext/ngtcp2/examples/tls_client_session_boringssl.h +52 -0
  123. data/ext/ngtcp2/examples/tls_client_session_gnutls.cc +190 -0
  124. data/ext/ngtcp2/examples/tls_client_session_gnutls.h +52 -0
  125. data/ext/ngtcp2/examples/tls_client_session_openssl.cc +113 -0
  126. data/ext/ngtcp2/examples/tls_client_session_openssl.h +52 -0
  127. data/ext/ngtcp2/examples/tls_client_session_picotls.cc +147 -0
  128. data/ext/ngtcp2/examples/tls_client_session_picotls.h +52 -0
  129. data/ext/ngtcp2/examples/tls_client_session_wolfssl.cc +160 -0
  130. data/ext/ngtcp2/examples/tls_client_session_wolfssl.h +52 -0
  131. data/ext/ngtcp2/examples/tls_server_context.h +52 -0
  132. data/ext/ngtcp2/examples/tls_server_context_boringssl.cc +257 -0
  133. data/ext/ngtcp2/examples/tls_server_context_boringssl.h +54 -0
  134. data/ext/ngtcp2/examples/tls_server_context_gnutls.cc +99 -0
  135. data/ext/ngtcp2/examples/tls_server_context_gnutls.h +59 -0
  136. data/ext/ngtcp2/examples/tls_server_context_openssl.cc +338 -0
  137. data/ext/ngtcp2/examples/tls_server_context_openssl.h +54 -0
  138. data/ext/ngtcp2/examples/tls_server_context_picotls.cc +321 -0
  139. data/ext/ngtcp2/examples/tls_server_context_picotls.h +58 -0
  140. data/ext/ngtcp2/examples/tls_server_context_wolfssl.cc +284 -0
  141. data/ext/ngtcp2/examples/tls_server_context_wolfssl.h +55 -0
  142. data/ext/ngtcp2/examples/tls_server_session.h +52 -0
  143. data/ext/ngtcp2/examples/tls_server_session_boringssl.cc +84 -0
  144. data/ext/ngtcp2/examples/tls_server_session_boringssl.h +47 -0
  145. data/ext/ngtcp2/examples/tls_server_session_gnutls.cc +155 -0
  146. data/ext/ngtcp2/examples/tls_server_session_gnutls.h +46 -0
  147. data/ext/ngtcp2/examples/tls_server_session_openssl.cc +54 -0
  148. data/ext/ngtcp2/examples/tls_server_session_openssl.h +47 -0
  149. data/ext/ngtcp2/examples/tls_server_session_picotls.cc +70 -0
  150. data/ext/ngtcp2/examples/tls_server_session_picotls.h +47 -0
  151. data/ext/ngtcp2/examples/tls_server_session_wolfssl.cc +55 -0
  152. data/ext/ngtcp2/examples/tls_server_session_wolfssl.h +47 -0
  153. data/ext/ngtcp2/examples/tls_session_base_gnutls.cc +87 -0
  154. data/ext/ngtcp2/examples/tls_session_base_gnutls.h +51 -0
  155. data/ext/ngtcp2/examples/tls_session_base_openssl.cc +54 -0
  156. data/ext/ngtcp2/examples/tls_session_base_openssl.h +52 -0
  157. data/ext/ngtcp2/examples/tls_session_base_picotls.cc +56 -0
  158. data/ext/ngtcp2/examples/tls_session_base_picotls.h +54 -0
  159. data/ext/ngtcp2/examples/tls_session_base_wolfssl.cc +54 -0
  160. data/ext/ngtcp2/examples/tls_session_base_wolfssl.h +54 -0
  161. data/ext/ngtcp2/examples/tls_shared_picotls.cc +59 -0
  162. data/ext/ngtcp2/examples/tls_shared_picotls.h +36 -0
  163. data/ext/ngtcp2/examples/util.cc +646 -0
  164. data/ext/ngtcp2/examples/util.h +361 -0
  165. data/ext/ngtcp2/examples/util_gnutls.cc +136 -0
  166. data/ext/ngtcp2/examples/util_openssl.cc +131 -0
  167. data/ext/ngtcp2/examples/util_test.cc +237 -0
  168. data/ext/ngtcp2/examples/util_test.h +45 -0
  169. data/ext/ngtcp2/examples/util_wolfssl.cc +130 -0
  170. data/ext/ngtcp2/fuzz/corpus/decode_frame/ack +0 -0
  171. data/ext/ngtcp2/fuzz/corpus/decode_frame/ack_ecn +0 -0
  172. data/ext/ngtcp2/fuzz/corpus/decode_frame/connection_close +0 -0
  173. data/ext/ngtcp2/fuzz/corpus/decode_frame/crypto +1 -0
  174. data/ext/ngtcp2/fuzz/corpus/decode_frame/data_blocked +1 -0
  175. data/ext/ngtcp2/fuzz/corpus/decode_frame/datagram +1 -0
  176. data/ext/ngtcp2/fuzz/corpus/decode_frame/datagram_len +1 -0
  177. data/ext/ngtcp2/fuzz/corpus/decode_frame/max_data +1 -0
  178. data/ext/ngtcp2/fuzz/corpus/decode_frame/max_stream_data +0 -0
  179. data/ext/ngtcp2/fuzz/corpus/decode_frame/max_streams +0 -0
  180. data/ext/ngtcp2/fuzz/corpus/decode_frame/new_connection_id +1 -0
  181. data/ext/ngtcp2/fuzz/corpus/decode_frame/new_token +1 -0
  182. data/ext/ngtcp2/fuzz/corpus/decode_frame/path_challenge +1 -0
  183. data/ext/ngtcp2/fuzz/corpus/decode_frame/path_response +1 -0
  184. data/ext/ngtcp2/fuzz/corpus/decode_frame/reset_stream +0 -0
  185. data/ext/ngtcp2/fuzz/corpus/decode_frame/retire_connection_id +1 -0
  186. data/ext/ngtcp2/fuzz/corpus/decode_frame/stop_sending +0 -0
  187. data/ext/ngtcp2/fuzz/corpus/decode_frame/stream +0 -0
  188. data/ext/ngtcp2/fuzz/corpus/decode_frame/stream_data_blocked +0 -0
  189. data/ext/ngtcp2/fuzz/corpus/decode_frame/stream_len +0 -0
  190. data/ext/ngtcp2/fuzz/corpus/decode_frame/streams_blocked +0 -0
  191. data/ext/ngtcp2/fuzz/corpus/ksl/random +0 -0
  192. data/ext/ngtcp2/fuzz/decode_frame.cc +25 -0
  193. data/ext/ngtcp2/fuzz/ksl.cc +77 -0
  194. data/ext/ngtcp2/interop/Dockerfile +39 -0
  195. data/ext/ngtcp2/interop/run_endpoint.sh +93 -0
  196. data/ext/ngtcp2/lib/CMakeLists.txt +110 -0
  197. data/ext/ngtcp2/lib/Makefile.am +122 -0
  198. data/ext/ngtcp2/lib/includes/CMakeLists.txt +4 -0
  199. data/ext/ngtcp2/lib/includes/Makefile.am +25 -0
  200. data/ext/ngtcp2/lib/includes/ngtcp2/ngtcp2.h +5843 -0
  201. data/ext/ngtcp2/lib/includes/ngtcp2/version.h.in +51 -0
  202. data/ext/ngtcp2/lib/libngtcp2.pc.in +33 -0
  203. data/ext/ngtcp2/lib/ngtcp2_acktr.c +335 -0
  204. data/ext/ngtcp2/lib/ngtcp2_acktr.h +221 -0
  205. data/ext/ngtcp2/lib/ngtcp2_addr.c +117 -0
  206. data/ext/ngtcp2/lib/ngtcp2_addr.h +69 -0
  207. data/ext/ngtcp2/lib/ngtcp2_balloc.c +90 -0
  208. data/ext/ngtcp2/lib/ngtcp2_balloc.h +91 -0
  209. data/ext/ngtcp2/lib/ngtcp2_bbr.c +693 -0
  210. data/ext/ngtcp2/lib/ngtcp2_bbr.h +157 -0
  211. data/ext/ngtcp2/lib/ngtcp2_bbr2.c +1490 -0
  212. data/ext/ngtcp2/lib/ngtcp2_bbr2.h +149 -0
  213. data/ext/ngtcp2/lib/ngtcp2_buf.c +56 -0
  214. data/ext/ngtcp2/lib/ngtcp2_buf.h +108 -0
  215. data/ext/ngtcp2/lib/ngtcp2_cc.c +616 -0
  216. data/ext/ngtcp2/lib/ngtcp2_cc.h +422 -0
  217. data/ext/ngtcp2/lib/ngtcp2_cid.c +147 -0
  218. data/ext/ngtcp2/lib/ngtcp2_cid.h +175 -0
  219. data/ext/ngtcp2/lib/ngtcp2_conn.c +13731 -0
  220. data/ext/ngtcp2/lib/ngtcp2_conn.h +1119 -0
  221. data/ext/ngtcp2/lib/ngtcp2_conn_stat.h +131 -0
  222. data/ext/ngtcp2/lib/ngtcp2_conv.c +291 -0
  223. data/ext/ngtcp2/lib/ngtcp2_conv.h +208 -0
  224. data/ext/ngtcp2/lib/ngtcp2_crypto.c +895 -0
  225. data/ext/ngtcp2/lib/ngtcp2_crypto.h +148 -0
  226. data/ext/ngtcp2/lib/ngtcp2_err.c +154 -0
  227. data/ext/ngtcp2/lib/ngtcp2_err.h +34 -0
  228. data/ext/ngtcp2/lib/ngtcp2_gaptr.c +167 -0
  229. data/ext/ngtcp2/lib/ngtcp2_gaptr.h +98 -0
  230. data/ext/ngtcp2/lib/ngtcp2_idtr.c +79 -0
  231. data/ext/ngtcp2/lib/ngtcp2_idtr.h +89 -0
  232. data/ext/ngtcp2/lib/ngtcp2_ksl.c +819 -0
  233. data/ext/ngtcp2/lib/ngtcp2_ksl.h +345 -0
  234. data/ext/ngtcp2/lib/ngtcp2_log.c +822 -0
  235. data/ext/ngtcp2/lib/ngtcp2_log.h +123 -0
  236. data/ext/ngtcp2/lib/ngtcp2_macro.h +58 -0
  237. data/ext/ngtcp2/lib/ngtcp2_map.c +336 -0
  238. data/ext/ngtcp2/lib/ngtcp2_map.h +136 -0
  239. data/ext/ngtcp2/lib/ngtcp2_mem.c +113 -0
  240. data/ext/ngtcp2/lib/ngtcp2_mem.h +72 -0
  241. data/ext/ngtcp2/lib/ngtcp2_net.h +136 -0
  242. data/ext/ngtcp2/lib/ngtcp2_objalloc.c +40 -0
  243. data/ext/ngtcp2/lib/ngtcp2_objalloc.h +140 -0
  244. data/ext/ngtcp2/lib/ngtcp2_opl.c +46 -0
  245. data/ext/ngtcp2/lib/ngtcp2_opl.h +65 -0
  246. data/ext/ngtcp2/lib/ngtcp2_path.c +77 -0
  247. data/ext/ngtcp2/lib/ngtcp2_path.h +49 -0
  248. data/ext/ngtcp2/lib/ngtcp2_pkt.c +2527 -0
  249. data/ext/ngtcp2/lib/ngtcp2_pkt.h +1235 -0
  250. data/ext/ngtcp2/lib/ngtcp2_pmtud.c +160 -0
  251. data/ext/ngtcp2/lib/ngtcp2_pmtud.h +123 -0
  252. data/ext/ngtcp2/lib/ngtcp2_ppe.c +230 -0
  253. data/ext/ngtcp2/lib/ngtcp2_ppe.h +153 -0
  254. data/ext/ngtcp2/lib/ngtcp2_pq.c +164 -0
  255. data/ext/ngtcp2/lib/ngtcp2_pq.h +126 -0
  256. data/ext/ngtcp2/lib/ngtcp2_pv.c +172 -0
  257. data/ext/ngtcp2/lib/ngtcp2_pv.h +194 -0
  258. data/ext/ngtcp2/lib/ngtcp2_qlog.c +1219 -0
  259. data/ext/ngtcp2/lib/ngtcp2_qlog.h +161 -0
  260. data/ext/ngtcp2/lib/ngtcp2_range.c +61 -0
  261. data/ext/ngtcp2/lib/ngtcp2_range.h +80 -0
  262. data/ext/ngtcp2/lib/ngtcp2_rcvry.h +40 -0
  263. data/ext/ngtcp2/lib/ngtcp2_ringbuf.c +121 -0
  264. data/ext/ngtcp2/lib/ngtcp2_ringbuf.h +132 -0
  265. data/ext/ngtcp2/lib/ngtcp2_rob.c +319 -0
  266. data/ext/ngtcp2/lib/ngtcp2_rob.h +197 -0
  267. data/ext/ngtcp2/lib/ngtcp2_rst.c +138 -0
  268. data/ext/ngtcp2/lib/ngtcp2_rst.h +86 -0
  269. data/ext/ngtcp2/lib/ngtcp2_rtb.c +1676 -0
  270. data/ext/ngtcp2/lib/ngtcp2_rtb.h +468 -0
  271. data/ext/ngtcp2/lib/ngtcp2_str.c +233 -0
  272. data/ext/ngtcp2/lib/ngtcp2_str.h +94 -0
  273. data/ext/ngtcp2/lib/ngtcp2_strm.c +698 -0
  274. data/ext/ngtcp2/lib/ngtcp2_strm.h +310 -0
  275. data/ext/ngtcp2/lib/ngtcp2_unreachable.c +71 -0
  276. data/ext/ngtcp2/lib/ngtcp2_unreachable.h +46 -0
  277. data/ext/ngtcp2/lib/ngtcp2_vec.c +243 -0
  278. data/ext/ngtcp2/lib/ngtcp2_vec.h +120 -0
  279. data/ext/ngtcp2/lib/ngtcp2_version.c +39 -0
  280. data/ext/ngtcp2/lib/ngtcp2_window_filter.c +99 -0
  281. data/ext/ngtcp2/lib/ngtcp2_window_filter.h +65 -0
  282. data/ext/ngtcp2/m4/ax_check_compile_flag.m4 +74 -0
  283. data/ext/ngtcp2/m4/ax_cxx_compile_stdcxx.m4 +1009 -0
  284. data/ext/ngtcp2/tests/CMakeLists.txt +68 -0
  285. data/ext/ngtcp2/tests/Makefile.am +94 -0
  286. data/ext/ngtcp2/tests/main.c +358 -0
  287. data/ext/ngtcp2/tests/ngtcp2_acktr_test.c +367 -0
  288. data/ext/ngtcp2/tests/ngtcp2_acktr_test.h +37 -0
  289. data/ext/ngtcp2/tests/ngtcp2_conn_test.c +9821 -0
  290. data/ext/ngtcp2/tests/ngtcp2_conn_test.h +104 -0
  291. data/ext/ngtcp2/tests/ngtcp2_conv_test.c +430 -0
  292. data/ext/ngtcp2/tests/ngtcp2_conv_test.h +46 -0
  293. data/ext/ngtcp2/tests/ngtcp2_crypto_test.c +667 -0
  294. data/ext/ngtcp2/tests/ngtcp2_crypto_test.h +35 -0
  295. data/ext/ngtcp2/tests/ngtcp2_gaptr_test.c +127 -0
  296. data/ext/ngtcp2/tests/ngtcp2_gaptr_test.h +36 -0
  297. data/ext/ngtcp2/tests/ngtcp2_idtr_test.c +79 -0
  298. data/ext/ngtcp2/tests/ngtcp2_idtr_test.h +34 -0
  299. data/ext/ngtcp2/tests/ngtcp2_ksl_test.c +502 -0
  300. data/ext/ngtcp2/tests/ngtcp2_ksl_test.h +39 -0
  301. data/ext/ngtcp2/tests/ngtcp2_map_test.c +206 -0
  302. data/ext/ngtcp2/tests/ngtcp2_map_test.h +38 -0
  303. data/ext/ngtcp2/tests/ngtcp2_pkt_test.c +1645 -0
  304. data/ext/ngtcp2/tests/ngtcp2_pkt_test.h +68 -0
  305. data/ext/ngtcp2/tests/ngtcp2_pmtud_test.c +153 -0
  306. data/ext/ngtcp2/tests/ngtcp2_pmtud_test.h +34 -0
  307. data/ext/ngtcp2/tests/ngtcp2_pv_test.c +129 -0
  308. data/ext/ngtcp2/tests/ngtcp2_pv_test.h +35 -0
  309. data/ext/ngtcp2/tests/ngtcp2_range_test.c +105 -0
  310. data/ext/ngtcp2/tests/ngtcp2_range_test.h +36 -0
  311. data/ext/ngtcp2/tests/ngtcp2_ringbuf_test.c +91 -0
  312. data/ext/ngtcp2/tests/ngtcp2_ringbuf_test.h +35 -0
  313. data/ext/ngtcp2/tests/ngtcp2_rob_test.c +552 -0
  314. data/ext/ngtcp2/tests/ngtcp2_rob_test.h +37 -0
  315. data/ext/ngtcp2/tests/ngtcp2_rtb_test.c +470 -0
  316. data/ext/ngtcp2/tests/ngtcp2_rtb_test.h +38 -0
  317. data/ext/ngtcp2/tests/ngtcp2_str_test.c +96 -0
  318. data/ext/ngtcp2/tests/ngtcp2_str_test.h +36 -0
  319. data/ext/ngtcp2/tests/ngtcp2_strm_test.c +575 -0
  320. data/ext/ngtcp2/tests/ngtcp2_strm_test.h +36 -0
  321. data/ext/ngtcp2/tests/ngtcp2_test_helper.c +404 -0
  322. data/ext/ngtcp2/tests/ngtcp2_test_helper.h +191 -0
  323. data/ext/ngtcp2/tests/ngtcp2_vec_test.c +426 -0
  324. data/ext/ngtcp2/tests/ngtcp2_vec_test.h +36 -0
  325. data/ext/ngtcp2/third-party/CMakeLists.txt +34 -0
  326. data/ext/ngtcp2/third-party/Makefile.am +31 -0
  327. data/ext/ngtcp2/third-party/http-parser/AUTHORS +68 -0
  328. data/ext/ngtcp2/third-party/http-parser/LICENSE-MIT +23 -0
  329. data/ext/ngtcp2/third-party/http-parser/Makefile +157 -0
  330. data/ext/ngtcp2/third-party/http-parser/README.md +246 -0
  331. data/ext/ngtcp2/third-party/http-parser/bench.c +111 -0
  332. data/ext/ngtcp2/third-party/http-parser/contrib/parsertrace.c +160 -0
  333. data/ext/ngtcp2/third-party/http-parser/contrib/url_parser.c +47 -0
  334. data/ext/ngtcp2/third-party/http-parser/http_parser.c +2419 -0
  335. data/ext/ngtcp2/third-party/http-parser/http_parser.gyp +111 -0
  336. data/ext/ngtcp2/third-party/http-parser/http_parser.h +431 -0
  337. data/ext/ngtcp2/third-party/http-parser/test.c +4411 -0
  338. data/lib/protocol/quic/version.rb +10 -0
  339. data/lib/protocol/quic.rb +9 -0
  340. data/license.md +21 -0
  341. data.tar.gz.sig +1 -0
  342. metadata +424 -0
  343. metadata.gz.sig +1 -0
@@ -0,0 +1,4411 @@
1
+ /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ * of this software and associated documentation files (the "Software"), to
5
+ * deal in the Software without restriction, including without limitation the
6
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ * sell copies of the Software, and to permit persons to whom the Software is
8
+ * furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in
11
+ * all copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ * IN THE SOFTWARE.
20
+ */
21
+ #include "http_parser.h"
22
+ #include <stdlib.h>
23
+ #include <assert.h>
24
+ #include <stdio.h>
25
+ #include <stdlib.h> /* rand */
26
+ #include <string.h>
27
+ #include <stdarg.h>
28
+
29
+ #if defined(__APPLE__)
30
+ # undef strlcat
31
+ # undef strlncpy
32
+ # undef strlcpy
33
+ #endif /* defined(__APPLE__) */
34
+
35
+ #undef TRUE
36
+ #define TRUE 1
37
+ #undef FALSE
38
+ #define FALSE 0
39
+
40
+ #define MAX_HEADERS 13
41
+ #define MAX_ELEMENT_SIZE 2048
42
+ #define MAX_CHUNKS 16
43
+
44
+ #define MIN(a,b) ((a) < (b) ? (a) : (b))
45
+
46
+ static http_parser *parser;
47
+
48
+ struct message {
49
+ const char *name; // for debugging purposes
50
+ const char *raw;
51
+ enum http_parser_type type;
52
+ enum http_method method;
53
+ int status_code;
54
+ char response_status[MAX_ELEMENT_SIZE];
55
+ char request_path[MAX_ELEMENT_SIZE];
56
+ char request_url[MAX_ELEMENT_SIZE];
57
+ char fragment[MAX_ELEMENT_SIZE];
58
+ char query_string[MAX_ELEMENT_SIZE];
59
+ char body[MAX_ELEMENT_SIZE];
60
+ size_t body_size;
61
+ const char *host;
62
+ const char *userinfo;
63
+ uint16_t port;
64
+ int num_headers;
65
+ enum { NONE=0, FIELD, VALUE } last_header_element;
66
+ char headers [MAX_HEADERS][2][MAX_ELEMENT_SIZE];
67
+ int should_keep_alive;
68
+
69
+ int num_chunks;
70
+ int num_chunks_complete;
71
+ int chunk_lengths[MAX_CHUNKS];
72
+
73
+ const char *upgrade; // upgraded body
74
+
75
+ unsigned short http_major;
76
+ unsigned short http_minor;
77
+
78
+ int message_begin_cb_called;
79
+ int headers_complete_cb_called;
80
+ int message_complete_cb_called;
81
+ int status_cb_called;
82
+ int message_complete_on_eof;
83
+ int body_is_final;
84
+ };
85
+
86
+ static int currently_parsing_eof;
87
+
88
+ static struct message messages[5];
89
+ static int num_messages;
90
+ static http_parser_settings *current_pause_parser;
91
+
92
+ /* * R E Q U E S T S * */
93
+ const struct message requests[] =
94
+ #define CURL_GET 0
95
+ { {.name= "curl get"
96
+ ,.type= HTTP_REQUEST
97
+ ,.raw= "GET /test HTTP/1.1\r\n"
98
+ "User-Agent: curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1\r\n"
99
+ "Host: 0.0.0.0=5000\r\n"
100
+ "Accept: */*\r\n"
101
+ "\r\n"
102
+ ,.should_keep_alive= TRUE
103
+ ,.message_complete_on_eof= FALSE
104
+ ,.http_major= 1
105
+ ,.http_minor= 1
106
+ ,.method= HTTP_GET
107
+ ,.query_string= ""
108
+ ,.fragment= ""
109
+ ,.request_path= "/test"
110
+ ,.request_url= "/test"
111
+ ,.num_headers= 3
112
+ ,.headers=
113
+ { { "User-Agent", "curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1" }
114
+ , { "Host", "0.0.0.0=5000" }
115
+ , { "Accept", "*/*" }
116
+ }
117
+ ,.body= ""
118
+ }
119
+
120
+ #define FIREFOX_GET 1
121
+ , {.name= "firefox get"
122
+ ,.type= HTTP_REQUEST
123
+ ,.raw= "GET /favicon.ico HTTP/1.1\r\n"
124
+ "Host: 0.0.0.0=5000\r\n"
125
+ "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0\r\n"
126
+ "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
127
+ "Accept-Language: en-us,en;q=0.5\r\n"
128
+ "Accept-Encoding: gzip,deflate\r\n"
129
+ "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"
130
+ "Keep-Alive: 300\r\n"
131
+ "Connection: keep-alive\r\n"
132
+ "\r\n"
133
+ ,.should_keep_alive= TRUE
134
+ ,.message_complete_on_eof= FALSE
135
+ ,.http_major= 1
136
+ ,.http_minor= 1
137
+ ,.method= HTTP_GET
138
+ ,.query_string= ""
139
+ ,.fragment= ""
140
+ ,.request_path= "/favicon.ico"
141
+ ,.request_url= "/favicon.ico"
142
+ ,.num_headers= 8
143
+ ,.headers=
144
+ { { "Host", "0.0.0.0=5000" }
145
+ , { "User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061015 Firefox/3.0" }
146
+ , { "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" }
147
+ , { "Accept-Language", "en-us,en;q=0.5" }
148
+ , { "Accept-Encoding", "gzip,deflate" }
149
+ , { "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7" }
150
+ , { "Keep-Alive", "300" }
151
+ , { "Connection", "keep-alive" }
152
+ }
153
+ ,.body= ""
154
+ }
155
+
156
+ #define DUMBFUCK 2
157
+ , {.name= "dumbfuck"
158
+ ,.type= HTTP_REQUEST
159
+ ,.raw= "GET /dumbfuck HTTP/1.1\r\n"
160
+ "aaaaaaaaaaaaa:++++++++++\r\n"
161
+ "\r\n"
162
+ ,.should_keep_alive= TRUE
163
+ ,.message_complete_on_eof= FALSE
164
+ ,.http_major= 1
165
+ ,.http_minor= 1
166
+ ,.method= HTTP_GET
167
+ ,.query_string= ""
168
+ ,.fragment= ""
169
+ ,.request_path= "/dumbfuck"
170
+ ,.request_url= "/dumbfuck"
171
+ ,.num_headers= 1
172
+ ,.headers=
173
+ { { "aaaaaaaaaaaaa", "++++++++++" }
174
+ }
175
+ ,.body= ""
176
+ }
177
+
178
+ #define FRAGMENT_IN_URI 3
179
+ , {.name= "fragment in url"
180
+ ,.type= HTTP_REQUEST
181
+ ,.raw= "GET /forums/1/topics/2375?page=1#posts-17408 HTTP/1.1\r\n"
182
+ "\r\n"
183
+ ,.should_keep_alive= TRUE
184
+ ,.message_complete_on_eof= FALSE
185
+ ,.http_major= 1
186
+ ,.http_minor= 1
187
+ ,.method= HTTP_GET
188
+ ,.query_string= "page=1"
189
+ ,.fragment= "posts-17408"
190
+ ,.request_path= "/forums/1/topics/2375"
191
+ /* XXX request url does include fragment? */
192
+ ,.request_url= "/forums/1/topics/2375?page=1#posts-17408"
193
+ ,.num_headers= 0
194
+ ,.body= ""
195
+ }
196
+
197
+ #define GET_NO_HEADERS_NO_BODY 4
198
+ , {.name= "get no headers no body"
199
+ ,.type= HTTP_REQUEST
200
+ ,.raw= "GET /get_no_headers_no_body/world HTTP/1.1\r\n"
201
+ "\r\n"
202
+ ,.should_keep_alive= TRUE
203
+ ,.message_complete_on_eof= FALSE /* would need Connection: close */
204
+ ,.http_major= 1
205
+ ,.http_minor= 1
206
+ ,.method= HTTP_GET
207
+ ,.query_string= ""
208
+ ,.fragment= ""
209
+ ,.request_path= "/get_no_headers_no_body/world"
210
+ ,.request_url= "/get_no_headers_no_body/world"
211
+ ,.num_headers= 0
212
+ ,.body= ""
213
+ }
214
+
215
+ #define GET_ONE_HEADER_NO_BODY 5
216
+ , {.name= "get one header no body"
217
+ ,.type= HTTP_REQUEST
218
+ ,.raw= "GET /get_one_header_no_body HTTP/1.1\r\n"
219
+ "Accept: */*\r\n"
220
+ "\r\n"
221
+ ,.should_keep_alive= TRUE
222
+ ,.message_complete_on_eof= FALSE /* would need Connection: close */
223
+ ,.http_major= 1
224
+ ,.http_minor= 1
225
+ ,.method= HTTP_GET
226
+ ,.query_string= ""
227
+ ,.fragment= ""
228
+ ,.request_path= "/get_one_header_no_body"
229
+ ,.request_url= "/get_one_header_no_body"
230
+ ,.num_headers= 1
231
+ ,.headers=
232
+ { { "Accept" , "*/*" }
233
+ }
234
+ ,.body= ""
235
+ }
236
+
237
+ #define GET_FUNKY_CONTENT_LENGTH 6
238
+ , {.name= "get funky content length body hello"
239
+ ,.type= HTTP_REQUEST
240
+ ,.raw= "GET /get_funky_content_length_body_hello HTTP/1.0\r\n"
241
+ "conTENT-Length: 5\r\n"
242
+ "\r\n"
243
+ "HELLO"
244
+ ,.should_keep_alive= FALSE
245
+ ,.message_complete_on_eof= FALSE
246
+ ,.http_major= 1
247
+ ,.http_minor= 0
248
+ ,.method= HTTP_GET
249
+ ,.query_string= ""
250
+ ,.fragment= ""
251
+ ,.request_path= "/get_funky_content_length_body_hello"
252
+ ,.request_url= "/get_funky_content_length_body_hello"
253
+ ,.num_headers= 1
254
+ ,.headers=
255
+ { { "conTENT-Length" , "5" }
256
+ }
257
+ ,.body= "HELLO"
258
+ }
259
+
260
+ #define POST_IDENTITY_BODY_WORLD 7
261
+ , {.name= "post identity body world"
262
+ ,.type= HTTP_REQUEST
263
+ ,.raw= "POST /post_identity_body_world?q=search#hey HTTP/1.1\r\n"
264
+ "Accept: */*\r\n"
265
+ "Transfer-Encoding: identity\r\n"
266
+ "Content-Length: 5\r\n"
267
+ "\r\n"
268
+ "World"
269
+ ,.should_keep_alive= TRUE
270
+ ,.message_complete_on_eof= FALSE
271
+ ,.http_major= 1
272
+ ,.http_minor= 1
273
+ ,.method= HTTP_POST
274
+ ,.query_string= "q=search"
275
+ ,.fragment= "hey"
276
+ ,.request_path= "/post_identity_body_world"
277
+ ,.request_url= "/post_identity_body_world?q=search#hey"
278
+ ,.num_headers= 3
279
+ ,.headers=
280
+ { { "Accept", "*/*" }
281
+ , { "Transfer-Encoding", "identity" }
282
+ , { "Content-Length", "5" }
283
+ }
284
+ ,.body= "World"
285
+ }
286
+
287
+ #define POST_CHUNKED_ALL_YOUR_BASE 8
288
+ , {.name= "post - chunked body: all your base are belong to us"
289
+ ,.type= HTTP_REQUEST
290
+ ,.raw= "POST /post_chunked_all_your_base HTTP/1.1\r\n"
291
+ "Transfer-Encoding: chunked\r\n"
292
+ "\r\n"
293
+ "1e\r\nall your base are belong to us\r\n"
294
+ "0\r\n"
295
+ "\r\n"
296
+ ,.should_keep_alive= TRUE
297
+ ,.message_complete_on_eof= FALSE
298
+ ,.http_major= 1
299
+ ,.http_minor= 1
300
+ ,.method= HTTP_POST
301
+ ,.query_string= ""
302
+ ,.fragment= ""
303
+ ,.request_path= "/post_chunked_all_your_base"
304
+ ,.request_url= "/post_chunked_all_your_base"
305
+ ,.num_headers= 1
306
+ ,.headers=
307
+ { { "Transfer-Encoding" , "chunked" }
308
+ }
309
+ ,.body= "all your base are belong to us"
310
+ ,.num_chunks_complete= 2
311
+ ,.chunk_lengths= { 0x1e }
312
+ }
313
+
314
+ #define TWO_CHUNKS_MULT_ZERO_END 9
315
+ , {.name= "two chunks ; triple zero ending"
316
+ ,.type= HTTP_REQUEST
317
+ ,.raw= "POST /two_chunks_mult_zero_end HTTP/1.1\r\n"
318
+ "Transfer-Encoding: chunked\r\n"
319
+ "\r\n"
320
+ "5\r\nhello\r\n"
321
+ "6\r\n world\r\n"
322
+ "000\r\n"
323
+ "\r\n"
324
+ ,.should_keep_alive= TRUE
325
+ ,.message_complete_on_eof= FALSE
326
+ ,.http_major= 1
327
+ ,.http_minor= 1
328
+ ,.method= HTTP_POST
329
+ ,.query_string= ""
330
+ ,.fragment= ""
331
+ ,.request_path= "/two_chunks_mult_zero_end"
332
+ ,.request_url= "/two_chunks_mult_zero_end"
333
+ ,.num_headers= 1
334
+ ,.headers=
335
+ { { "Transfer-Encoding", "chunked" }
336
+ }
337
+ ,.body= "hello world"
338
+ ,.num_chunks_complete= 3
339
+ ,.chunk_lengths= { 5, 6 }
340
+ }
341
+
342
+ #define CHUNKED_W_TRAILING_HEADERS 10
343
+ , {.name= "chunked with trailing headers. blech."
344
+ ,.type= HTTP_REQUEST
345
+ ,.raw= "POST /chunked_w_trailing_headers HTTP/1.1\r\n"
346
+ "Transfer-Encoding: chunked\r\n"
347
+ "\r\n"
348
+ "5\r\nhello\r\n"
349
+ "6\r\n world\r\n"
350
+ "0\r\n"
351
+ "Vary: *\r\n"
352
+ "Content-Type: text/plain\r\n"
353
+ "\r\n"
354
+ ,.should_keep_alive= TRUE
355
+ ,.message_complete_on_eof= FALSE
356
+ ,.http_major= 1
357
+ ,.http_minor= 1
358
+ ,.method= HTTP_POST
359
+ ,.query_string= ""
360
+ ,.fragment= ""
361
+ ,.request_path= "/chunked_w_trailing_headers"
362
+ ,.request_url= "/chunked_w_trailing_headers"
363
+ ,.num_headers= 3
364
+ ,.headers=
365
+ { { "Transfer-Encoding", "chunked" }
366
+ , { "Vary", "*" }
367
+ , { "Content-Type", "text/plain" }
368
+ }
369
+ ,.body= "hello world"
370
+ ,.num_chunks_complete= 3
371
+ ,.chunk_lengths= { 5, 6 }
372
+ }
373
+
374
+ #define CHUNKED_W_BULLSHIT_AFTER_LENGTH 11
375
+ , {.name= "with bullshit after the length"
376
+ ,.type= HTTP_REQUEST
377
+ ,.raw= "POST /chunked_w_bullshit_after_length HTTP/1.1\r\n"
378
+ "Transfer-Encoding: chunked\r\n"
379
+ "\r\n"
380
+ "5; ihatew3;whatthefuck=aretheseparametersfor\r\nhello\r\n"
381
+ "6; blahblah; blah\r\n world\r\n"
382
+ "0\r\n"
383
+ "\r\n"
384
+ ,.should_keep_alive= TRUE
385
+ ,.message_complete_on_eof= FALSE
386
+ ,.http_major= 1
387
+ ,.http_minor= 1
388
+ ,.method= HTTP_POST
389
+ ,.query_string= ""
390
+ ,.fragment= ""
391
+ ,.request_path= "/chunked_w_bullshit_after_length"
392
+ ,.request_url= "/chunked_w_bullshit_after_length"
393
+ ,.num_headers= 1
394
+ ,.headers=
395
+ { { "Transfer-Encoding", "chunked" }
396
+ }
397
+ ,.body= "hello world"
398
+ ,.num_chunks_complete= 3
399
+ ,.chunk_lengths= { 5, 6 }
400
+ }
401
+
402
+ #define WITH_QUOTES 12
403
+ , {.name= "with quotes"
404
+ ,.type= HTTP_REQUEST
405
+ ,.raw= "GET /with_\"stupid\"_quotes?foo=\"bar\" HTTP/1.1\r\n\r\n"
406
+ ,.should_keep_alive= TRUE
407
+ ,.message_complete_on_eof= FALSE
408
+ ,.http_major= 1
409
+ ,.http_minor= 1
410
+ ,.method= HTTP_GET
411
+ ,.query_string= "foo=\"bar\""
412
+ ,.fragment= ""
413
+ ,.request_path= "/with_\"stupid\"_quotes"
414
+ ,.request_url= "/with_\"stupid\"_quotes?foo=\"bar\""
415
+ ,.num_headers= 0
416
+ ,.headers= { }
417
+ ,.body= ""
418
+ }
419
+
420
+ #define APACHEBENCH_GET 13
421
+ /* The server receiving this request SHOULD NOT wait for EOF
422
+ * to know that content-length == 0.
423
+ * How to represent this in a unit test? message_complete_on_eof
424
+ * Compare with NO_CONTENT_LENGTH_RESPONSE.
425
+ */
426
+ , {.name = "apachebench get"
427
+ ,.type= HTTP_REQUEST
428
+ ,.raw= "GET /test HTTP/1.0\r\n"
429
+ "Host: 0.0.0.0:5000\r\n"
430
+ "User-Agent: ApacheBench/2.3\r\n"
431
+ "Accept: */*\r\n\r\n"
432
+ ,.should_keep_alive= FALSE
433
+ ,.message_complete_on_eof= FALSE
434
+ ,.http_major= 1
435
+ ,.http_minor= 0
436
+ ,.method= HTTP_GET
437
+ ,.query_string= ""
438
+ ,.fragment= ""
439
+ ,.request_path= "/test"
440
+ ,.request_url= "/test"
441
+ ,.num_headers= 3
442
+ ,.headers= { { "Host", "0.0.0.0:5000" }
443
+ , { "User-Agent", "ApacheBench/2.3" }
444
+ , { "Accept", "*/*" }
445
+ }
446
+ ,.body= ""
447
+ }
448
+
449
+ #define QUERY_URL_WITH_QUESTION_MARK_GET 14
450
+ /* Some clients include '?' characters in query strings.
451
+ */
452
+ , {.name = "query url with question mark"
453
+ ,.type= HTTP_REQUEST
454
+ ,.raw= "GET /test.cgi?foo=bar?baz HTTP/1.1\r\n\r\n"
455
+ ,.should_keep_alive= TRUE
456
+ ,.message_complete_on_eof= FALSE
457
+ ,.http_major= 1
458
+ ,.http_minor= 1
459
+ ,.method= HTTP_GET
460
+ ,.query_string= "foo=bar?baz"
461
+ ,.fragment= ""
462
+ ,.request_path= "/test.cgi"
463
+ ,.request_url= "/test.cgi?foo=bar?baz"
464
+ ,.num_headers= 0
465
+ ,.headers= {}
466
+ ,.body= ""
467
+ }
468
+
469
+ #define PREFIX_NEWLINE_GET 15
470
+ /* Some clients, especially after a POST in a keep-alive connection,
471
+ * will send an extra CRLF before the next request
472
+ */
473
+ , {.name = "newline prefix get"
474
+ ,.type= HTTP_REQUEST
475
+ ,.raw= "\r\nGET /test HTTP/1.1\r\n\r\n"
476
+ ,.should_keep_alive= TRUE
477
+ ,.message_complete_on_eof= FALSE
478
+ ,.http_major= 1
479
+ ,.http_minor= 1
480
+ ,.method= HTTP_GET
481
+ ,.query_string= ""
482
+ ,.fragment= ""
483
+ ,.request_path= "/test"
484
+ ,.request_url= "/test"
485
+ ,.num_headers= 0
486
+ ,.headers= { }
487
+ ,.body= ""
488
+ }
489
+
490
+ #define UPGRADE_REQUEST 16
491
+ , {.name = "upgrade request"
492
+ ,.type= HTTP_REQUEST
493
+ ,.raw= "GET /demo HTTP/1.1\r\n"
494
+ "Host: example.com\r\n"
495
+ "Connection: Upgrade\r\n"
496
+ "Sec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\n"
497
+ "Sec-WebSocket-Protocol: sample\r\n"
498
+ "Upgrade: WebSocket\r\n"
499
+ "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n"
500
+ "Origin: http://example.com\r\n"
501
+ "\r\n"
502
+ "Hot diggity dogg"
503
+ ,.should_keep_alive= TRUE
504
+ ,.message_complete_on_eof= FALSE
505
+ ,.http_major= 1
506
+ ,.http_minor= 1
507
+ ,.method= HTTP_GET
508
+ ,.query_string= ""
509
+ ,.fragment= ""
510
+ ,.request_path= "/demo"
511
+ ,.request_url= "/demo"
512
+ ,.num_headers= 7
513
+ ,.upgrade="Hot diggity dogg"
514
+ ,.headers= { { "Host", "example.com" }
515
+ , { "Connection", "Upgrade" }
516
+ , { "Sec-WebSocket-Key2", "12998 5 Y3 1 .P00" }
517
+ , { "Sec-WebSocket-Protocol", "sample" }
518
+ , { "Upgrade", "WebSocket" }
519
+ , { "Sec-WebSocket-Key1", "4 @1 46546xW%0l 1 5" }
520
+ , { "Origin", "http://example.com" }
521
+ }
522
+ ,.body= ""
523
+ }
524
+
525
+ #define CONNECT_REQUEST 17
526
+ , {.name = "connect request"
527
+ ,.type= HTTP_REQUEST
528
+ ,.raw= "CONNECT 0-home0.netscape.com:443 HTTP/1.0\r\n"
529
+ "User-agent: Mozilla/1.1N\r\n"
530
+ "Proxy-authorization: basic aGVsbG86d29ybGQ=\r\n"
531
+ "\r\n"
532
+ "some data\r\n"
533
+ "and yet even more data"
534
+ ,.should_keep_alive= FALSE
535
+ ,.message_complete_on_eof= FALSE
536
+ ,.http_major= 1
537
+ ,.http_minor= 0
538
+ ,.method= HTTP_CONNECT
539
+ ,.query_string= ""
540
+ ,.fragment= ""
541
+ ,.request_path= ""
542
+ ,.request_url= "0-home0.netscape.com:443"
543
+ ,.num_headers= 2
544
+ ,.upgrade="some data\r\nand yet even more data"
545
+ ,.headers= { { "User-agent", "Mozilla/1.1N" }
546
+ , { "Proxy-authorization", "basic aGVsbG86d29ybGQ=" }
547
+ }
548
+ ,.body= ""
549
+ }
550
+
551
+ #define REPORT_REQ 18
552
+ , {.name= "report request"
553
+ ,.type= HTTP_REQUEST
554
+ ,.raw= "REPORT /test HTTP/1.1\r\n"
555
+ "\r\n"
556
+ ,.should_keep_alive= TRUE
557
+ ,.message_complete_on_eof= FALSE
558
+ ,.http_major= 1
559
+ ,.http_minor= 1
560
+ ,.method= HTTP_REPORT
561
+ ,.query_string= ""
562
+ ,.fragment= ""
563
+ ,.request_path= "/test"
564
+ ,.request_url= "/test"
565
+ ,.num_headers= 0
566
+ ,.headers= {}
567
+ ,.body= ""
568
+ }
569
+
570
+ #define NO_HTTP_VERSION 19
571
+ , {.name= "request with no http version"
572
+ ,.type= HTTP_REQUEST
573
+ ,.raw= "GET /\r\n"
574
+ "\r\n"
575
+ ,.should_keep_alive= FALSE
576
+ ,.message_complete_on_eof= FALSE
577
+ ,.http_major= 0
578
+ ,.http_minor= 9
579
+ ,.method= HTTP_GET
580
+ ,.query_string= ""
581
+ ,.fragment= ""
582
+ ,.request_path= "/"
583
+ ,.request_url= "/"
584
+ ,.num_headers= 0
585
+ ,.headers= {}
586
+ ,.body= ""
587
+ }
588
+
589
+ #define MSEARCH_REQ 20
590
+ , {.name= "m-search request"
591
+ ,.type= HTTP_REQUEST
592
+ ,.raw= "M-SEARCH * HTTP/1.1\r\n"
593
+ "HOST: 239.255.255.250:1900\r\n"
594
+ "MAN: \"ssdp:discover\"\r\n"
595
+ "ST: \"ssdp:all\"\r\n"
596
+ "\r\n"
597
+ ,.should_keep_alive= TRUE
598
+ ,.message_complete_on_eof= FALSE
599
+ ,.http_major= 1
600
+ ,.http_minor= 1
601
+ ,.method= HTTP_MSEARCH
602
+ ,.query_string= ""
603
+ ,.fragment= ""
604
+ ,.request_path= "*"
605
+ ,.request_url= "*"
606
+ ,.num_headers= 3
607
+ ,.headers= { { "HOST", "239.255.255.250:1900" }
608
+ , { "MAN", "\"ssdp:discover\"" }
609
+ , { "ST", "\"ssdp:all\"" }
610
+ }
611
+ ,.body= ""
612
+ }
613
+
614
+ #define LINE_FOLDING_IN_HEADER 21
615
+ , {.name= "line folding in header value"
616
+ ,.type= HTTP_REQUEST
617
+ ,.raw= "GET / HTTP/1.1\r\n"
618
+ "Line1: abc\r\n"
619
+ "\tdef\r\n"
620
+ " ghi\r\n"
621
+ "\t\tjkl\r\n"
622
+ " mno \r\n"
623
+ "\t \tqrs\r\n"
624
+ "Line2: \t line2\t\r\n"
625
+ "Line3:\r\n"
626
+ " line3\r\n"
627
+ "Line4: \r\n"
628
+ " \r\n"
629
+ "Connection:\r\n"
630
+ " close\r\n"
631
+ "\r\n"
632
+ ,.should_keep_alive= FALSE
633
+ ,.message_complete_on_eof= FALSE
634
+ ,.http_major= 1
635
+ ,.http_minor= 1
636
+ ,.method= HTTP_GET
637
+ ,.query_string= ""
638
+ ,.fragment= ""
639
+ ,.request_path= "/"
640
+ ,.request_url= "/"
641
+ ,.num_headers= 5
642
+ ,.headers= { { "Line1", "abc\tdef ghi\t\tjkl mno \t \tqrs" }
643
+ , { "Line2", "line2\t" }
644
+ , { "Line3", "line3" }
645
+ , { "Line4", "" }
646
+ , { "Connection", "close" },
647
+ }
648
+ ,.body= ""
649
+ }
650
+
651
+
652
+ #define QUERY_TERMINATED_HOST 22
653
+ , {.name= "host terminated by a query string"
654
+ ,.type= HTTP_REQUEST
655
+ ,.raw= "GET http://hypnotoad.org?hail=all HTTP/1.1\r\n"
656
+ "\r\n"
657
+ ,.should_keep_alive= TRUE
658
+ ,.message_complete_on_eof= FALSE
659
+ ,.http_major= 1
660
+ ,.http_minor= 1
661
+ ,.method= HTTP_GET
662
+ ,.query_string= "hail=all"
663
+ ,.fragment= ""
664
+ ,.request_path= ""
665
+ ,.request_url= "http://hypnotoad.org?hail=all"
666
+ ,.host= "hypnotoad.org"
667
+ ,.num_headers= 0
668
+ ,.headers= { }
669
+ ,.body= ""
670
+ }
671
+
672
+ #define QUERY_TERMINATED_HOSTPORT 23
673
+ , {.name= "host:port terminated by a query string"
674
+ ,.type= HTTP_REQUEST
675
+ ,.raw= "GET http://hypnotoad.org:1234?hail=all HTTP/1.1\r\n"
676
+ "\r\n"
677
+ ,.should_keep_alive= TRUE
678
+ ,.message_complete_on_eof= FALSE
679
+ ,.http_major= 1
680
+ ,.http_minor= 1
681
+ ,.method= HTTP_GET
682
+ ,.query_string= "hail=all"
683
+ ,.fragment= ""
684
+ ,.request_path= ""
685
+ ,.request_url= "http://hypnotoad.org:1234?hail=all"
686
+ ,.host= "hypnotoad.org"
687
+ ,.port= 1234
688
+ ,.num_headers= 0
689
+ ,.headers= { }
690
+ ,.body= ""
691
+ }
692
+
693
+ #define SPACE_TERMINATED_HOSTPORT 24
694
+ , {.name= "host:port terminated by a space"
695
+ ,.type= HTTP_REQUEST
696
+ ,.raw= "GET http://hypnotoad.org:1234 HTTP/1.1\r\n"
697
+ "\r\n"
698
+ ,.should_keep_alive= TRUE
699
+ ,.message_complete_on_eof= FALSE
700
+ ,.http_major= 1
701
+ ,.http_minor= 1
702
+ ,.method= HTTP_GET
703
+ ,.query_string= ""
704
+ ,.fragment= ""
705
+ ,.request_path= ""
706
+ ,.request_url= "http://hypnotoad.org:1234"
707
+ ,.host= "hypnotoad.org"
708
+ ,.port= 1234
709
+ ,.num_headers= 0
710
+ ,.headers= { }
711
+ ,.body= ""
712
+ }
713
+
714
+ #define PATCH_REQ 25
715
+ , {.name = "PATCH request"
716
+ ,.type= HTTP_REQUEST
717
+ ,.raw= "PATCH /file.txt HTTP/1.1\r\n"
718
+ "Host: www.example.com\r\n"
719
+ "Content-Type: application/example\r\n"
720
+ "If-Match: \"e0023aa4e\"\r\n"
721
+ "Content-Length: 10\r\n"
722
+ "\r\n"
723
+ "cccccccccc"
724
+ ,.should_keep_alive= TRUE
725
+ ,.message_complete_on_eof= FALSE
726
+ ,.http_major= 1
727
+ ,.http_minor= 1
728
+ ,.method= HTTP_PATCH
729
+ ,.query_string= ""
730
+ ,.fragment= ""
731
+ ,.request_path= "/file.txt"
732
+ ,.request_url= "/file.txt"
733
+ ,.num_headers= 4
734
+ ,.headers= { { "Host", "www.example.com" }
735
+ , { "Content-Type", "application/example" }
736
+ , { "If-Match", "\"e0023aa4e\"" }
737
+ , { "Content-Length", "10" }
738
+ }
739
+ ,.body= "cccccccccc"
740
+ }
741
+
742
+ #define CONNECT_CAPS_REQUEST 26
743
+ , {.name = "connect caps request"
744
+ ,.type= HTTP_REQUEST
745
+ ,.raw= "CONNECT HOME0.NETSCAPE.COM:443 HTTP/1.0\r\n"
746
+ "User-agent: Mozilla/1.1N\r\n"
747
+ "Proxy-authorization: basic aGVsbG86d29ybGQ=\r\n"
748
+ "\r\n"
749
+ ,.should_keep_alive= FALSE
750
+ ,.message_complete_on_eof= FALSE
751
+ ,.http_major= 1
752
+ ,.http_minor= 0
753
+ ,.method= HTTP_CONNECT
754
+ ,.query_string= ""
755
+ ,.fragment= ""
756
+ ,.request_path= ""
757
+ ,.request_url= "HOME0.NETSCAPE.COM:443"
758
+ ,.num_headers= 2
759
+ ,.upgrade=""
760
+ ,.headers= { { "User-agent", "Mozilla/1.1N" }
761
+ , { "Proxy-authorization", "basic aGVsbG86d29ybGQ=" }
762
+ }
763
+ ,.body= ""
764
+ }
765
+
766
+ #if !HTTP_PARSER_STRICT
767
+ #define UTF8_PATH_REQ 27
768
+ , {.name= "utf-8 path request"
769
+ ,.type= HTTP_REQUEST
770
+ ,.raw= "GET /δ¶/δt/pope?q=1#narf HTTP/1.1\r\n"
771
+ "Host: github.com\r\n"
772
+ "\r\n"
773
+ ,.should_keep_alive= TRUE
774
+ ,.message_complete_on_eof= FALSE
775
+ ,.http_major= 1
776
+ ,.http_minor= 1
777
+ ,.method= HTTP_GET
778
+ ,.query_string= "q=1"
779
+ ,.fragment= "narf"
780
+ ,.request_path= "/δ¶/δt/pope"
781
+ ,.request_url= "/δ¶/δt/pope?q=1#narf"
782
+ ,.num_headers= 1
783
+ ,.headers= { {"Host", "github.com" }
784
+ }
785
+ ,.body= ""
786
+ }
787
+
788
+ #define HOSTNAME_UNDERSCORE 28
789
+ , {.name = "hostname underscore"
790
+ ,.type= HTTP_REQUEST
791
+ ,.raw= "CONNECT home_0.netscape.com:443 HTTP/1.0\r\n"
792
+ "User-agent: Mozilla/1.1N\r\n"
793
+ "Proxy-authorization: basic aGVsbG86d29ybGQ=\r\n"
794
+ "\r\n"
795
+ ,.should_keep_alive= FALSE
796
+ ,.message_complete_on_eof= FALSE
797
+ ,.http_major= 1
798
+ ,.http_minor= 0
799
+ ,.method= HTTP_CONNECT
800
+ ,.query_string= ""
801
+ ,.fragment= ""
802
+ ,.request_path= ""
803
+ ,.request_url= "home_0.netscape.com:443"
804
+ ,.num_headers= 2
805
+ ,.upgrade=""
806
+ ,.headers= { { "User-agent", "Mozilla/1.1N" }
807
+ , { "Proxy-authorization", "basic aGVsbG86d29ybGQ=" }
808
+ }
809
+ ,.body= ""
810
+ }
811
+ #endif /* !HTTP_PARSER_STRICT */
812
+
813
+ /* see https://github.com/ry/http-parser/issues/47 */
814
+ #define EAT_TRAILING_CRLF_NO_CONNECTION_CLOSE 29
815
+ , {.name = "eat CRLF between requests, no \"Connection: close\" header"
816
+ ,.raw= "POST / HTTP/1.1\r\n"
817
+ "Host: www.example.com\r\n"
818
+ "Content-Type: application/x-www-form-urlencoded\r\n"
819
+ "Content-Length: 4\r\n"
820
+ "\r\n"
821
+ "q=42\r\n" /* note the trailing CRLF */
822
+ ,.should_keep_alive= TRUE
823
+ ,.message_complete_on_eof= FALSE
824
+ ,.http_major= 1
825
+ ,.http_minor= 1
826
+ ,.method= HTTP_POST
827
+ ,.query_string= ""
828
+ ,.fragment= ""
829
+ ,.request_path= "/"
830
+ ,.request_url= "/"
831
+ ,.num_headers= 3
832
+ ,.upgrade= 0
833
+ ,.headers= { { "Host", "www.example.com" }
834
+ , { "Content-Type", "application/x-www-form-urlencoded" }
835
+ , { "Content-Length", "4" }
836
+ }
837
+ ,.body= "q=42"
838
+ }
839
+
840
+ /* see https://github.com/ry/http-parser/issues/47 */
841
+ #define EAT_TRAILING_CRLF_WITH_CONNECTION_CLOSE 30
842
+ , {.name = "eat CRLF between requests even if \"Connection: close\" is set"
843
+ ,.raw= "POST / HTTP/1.1\r\n"
844
+ "Host: www.example.com\r\n"
845
+ "Content-Type: application/x-www-form-urlencoded\r\n"
846
+ "Content-Length: 4\r\n"
847
+ "Connection: close\r\n"
848
+ "\r\n"
849
+ "q=42\r\n" /* note the trailing CRLF */
850
+ ,.should_keep_alive= FALSE
851
+ ,.message_complete_on_eof= FALSE /* input buffer isn't empty when on_message_complete is called */
852
+ ,.http_major= 1
853
+ ,.http_minor= 1
854
+ ,.method= HTTP_POST
855
+ ,.query_string= ""
856
+ ,.fragment= ""
857
+ ,.request_path= "/"
858
+ ,.request_url= "/"
859
+ ,.num_headers= 4
860
+ ,.upgrade= 0
861
+ ,.headers= { { "Host", "www.example.com" }
862
+ , { "Content-Type", "application/x-www-form-urlencoded" }
863
+ , { "Content-Length", "4" }
864
+ , { "Connection", "close" }
865
+ }
866
+ ,.body= "q=42"
867
+ }
868
+
869
+ #define PURGE_REQ 31
870
+ , {.name = "PURGE request"
871
+ ,.type= HTTP_REQUEST
872
+ ,.raw= "PURGE /file.txt HTTP/1.1\r\n"
873
+ "Host: www.example.com\r\n"
874
+ "\r\n"
875
+ ,.should_keep_alive= TRUE
876
+ ,.message_complete_on_eof= FALSE
877
+ ,.http_major= 1
878
+ ,.http_minor= 1
879
+ ,.method= HTTP_PURGE
880
+ ,.query_string= ""
881
+ ,.fragment= ""
882
+ ,.request_path= "/file.txt"
883
+ ,.request_url= "/file.txt"
884
+ ,.num_headers= 1
885
+ ,.headers= { { "Host", "www.example.com" } }
886
+ ,.body= ""
887
+ }
888
+
889
+ #define SEARCH_REQ 32
890
+ , {.name = "SEARCH request"
891
+ ,.type= HTTP_REQUEST
892
+ ,.raw= "SEARCH / HTTP/1.1\r\n"
893
+ "Host: www.example.com\r\n"
894
+ "\r\n"
895
+ ,.should_keep_alive= TRUE
896
+ ,.message_complete_on_eof= FALSE
897
+ ,.http_major= 1
898
+ ,.http_minor= 1
899
+ ,.method= HTTP_SEARCH
900
+ ,.query_string= ""
901
+ ,.fragment= ""
902
+ ,.request_path= "/"
903
+ ,.request_url= "/"
904
+ ,.num_headers= 1
905
+ ,.headers= { { "Host", "www.example.com" } }
906
+ ,.body= ""
907
+ }
908
+
909
+ #define PROXY_WITH_BASIC_AUTH 33
910
+ , {.name= "host:port and basic_auth"
911
+ ,.type= HTTP_REQUEST
912
+ ,.raw= "GET http://a%12:b!&*$@hypnotoad.org:1234/toto HTTP/1.1\r\n"
913
+ "\r\n"
914
+ ,.should_keep_alive= TRUE
915
+ ,.message_complete_on_eof= FALSE
916
+ ,.http_major= 1
917
+ ,.http_minor= 1
918
+ ,.method= HTTP_GET
919
+ ,.fragment= ""
920
+ ,.request_path= "/toto"
921
+ ,.request_url= "http://a%12:b!&*$@hypnotoad.org:1234/toto"
922
+ ,.host= "hypnotoad.org"
923
+ ,.userinfo= "a%12:b!&*$"
924
+ ,.port= 1234
925
+ ,.num_headers= 0
926
+ ,.headers= { }
927
+ ,.body= ""
928
+ }
929
+
930
+ #define LINE_FOLDING_IN_HEADER_WITH_LF 34
931
+ , {.name= "line folding in header value"
932
+ ,.type= HTTP_REQUEST
933
+ ,.raw= "GET / HTTP/1.1\n"
934
+ "Line1: abc\n"
935
+ "\tdef\n"
936
+ " ghi\n"
937
+ "\t\tjkl\n"
938
+ " mno \n"
939
+ "\t \tqrs\n"
940
+ "Line2: \t line2\t\n"
941
+ "Line3:\n"
942
+ " line3\n"
943
+ "Line4: \n"
944
+ " \n"
945
+ "Connection:\n"
946
+ " close\n"
947
+ "\n"
948
+ ,.should_keep_alive= FALSE
949
+ ,.message_complete_on_eof= FALSE
950
+ ,.http_major= 1
951
+ ,.http_minor= 1
952
+ ,.method= HTTP_GET
953
+ ,.query_string= ""
954
+ ,.fragment= ""
955
+ ,.request_path= "/"
956
+ ,.request_url= "/"
957
+ ,.num_headers= 5
958
+ ,.headers= { { "Line1", "abc\tdef ghi\t\tjkl mno \t \tqrs" }
959
+ , { "Line2", "line2\t" }
960
+ , { "Line3", "line3" }
961
+ , { "Line4", "" }
962
+ , { "Connection", "close" },
963
+ }
964
+ ,.body= ""
965
+ }
966
+
967
+ #define CONNECTION_MULTI 35
968
+ , {.name = "multiple connection header values with folding"
969
+ ,.type= HTTP_REQUEST
970
+ ,.raw= "GET /demo HTTP/1.1\r\n"
971
+ "Host: example.com\r\n"
972
+ "Connection: Something,\r\n"
973
+ " Upgrade, ,Keep-Alive\r\n"
974
+ "Sec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\n"
975
+ "Sec-WebSocket-Protocol: sample\r\n"
976
+ "Upgrade: WebSocket\r\n"
977
+ "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n"
978
+ "Origin: http://example.com\r\n"
979
+ "\r\n"
980
+ "Hot diggity dogg"
981
+ ,.should_keep_alive= TRUE
982
+ ,.message_complete_on_eof= FALSE
983
+ ,.http_major= 1
984
+ ,.http_minor= 1
985
+ ,.method= HTTP_GET
986
+ ,.query_string= ""
987
+ ,.fragment= ""
988
+ ,.request_path= "/demo"
989
+ ,.request_url= "/demo"
990
+ ,.num_headers= 7
991
+ ,.upgrade="Hot diggity dogg"
992
+ ,.headers= { { "Host", "example.com" }
993
+ , { "Connection", "Something, Upgrade, ,Keep-Alive" }
994
+ , { "Sec-WebSocket-Key2", "12998 5 Y3 1 .P00" }
995
+ , { "Sec-WebSocket-Protocol", "sample" }
996
+ , { "Upgrade", "WebSocket" }
997
+ , { "Sec-WebSocket-Key1", "4 @1 46546xW%0l 1 5" }
998
+ , { "Origin", "http://example.com" }
999
+ }
1000
+ ,.body= ""
1001
+ }
1002
+
1003
+ #define CONNECTION_MULTI_LWS 36
1004
+ , {.name = "multiple connection header values with folding and lws"
1005
+ ,.type= HTTP_REQUEST
1006
+ ,.raw= "GET /demo HTTP/1.1\r\n"
1007
+ "Connection: keep-alive, upgrade\r\n"
1008
+ "Upgrade: WebSocket\r\n"
1009
+ "\r\n"
1010
+ "Hot diggity dogg"
1011
+ ,.should_keep_alive= TRUE
1012
+ ,.message_complete_on_eof= FALSE
1013
+ ,.http_major= 1
1014
+ ,.http_minor= 1
1015
+ ,.method= HTTP_GET
1016
+ ,.query_string= ""
1017
+ ,.fragment= ""
1018
+ ,.request_path= "/demo"
1019
+ ,.request_url= "/demo"
1020
+ ,.num_headers= 2
1021
+ ,.upgrade="Hot diggity dogg"
1022
+ ,.headers= { { "Connection", "keep-alive, upgrade" }
1023
+ , { "Upgrade", "WebSocket" }
1024
+ }
1025
+ ,.body= ""
1026
+ }
1027
+
1028
+ #define CONNECTION_MULTI_LWS_CRLF 37
1029
+ , {.name = "multiple connection header values with folding and lws"
1030
+ ,.type= HTTP_REQUEST
1031
+ ,.raw= "GET /demo HTTP/1.1\r\n"
1032
+ "Connection: keep-alive, \r\n upgrade\r\n"
1033
+ "Upgrade: WebSocket\r\n"
1034
+ "\r\n"
1035
+ "Hot diggity dogg"
1036
+ ,.should_keep_alive= TRUE
1037
+ ,.message_complete_on_eof= FALSE
1038
+ ,.http_major= 1
1039
+ ,.http_minor= 1
1040
+ ,.method= HTTP_GET
1041
+ ,.query_string= ""
1042
+ ,.fragment= ""
1043
+ ,.request_path= "/demo"
1044
+ ,.request_url= "/demo"
1045
+ ,.num_headers= 2
1046
+ ,.upgrade="Hot diggity dogg"
1047
+ ,.headers= { { "Connection", "keep-alive, upgrade" }
1048
+ , { "Upgrade", "WebSocket" }
1049
+ }
1050
+ ,.body= ""
1051
+ }
1052
+
1053
+ #define UPGRADE_POST_REQUEST 38
1054
+ , {.name = "upgrade post request"
1055
+ ,.type= HTTP_REQUEST
1056
+ ,.raw= "POST /demo HTTP/1.1\r\n"
1057
+ "Host: example.com\r\n"
1058
+ "Connection: Upgrade\r\n"
1059
+ "Upgrade: HTTP/2.0\r\n"
1060
+ "Content-Length: 15\r\n"
1061
+ "\r\n"
1062
+ "sweet post body"
1063
+ "Hot diggity dogg"
1064
+ ,.should_keep_alive= TRUE
1065
+ ,.message_complete_on_eof= FALSE
1066
+ ,.http_major= 1
1067
+ ,.http_minor= 1
1068
+ ,.method= HTTP_POST
1069
+ ,.request_path= "/demo"
1070
+ ,.request_url= "/demo"
1071
+ ,.num_headers= 4
1072
+ ,.upgrade="Hot diggity dogg"
1073
+ ,.headers= { { "Host", "example.com" }
1074
+ , { "Connection", "Upgrade" }
1075
+ , { "Upgrade", "HTTP/2.0" }
1076
+ , { "Content-Length", "15" }
1077
+ }
1078
+ ,.body= "sweet post body"
1079
+ }
1080
+
1081
+ #define CONNECT_WITH_BODY_REQUEST 39
1082
+ , {.name = "connect with body request"
1083
+ ,.type= HTTP_REQUEST
1084
+ ,.raw= "CONNECT foo.bar.com:443 HTTP/1.0\r\n"
1085
+ "User-agent: Mozilla/1.1N\r\n"
1086
+ "Proxy-authorization: basic aGVsbG86d29ybGQ=\r\n"
1087
+ "Content-Length: 10\r\n"
1088
+ "\r\n"
1089
+ "blarfcicle"
1090
+ ,.should_keep_alive= FALSE
1091
+ ,.message_complete_on_eof= FALSE
1092
+ ,.http_major= 1
1093
+ ,.http_minor= 0
1094
+ ,.method= HTTP_CONNECT
1095
+ ,.request_url= "foo.bar.com:443"
1096
+ ,.num_headers= 3
1097
+ ,.upgrade="blarfcicle"
1098
+ ,.headers= { { "User-agent", "Mozilla/1.1N" }
1099
+ , { "Proxy-authorization", "basic aGVsbG86d29ybGQ=" }
1100
+ , { "Content-Length", "10" }
1101
+ }
1102
+ ,.body= ""
1103
+ }
1104
+
1105
+ /* Examples from the Internet draft for LINK/UNLINK methods:
1106
+ * https://tools.ietf.org/id/draft-snell-link-method-01.html#rfc.section.5
1107
+ */
1108
+
1109
+ #define LINK_REQUEST 40
1110
+ , {.name = "link request"
1111
+ ,.type= HTTP_REQUEST
1112
+ ,.raw= "LINK /images/my_dog.jpg HTTP/1.1\r\n"
1113
+ "Host: example.com\r\n"
1114
+ "Link: <http://example.com/profiles/joe>; rel=\"tag\"\r\n"
1115
+ "Link: <http://example.com/profiles/sally>; rel=\"tag\"\r\n"
1116
+ "\r\n"
1117
+ ,.should_keep_alive= TRUE
1118
+ ,.message_complete_on_eof= FALSE
1119
+ ,.http_major= 1
1120
+ ,.http_minor= 1
1121
+ ,.method= HTTP_LINK
1122
+ ,.request_path= "/images/my_dog.jpg"
1123
+ ,.request_url= "/images/my_dog.jpg"
1124
+ ,.query_string= ""
1125
+ ,.fragment= ""
1126
+ ,.num_headers= 3
1127
+ ,.headers= { { "Host", "example.com" }
1128
+ , { "Link", "<http://example.com/profiles/joe>; rel=\"tag\"" }
1129
+ , { "Link", "<http://example.com/profiles/sally>; rel=\"tag\"" }
1130
+ }
1131
+ ,.body= ""
1132
+ }
1133
+
1134
+ #define UNLINK_REQUEST 41
1135
+ , {.name = "unlink request"
1136
+ ,.type= HTTP_REQUEST
1137
+ ,.raw= "UNLINK /images/my_dog.jpg HTTP/1.1\r\n"
1138
+ "Host: example.com\r\n"
1139
+ "Link: <http://example.com/profiles/sally>; rel=\"tag\"\r\n"
1140
+ "\r\n"
1141
+ ,.should_keep_alive= TRUE
1142
+ ,.message_complete_on_eof= FALSE
1143
+ ,.http_major= 1
1144
+ ,.http_minor= 1
1145
+ ,.method= HTTP_UNLINK
1146
+ ,.request_path= "/images/my_dog.jpg"
1147
+ ,.request_url= "/images/my_dog.jpg"
1148
+ ,.query_string= ""
1149
+ ,.fragment= ""
1150
+ ,.num_headers= 2
1151
+ ,.headers= { { "Host", "example.com" }
1152
+ , { "Link", "<http://example.com/profiles/sally>; rel=\"tag\"" }
1153
+ }
1154
+ ,.body= ""
1155
+ }
1156
+
1157
+ , {.name= NULL } /* sentinel */
1158
+ };
1159
+
1160
+ /* * R E S P O N S E S * */
1161
+ const struct message responses[] =
1162
+ #define GOOGLE_301 0
1163
+ { {.name= "google 301"
1164
+ ,.type= HTTP_RESPONSE
1165
+ ,.raw= "HTTP/1.1 301 Moved Permanently\r\n"
1166
+ "Location: http://www.google.com/\r\n"
1167
+ "Content-Type: text/html; charset=UTF-8\r\n"
1168
+ "Date: Sun, 26 Apr 2009 11:11:49 GMT\r\n"
1169
+ "Expires: Tue, 26 May 2009 11:11:49 GMT\r\n"
1170
+ "X-$PrototypeBI-Version: 1.6.0.3\r\n" /* $ char in header field */
1171
+ "Cache-Control: public, max-age=2592000\r\n"
1172
+ "Server: gws\r\n"
1173
+ "Content-Length: 219 \r\n"
1174
+ "\r\n"
1175
+ "<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n"
1176
+ "<TITLE>301 Moved</TITLE></HEAD><BODY>\n"
1177
+ "<H1>301 Moved</H1>\n"
1178
+ "The document has moved\n"
1179
+ "<A HREF=\"http://www.google.com/\">here</A>.\r\n"
1180
+ "</BODY></HTML>\r\n"
1181
+ ,.should_keep_alive= TRUE
1182
+ ,.message_complete_on_eof= FALSE
1183
+ ,.http_major= 1
1184
+ ,.http_minor= 1
1185
+ ,.status_code= 301
1186
+ ,.response_status= "Moved Permanently"
1187
+ ,.num_headers= 8
1188
+ ,.headers=
1189
+ { { "Location", "http://www.google.com/" }
1190
+ , { "Content-Type", "text/html; charset=UTF-8" }
1191
+ , { "Date", "Sun, 26 Apr 2009 11:11:49 GMT" }
1192
+ , { "Expires", "Tue, 26 May 2009 11:11:49 GMT" }
1193
+ , { "X-$PrototypeBI-Version", "1.6.0.3" }
1194
+ , { "Cache-Control", "public, max-age=2592000" }
1195
+ , { "Server", "gws" }
1196
+ , { "Content-Length", "219 " }
1197
+ }
1198
+ ,.body= "<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n"
1199
+ "<TITLE>301 Moved</TITLE></HEAD><BODY>\n"
1200
+ "<H1>301 Moved</H1>\n"
1201
+ "The document has moved\n"
1202
+ "<A HREF=\"http://www.google.com/\">here</A>.\r\n"
1203
+ "</BODY></HTML>\r\n"
1204
+ }
1205
+
1206
+ #define NO_CONTENT_LENGTH_RESPONSE 1
1207
+ /* The client should wait for the server's EOF. That is, when content-length
1208
+ * is not specified, and "Connection: close", the end of body is specified
1209
+ * by the EOF.
1210
+ * Compare with APACHEBENCH_GET
1211
+ */
1212
+ , {.name= "no content-length response"
1213
+ ,.type= HTTP_RESPONSE
1214
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1215
+ "Date: Tue, 04 Aug 2009 07:59:32 GMT\r\n"
1216
+ "Server: Apache\r\n"
1217
+ "X-Powered-By: Servlet/2.5 JSP/2.1\r\n"
1218
+ "Content-Type: text/xml; charset=utf-8\r\n"
1219
+ "Connection: close\r\n"
1220
+ "\r\n"
1221
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1222
+ "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
1223
+ " <SOAP-ENV:Body>\n"
1224
+ " <SOAP-ENV:Fault>\n"
1225
+ " <faultcode>SOAP-ENV:Client</faultcode>\n"
1226
+ " <faultstring>Client Error</faultstring>\n"
1227
+ " </SOAP-ENV:Fault>\n"
1228
+ " </SOAP-ENV:Body>\n"
1229
+ "</SOAP-ENV:Envelope>"
1230
+ ,.should_keep_alive= FALSE
1231
+ ,.message_complete_on_eof= TRUE
1232
+ ,.http_major= 1
1233
+ ,.http_minor= 1
1234
+ ,.status_code= 200
1235
+ ,.response_status= "OK"
1236
+ ,.num_headers= 5
1237
+ ,.headers=
1238
+ { { "Date", "Tue, 04 Aug 2009 07:59:32 GMT" }
1239
+ , { "Server", "Apache" }
1240
+ , { "X-Powered-By", "Servlet/2.5 JSP/2.1" }
1241
+ , { "Content-Type", "text/xml; charset=utf-8" }
1242
+ , { "Connection", "close" }
1243
+ }
1244
+ ,.body= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1245
+ "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
1246
+ " <SOAP-ENV:Body>\n"
1247
+ " <SOAP-ENV:Fault>\n"
1248
+ " <faultcode>SOAP-ENV:Client</faultcode>\n"
1249
+ " <faultstring>Client Error</faultstring>\n"
1250
+ " </SOAP-ENV:Fault>\n"
1251
+ " </SOAP-ENV:Body>\n"
1252
+ "</SOAP-ENV:Envelope>"
1253
+ }
1254
+
1255
+ #define NO_HEADERS_NO_BODY_404 2
1256
+ , {.name= "404 no headers no body"
1257
+ ,.type= HTTP_RESPONSE
1258
+ ,.raw= "HTTP/1.1 404 Not Found\r\n\r\n"
1259
+ ,.should_keep_alive= FALSE
1260
+ ,.message_complete_on_eof= TRUE
1261
+ ,.http_major= 1
1262
+ ,.http_minor= 1
1263
+ ,.status_code= 404
1264
+ ,.response_status= "Not Found"
1265
+ ,.num_headers= 0
1266
+ ,.headers= {}
1267
+ ,.body_size= 0
1268
+ ,.body= ""
1269
+ }
1270
+
1271
+ #define NO_REASON_PHRASE 3
1272
+ , {.name= "301 no response phrase"
1273
+ ,.type= HTTP_RESPONSE
1274
+ ,.raw= "HTTP/1.1 301\r\n\r\n"
1275
+ ,.should_keep_alive = FALSE
1276
+ ,.message_complete_on_eof= TRUE
1277
+ ,.http_major= 1
1278
+ ,.http_minor= 1
1279
+ ,.status_code= 301
1280
+ ,.response_status= ""
1281
+ ,.num_headers= 0
1282
+ ,.headers= {}
1283
+ ,.body= ""
1284
+ }
1285
+
1286
+ #define TRAILING_SPACE_ON_CHUNKED_BODY 4
1287
+ , {.name="200 trailing space on chunked body"
1288
+ ,.type= HTTP_RESPONSE
1289
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1290
+ "Content-Type: text/plain\r\n"
1291
+ "Transfer-Encoding: chunked\r\n"
1292
+ "\r\n"
1293
+ "25 \r\n"
1294
+ "This is the data in the first chunk\r\n"
1295
+ "\r\n"
1296
+ "1C\r\n"
1297
+ "and this is the second one\r\n"
1298
+ "\r\n"
1299
+ "0 \r\n"
1300
+ "\r\n"
1301
+ ,.should_keep_alive= TRUE
1302
+ ,.message_complete_on_eof= FALSE
1303
+ ,.http_major= 1
1304
+ ,.http_minor= 1
1305
+ ,.status_code= 200
1306
+ ,.response_status= "OK"
1307
+ ,.num_headers= 2
1308
+ ,.headers=
1309
+ { {"Content-Type", "text/plain" }
1310
+ , {"Transfer-Encoding", "chunked" }
1311
+ }
1312
+ ,.body_size = 37+28
1313
+ ,.body =
1314
+ "This is the data in the first chunk\r\n"
1315
+ "and this is the second one\r\n"
1316
+ ,.num_chunks_complete= 3
1317
+ ,.chunk_lengths= { 0x25, 0x1c }
1318
+ }
1319
+
1320
+ #define NO_CARRIAGE_RET 5
1321
+ , {.name="no carriage ret"
1322
+ ,.type= HTTP_RESPONSE
1323
+ ,.raw= "HTTP/1.1 200 OK\n"
1324
+ "Content-Type: text/html; charset=utf-8\n"
1325
+ "Connection: close\n"
1326
+ "\n"
1327
+ "these headers are from http://news.ycombinator.com/"
1328
+ ,.should_keep_alive= FALSE
1329
+ ,.message_complete_on_eof= TRUE
1330
+ ,.http_major= 1
1331
+ ,.http_minor= 1
1332
+ ,.status_code= 200
1333
+ ,.response_status= "OK"
1334
+ ,.num_headers= 2
1335
+ ,.headers=
1336
+ { {"Content-Type", "text/html; charset=utf-8" }
1337
+ , {"Connection", "close" }
1338
+ }
1339
+ ,.body= "these headers are from http://news.ycombinator.com/"
1340
+ }
1341
+
1342
+ #define PROXY_CONNECTION 6
1343
+ , {.name="proxy connection"
1344
+ ,.type= HTTP_RESPONSE
1345
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1346
+ "Content-Type: text/html; charset=UTF-8\r\n"
1347
+ "Content-Length: 11\r\n"
1348
+ "Proxy-Connection: close\r\n"
1349
+ "Date: Thu, 31 Dec 2009 20:55:48 +0000\r\n"
1350
+ "\r\n"
1351
+ "hello world"
1352
+ ,.should_keep_alive= FALSE
1353
+ ,.message_complete_on_eof= FALSE
1354
+ ,.http_major= 1
1355
+ ,.http_minor= 1
1356
+ ,.status_code= 200
1357
+ ,.response_status= "OK"
1358
+ ,.num_headers= 4
1359
+ ,.headers=
1360
+ { {"Content-Type", "text/html; charset=UTF-8" }
1361
+ , {"Content-Length", "11" }
1362
+ , {"Proxy-Connection", "close" }
1363
+ , {"Date", "Thu, 31 Dec 2009 20:55:48 +0000"}
1364
+ }
1365
+ ,.body= "hello world"
1366
+ }
1367
+
1368
+ #define UNDERSTORE_HEADER_KEY 7
1369
+ // shown by
1370
+ // curl -o /dev/null -v "http://ad.doubleclick.net/pfadx/DARTSHELLCONFIGXML;dcmt=text/xml;"
1371
+ , {.name="underscore header key"
1372
+ ,.type= HTTP_RESPONSE
1373
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1374
+ "Server: DCLK-AdSvr\r\n"
1375
+ "Content-Type: text/xml\r\n"
1376
+ "Content-Length: 0\r\n"
1377
+ "DCLK_imp: v7;x;114750856;0-0;0;17820020;0/0;21603567/21621457/1;;~okv=;dcmt=text/xml;;~cs=o\r\n\r\n"
1378
+ ,.should_keep_alive= TRUE
1379
+ ,.message_complete_on_eof= FALSE
1380
+ ,.http_major= 1
1381
+ ,.http_minor= 1
1382
+ ,.status_code= 200
1383
+ ,.response_status= "OK"
1384
+ ,.num_headers= 4
1385
+ ,.headers=
1386
+ { {"Server", "DCLK-AdSvr" }
1387
+ , {"Content-Type", "text/xml" }
1388
+ , {"Content-Length", "0" }
1389
+ , {"DCLK_imp", "v7;x;114750856;0-0;0;17820020;0/0;21603567/21621457/1;;~okv=;dcmt=text/xml;;~cs=o" }
1390
+ }
1391
+ ,.body= ""
1392
+ }
1393
+
1394
+ #define BONJOUR_MADAME_FR 8
1395
+ /* The client should not merge two headers fields when the first one doesn't
1396
+ * have a value.
1397
+ */
1398
+ , {.name= "bonjourmadame.fr"
1399
+ ,.type= HTTP_RESPONSE
1400
+ ,.raw= "HTTP/1.0 301 Moved Permanently\r\n"
1401
+ "Date: Thu, 03 Jun 2010 09:56:32 GMT\r\n"
1402
+ "Server: Apache/2.2.3 (Red Hat)\r\n"
1403
+ "Cache-Control: public\r\n"
1404
+ "Pragma: \r\n"
1405
+ "Location: http://www.bonjourmadame.fr/\r\n"
1406
+ "Vary: Accept-Encoding\r\n"
1407
+ "Content-Length: 0\r\n"
1408
+ "Content-Type: text/html; charset=UTF-8\r\n"
1409
+ "Connection: keep-alive\r\n"
1410
+ "\r\n"
1411
+ ,.should_keep_alive= TRUE
1412
+ ,.message_complete_on_eof= FALSE
1413
+ ,.http_major= 1
1414
+ ,.http_minor= 0
1415
+ ,.status_code= 301
1416
+ ,.response_status= "Moved Permanently"
1417
+ ,.num_headers= 9
1418
+ ,.headers=
1419
+ { { "Date", "Thu, 03 Jun 2010 09:56:32 GMT" }
1420
+ , { "Server", "Apache/2.2.3 (Red Hat)" }
1421
+ , { "Cache-Control", "public" }
1422
+ , { "Pragma", "" }
1423
+ , { "Location", "http://www.bonjourmadame.fr/" }
1424
+ , { "Vary", "Accept-Encoding" }
1425
+ , { "Content-Length", "0" }
1426
+ , { "Content-Type", "text/html; charset=UTF-8" }
1427
+ , { "Connection", "keep-alive" }
1428
+ }
1429
+ ,.body= ""
1430
+ }
1431
+
1432
+ #define RES_FIELD_UNDERSCORE 9
1433
+ /* Should handle spaces in header fields */
1434
+ , {.name= "field underscore"
1435
+ ,.type= HTTP_RESPONSE
1436
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1437
+ "Date: Tue, 28 Sep 2010 01:14:13 GMT\r\n"
1438
+ "Server: Apache\r\n"
1439
+ "Cache-Control: no-cache, must-revalidate\r\n"
1440
+ "Expires: Mon, 26 Jul 1997 05:00:00 GMT\r\n"
1441
+ ".et-Cookie: PlaxoCS=1274804622353690521; path=/; domain=.plaxo.com\r\n"
1442
+ "Vary: Accept-Encoding\r\n"
1443
+ "_eep-Alive: timeout=45\r\n" /* semantic value ignored */
1444
+ "_onnection: Keep-Alive\r\n" /* semantic value ignored */
1445
+ "Transfer-Encoding: chunked\r\n"
1446
+ "Content-Type: text/html\r\n"
1447
+ "Connection: close\r\n"
1448
+ "\r\n"
1449
+ "0\r\n\r\n"
1450
+ ,.should_keep_alive= FALSE
1451
+ ,.message_complete_on_eof= FALSE
1452
+ ,.http_major= 1
1453
+ ,.http_minor= 1
1454
+ ,.status_code= 200
1455
+ ,.response_status= "OK"
1456
+ ,.num_headers= 11
1457
+ ,.headers=
1458
+ { { "Date", "Tue, 28 Sep 2010 01:14:13 GMT" }
1459
+ , { "Server", "Apache" }
1460
+ , { "Cache-Control", "no-cache, must-revalidate" }
1461
+ , { "Expires", "Mon, 26 Jul 1997 05:00:00 GMT" }
1462
+ , { ".et-Cookie", "PlaxoCS=1274804622353690521; path=/; domain=.plaxo.com" }
1463
+ , { "Vary", "Accept-Encoding" }
1464
+ , { "_eep-Alive", "timeout=45" }
1465
+ , { "_onnection", "Keep-Alive" }
1466
+ , { "Transfer-Encoding", "chunked" }
1467
+ , { "Content-Type", "text/html" }
1468
+ , { "Connection", "close" }
1469
+ }
1470
+ ,.body= ""
1471
+ ,.num_chunks_complete= 1
1472
+ ,.chunk_lengths= {}
1473
+ }
1474
+
1475
+ #define NON_ASCII_IN_STATUS_LINE 10
1476
+ /* Should handle non-ASCII in status line */
1477
+ , {.name= "non-ASCII in status line"
1478
+ ,.type= HTTP_RESPONSE
1479
+ ,.raw= "HTTP/1.1 500 Oriëntatieprobleem\r\n"
1480
+ "Date: Fri, 5 Nov 2010 23:07:12 GMT+2\r\n"
1481
+ "Content-Length: 0\r\n"
1482
+ "Connection: close\r\n"
1483
+ "\r\n"
1484
+ ,.should_keep_alive= FALSE
1485
+ ,.message_complete_on_eof= FALSE
1486
+ ,.http_major= 1
1487
+ ,.http_minor= 1
1488
+ ,.status_code= 500
1489
+ ,.response_status= "Oriëntatieprobleem"
1490
+ ,.num_headers= 3
1491
+ ,.headers=
1492
+ { { "Date", "Fri, 5 Nov 2010 23:07:12 GMT+2" }
1493
+ , { "Content-Length", "0" }
1494
+ , { "Connection", "close" }
1495
+ }
1496
+ ,.body= ""
1497
+ }
1498
+
1499
+ #define HTTP_VERSION_0_9 11
1500
+ /* Should handle HTTP/0.9 */
1501
+ , {.name= "http version 0.9"
1502
+ ,.type= HTTP_RESPONSE
1503
+ ,.raw= "HTTP/0.9 200 OK\r\n"
1504
+ "\r\n"
1505
+ ,.should_keep_alive= FALSE
1506
+ ,.message_complete_on_eof= TRUE
1507
+ ,.http_major= 0
1508
+ ,.http_minor= 9
1509
+ ,.status_code= 200
1510
+ ,.response_status= "OK"
1511
+ ,.num_headers= 0
1512
+ ,.headers=
1513
+ {}
1514
+ ,.body= ""
1515
+ }
1516
+
1517
+ #define NO_CONTENT_LENGTH_NO_TRANSFER_ENCODING_RESPONSE 12
1518
+ /* The client should wait for the server's EOF. That is, when neither
1519
+ * content-length nor transfer-encoding is specified, the end of body
1520
+ * is specified by the EOF.
1521
+ */
1522
+ , {.name= "neither content-length nor transfer-encoding response"
1523
+ ,.type= HTTP_RESPONSE
1524
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1525
+ "Content-Type: text/plain\r\n"
1526
+ "\r\n"
1527
+ "hello world"
1528
+ ,.should_keep_alive= FALSE
1529
+ ,.message_complete_on_eof= TRUE
1530
+ ,.http_major= 1
1531
+ ,.http_minor= 1
1532
+ ,.status_code= 200
1533
+ ,.response_status= "OK"
1534
+ ,.num_headers= 1
1535
+ ,.headers=
1536
+ { { "Content-Type", "text/plain" }
1537
+ }
1538
+ ,.body= "hello world"
1539
+ }
1540
+
1541
+ #define NO_BODY_HTTP10_KA_200 13
1542
+ , {.name= "HTTP/1.0 with keep-alive and EOF-terminated 200 status"
1543
+ ,.type= HTTP_RESPONSE
1544
+ ,.raw= "HTTP/1.0 200 OK\r\n"
1545
+ "Connection: keep-alive\r\n"
1546
+ "\r\n"
1547
+ ,.should_keep_alive= FALSE
1548
+ ,.message_complete_on_eof= TRUE
1549
+ ,.http_major= 1
1550
+ ,.http_minor= 0
1551
+ ,.status_code= 200
1552
+ ,.response_status= "OK"
1553
+ ,.num_headers= 1
1554
+ ,.headers=
1555
+ { { "Connection", "keep-alive" }
1556
+ }
1557
+ ,.body_size= 0
1558
+ ,.body= ""
1559
+ }
1560
+
1561
+ #define NO_BODY_HTTP10_KA_204 14
1562
+ , {.name= "HTTP/1.0 with keep-alive and a 204 status"
1563
+ ,.type= HTTP_RESPONSE
1564
+ ,.raw= "HTTP/1.0 204 No content\r\n"
1565
+ "Connection: keep-alive\r\n"
1566
+ "\r\n"
1567
+ ,.should_keep_alive= TRUE
1568
+ ,.message_complete_on_eof= FALSE
1569
+ ,.http_major= 1
1570
+ ,.http_minor= 0
1571
+ ,.status_code= 204
1572
+ ,.response_status= "No content"
1573
+ ,.num_headers= 1
1574
+ ,.headers=
1575
+ { { "Connection", "keep-alive" }
1576
+ }
1577
+ ,.body_size= 0
1578
+ ,.body= ""
1579
+ }
1580
+
1581
+ #define NO_BODY_HTTP11_KA_200 15
1582
+ , {.name= "HTTP/1.1 with an EOF-terminated 200 status"
1583
+ ,.type= HTTP_RESPONSE
1584
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1585
+ "\r\n"
1586
+ ,.should_keep_alive= FALSE
1587
+ ,.message_complete_on_eof= TRUE
1588
+ ,.http_major= 1
1589
+ ,.http_minor= 1
1590
+ ,.status_code= 200
1591
+ ,.response_status= "OK"
1592
+ ,.num_headers= 0
1593
+ ,.headers={}
1594
+ ,.body_size= 0
1595
+ ,.body= ""
1596
+ }
1597
+
1598
+ #define NO_BODY_HTTP11_KA_204 16
1599
+ , {.name= "HTTP/1.1 with a 204 status"
1600
+ ,.type= HTTP_RESPONSE
1601
+ ,.raw= "HTTP/1.1 204 No content\r\n"
1602
+ "\r\n"
1603
+ ,.should_keep_alive= TRUE
1604
+ ,.message_complete_on_eof= FALSE
1605
+ ,.http_major= 1
1606
+ ,.http_minor= 1
1607
+ ,.status_code= 204
1608
+ ,.response_status= "No content"
1609
+ ,.num_headers= 0
1610
+ ,.headers={}
1611
+ ,.body_size= 0
1612
+ ,.body= ""
1613
+ }
1614
+
1615
+ #define NO_BODY_HTTP11_NOKA_204 17
1616
+ , {.name= "HTTP/1.1 with a 204 status and keep-alive disabled"
1617
+ ,.type= HTTP_RESPONSE
1618
+ ,.raw= "HTTP/1.1 204 No content\r\n"
1619
+ "Connection: close\r\n"
1620
+ "\r\n"
1621
+ ,.should_keep_alive= FALSE
1622
+ ,.message_complete_on_eof= FALSE
1623
+ ,.http_major= 1
1624
+ ,.http_minor= 1
1625
+ ,.status_code= 204
1626
+ ,.response_status= "No content"
1627
+ ,.num_headers= 1
1628
+ ,.headers=
1629
+ { { "Connection", "close" }
1630
+ }
1631
+ ,.body_size= 0
1632
+ ,.body= ""
1633
+ }
1634
+
1635
+ #define NO_BODY_HTTP11_KA_CHUNKED_200 18
1636
+ , {.name= "HTTP/1.1 with chunked endocing and a 200 response"
1637
+ ,.type= HTTP_RESPONSE
1638
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1639
+ "Transfer-Encoding: chunked\r\n"
1640
+ "\r\n"
1641
+ "0\r\n"
1642
+ "\r\n"
1643
+ ,.should_keep_alive= TRUE
1644
+ ,.message_complete_on_eof= FALSE
1645
+ ,.http_major= 1
1646
+ ,.http_minor= 1
1647
+ ,.status_code= 200
1648
+ ,.response_status= "OK"
1649
+ ,.num_headers= 1
1650
+ ,.headers=
1651
+ { { "Transfer-Encoding", "chunked" }
1652
+ }
1653
+ ,.body_size= 0
1654
+ ,.body= ""
1655
+ ,.num_chunks_complete= 1
1656
+ }
1657
+
1658
+ #if !HTTP_PARSER_STRICT
1659
+ #define SPACE_IN_FIELD_RES 19
1660
+ /* Should handle spaces in header fields */
1661
+ , {.name= "field space"
1662
+ ,.type= HTTP_RESPONSE
1663
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1664
+ "Server: Microsoft-IIS/6.0\r\n"
1665
+ "X-Powered-By: ASP.NET\r\n"
1666
+ "en-US Content-Type: text/xml\r\n" /* this is the problem */
1667
+ "Content-Type: text/xml\r\n"
1668
+ "Content-Length: 16\r\n"
1669
+ "Date: Fri, 23 Jul 2010 18:45:38 GMT\r\n"
1670
+ "Connection: keep-alive\r\n"
1671
+ "\r\n"
1672
+ "<xml>hello</xml>" /* fake body */
1673
+ ,.should_keep_alive= TRUE
1674
+ ,.message_complete_on_eof= FALSE
1675
+ ,.http_major= 1
1676
+ ,.http_minor= 1
1677
+ ,.status_code= 200
1678
+ ,.response_status= "OK"
1679
+ ,.num_headers= 7
1680
+ ,.headers=
1681
+ { { "Server", "Microsoft-IIS/6.0" }
1682
+ , { "X-Powered-By", "ASP.NET" }
1683
+ , { "en-US Content-Type", "text/xml" }
1684
+ , { "Content-Type", "text/xml" }
1685
+ , { "Content-Length", "16" }
1686
+ , { "Date", "Fri, 23 Jul 2010 18:45:38 GMT" }
1687
+ , { "Connection", "keep-alive" }
1688
+ }
1689
+ ,.body= "<xml>hello</xml>"
1690
+ }
1691
+ #endif /* !HTTP_PARSER_STRICT */
1692
+
1693
+ #define AMAZON_COM 20
1694
+ , {.name= "amazon.com"
1695
+ ,.type= HTTP_RESPONSE
1696
+ ,.raw= "HTTP/1.1 301 MovedPermanently\r\n"
1697
+ "Date: Wed, 15 May 2013 17:06:33 GMT\r\n"
1698
+ "Server: Server\r\n"
1699
+ "x-amz-id-1: 0GPHKXSJQ826RK7GZEB2\r\n"
1700
+ "p3p: policyref=\"http://www.amazon.com/w3c/p3p.xml\",CP=\"CAO DSP LAW CUR ADM IVAo IVDo CONo OTPo OUR DELi PUBi OTRi BUS PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA HEA PRE LOC GOV OTC \"\r\n"
1701
+ "x-amz-id-2: STN69VZxIFSz9YJLbz1GDbxpbjG6Qjmmq5E3DxRhOUw+Et0p4hr7c/Q8qNcx4oAD\r\n"
1702
+ "Location: http://www.amazon.com/Dan-Brown/e/B000AP9DSU/ref=s9_pop_gw_al1?_encoding=UTF8&refinementId=618073011&pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=0SHYY5BZXN3KR20BNFAY&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846\r\n"
1703
+ "Vary: Accept-Encoding,User-Agent\r\n"
1704
+ "Content-Type: text/html; charset=ISO-8859-1\r\n"
1705
+ "Transfer-Encoding: chunked\r\n"
1706
+ "\r\n"
1707
+ "1\r\n"
1708
+ "\n\r\n"
1709
+ "0\r\n"
1710
+ "\r\n"
1711
+ ,.should_keep_alive= TRUE
1712
+ ,.message_complete_on_eof= FALSE
1713
+ ,.http_major= 1
1714
+ ,.http_minor= 1
1715
+ ,.status_code= 301
1716
+ ,.response_status= "MovedPermanently"
1717
+ ,.num_headers= 9
1718
+ ,.headers= { { "Date", "Wed, 15 May 2013 17:06:33 GMT" }
1719
+ , { "Server", "Server" }
1720
+ , { "x-amz-id-1", "0GPHKXSJQ826RK7GZEB2" }
1721
+ , { "p3p", "policyref=\"http://www.amazon.com/w3c/p3p.xml\",CP=\"CAO DSP LAW CUR ADM IVAo IVDo CONo OTPo OUR DELi PUBi OTRi BUS PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA HEA PRE LOC GOV OTC \"" }
1722
+ , { "x-amz-id-2", "STN69VZxIFSz9YJLbz1GDbxpbjG6Qjmmq5E3DxRhOUw+Et0p4hr7c/Q8qNcx4oAD" }
1723
+ , { "Location", "http://www.amazon.com/Dan-Brown/e/B000AP9DSU/ref=s9_pop_gw_al1?_encoding=UTF8&refinementId=618073011&pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=0SHYY5BZXN3KR20BNFAY&pf_rd_t=101&pf_rd_p=1263340922&pf_rd_i=507846" }
1724
+ , { "Vary", "Accept-Encoding,User-Agent" }
1725
+ , { "Content-Type", "text/html; charset=ISO-8859-1" }
1726
+ , { "Transfer-Encoding", "chunked" }
1727
+ }
1728
+ ,.body= "\n"
1729
+ ,.num_chunks_complete= 2
1730
+ ,.chunk_lengths= { 1 }
1731
+ }
1732
+
1733
+ #define EMPTY_REASON_PHRASE_AFTER_SPACE 20
1734
+ , {.name= "empty reason phrase after space"
1735
+ ,.type= HTTP_RESPONSE
1736
+ ,.raw= "HTTP/1.1 200 \r\n"
1737
+ "\r\n"
1738
+ ,.should_keep_alive= FALSE
1739
+ ,.message_complete_on_eof= TRUE
1740
+ ,.http_major= 1
1741
+ ,.http_minor= 1
1742
+ ,.status_code= 200
1743
+ ,.response_status= ""
1744
+ ,.num_headers= 0
1745
+ ,.headers= {}
1746
+ ,.body= ""
1747
+ }
1748
+
1749
+ #define CONTENT_LENGTH_X 21
1750
+ , {.name= "Content-Length-X"
1751
+ ,.type= HTTP_RESPONSE
1752
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1753
+ "Content-Length-X: 0\r\n"
1754
+ "Transfer-Encoding: chunked\r\n"
1755
+ "\r\n"
1756
+ "2\r\n"
1757
+ "OK\r\n"
1758
+ "0\r\n"
1759
+ "\r\n"
1760
+ ,.should_keep_alive= TRUE
1761
+ ,.message_complete_on_eof= FALSE
1762
+ ,.http_major= 1
1763
+ ,.http_minor= 1
1764
+ ,.status_code= 200
1765
+ ,.response_status= "OK"
1766
+ ,.num_headers= 2
1767
+ ,.headers= { { "Content-Length-X", "0" }
1768
+ , { "Transfer-Encoding", "chunked" }
1769
+ }
1770
+ ,.body= "OK"
1771
+ ,.num_chunks_complete= 2
1772
+ ,.chunk_lengths= { 2 }
1773
+ }
1774
+
1775
+ #define HTTP_101_RESPONSE_WITH_UPGRADE_HEADER 22
1776
+ , {.name= "HTTP 101 response with Upgrade header"
1777
+ ,.type= HTTP_RESPONSE
1778
+ ,.raw= "HTTP/1.1 101 Switching Protocols\r\n"
1779
+ "Connection: upgrade\r\n"
1780
+ "Upgrade: h2c\r\n"
1781
+ "\r\n"
1782
+ "proto"
1783
+ ,.should_keep_alive= TRUE
1784
+ ,.message_complete_on_eof= FALSE
1785
+ ,.http_major= 1
1786
+ ,.http_minor= 1
1787
+ ,.status_code= 101
1788
+ ,.response_status= "Switching Protocols"
1789
+ ,.upgrade= "proto"
1790
+ ,.num_headers= 2
1791
+ ,.headers=
1792
+ { { "Connection", "upgrade" }
1793
+ , { "Upgrade", "h2c" }
1794
+ }
1795
+ }
1796
+
1797
+ #define HTTP_101_RESPONSE_WITH_UPGRADE_HEADER_AND_CONTENT_LENGTH 23
1798
+ , {.name= "HTTP 101 response with Upgrade and Content-Length header"
1799
+ ,.type= HTTP_RESPONSE
1800
+ ,.raw= "HTTP/1.1 101 Switching Protocols\r\n"
1801
+ "Connection: upgrade\r\n"
1802
+ "Upgrade: h2c\r\n"
1803
+ "Content-Length: 4\r\n"
1804
+ "\r\n"
1805
+ "body"
1806
+ "proto"
1807
+ ,.should_keep_alive= TRUE
1808
+ ,.message_complete_on_eof= FALSE
1809
+ ,.http_major= 1
1810
+ ,.http_minor= 1
1811
+ ,.status_code= 101
1812
+ ,.response_status= "Switching Protocols"
1813
+ ,.body= "body"
1814
+ ,.upgrade= "proto"
1815
+ ,.num_headers= 3
1816
+ ,.headers=
1817
+ { { "Connection", "upgrade" }
1818
+ , { "Upgrade", "h2c" }
1819
+ , { "Content-Length", "4" }
1820
+ }
1821
+ }
1822
+
1823
+ #define HTTP_101_RESPONSE_WITH_UPGRADE_HEADER_AND_TRANSFER_ENCODING 24
1824
+ , {.name= "HTTP 101 response with Upgrade and Transfer-Encoding header"
1825
+ ,.type= HTTP_RESPONSE
1826
+ ,.raw= "HTTP/1.1 101 Switching Protocols\r\n"
1827
+ "Connection: upgrade\r\n"
1828
+ "Upgrade: h2c\r\n"
1829
+ "Transfer-Encoding: chunked\r\n"
1830
+ "\r\n"
1831
+ "2\r\n"
1832
+ "bo\r\n"
1833
+ "2\r\n"
1834
+ "dy\r\n"
1835
+ "0\r\n"
1836
+ "\r\n"
1837
+ "proto"
1838
+ ,.should_keep_alive= TRUE
1839
+ ,.message_complete_on_eof= FALSE
1840
+ ,.http_major= 1
1841
+ ,.http_minor= 1
1842
+ ,.status_code= 101
1843
+ ,.response_status= "Switching Protocols"
1844
+ ,.body= "body"
1845
+ ,.upgrade= "proto"
1846
+ ,.num_headers= 3
1847
+ ,.headers=
1848
+ { { "Connection", "upgrade" }
1849
+ , { "Upgrade", "h2c" }
1850
+ , { "Transfer-Encoding", "chunked" }
1851
+ }
1852
+ ,.num_chunks_complete= 3
1853
+ ,.chunk_lengths= { 2, 2 }
1854
+ }
1855
+
1856
+ #define HTTP_200_RESPONSE_WITH_UPGRADE_HEADER 25
1857
+ , {.name= "HTTP 200 response with Upgrade header"
1858
+ ,.type= HTTP_RESPONSE
1859
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1860
+ "Connection: upgrade\r\n"
1861
+ "Upgrade: h2c\r\n"
1862
+ "\r\n"
1863
+ "body"
1864
+ ,.should_keep_alive= FALSE
1865
+ ,.message_complete_on_eof= TRUE
1866
+ ,.http_major= 1
1867
+ ,.http_minor= 1
1868
+ ,.status_code= 200
1869
+ ,.response_status= "OK"
1870
+ ,.body= "body"
1871
+ ,.upgrade= NULL
1872
+ ,.num_headers= 2
1873
+ ,.headers=
1874
+ { { "Connection", "upgrade" }
1875
+ , { "Upgrade", "h2c" }
1876
+ }
1877
+ }
1878
+
1879
+ #define HTTP_200_RESPONSE_WITH_UPGRADE_HEADER_AND_CONTENT_LENGTH 26
1880
+ , {.name= "HTTP 200 response with Upgrade and Content-Length header"
1881
+ ,.type= HTTP_RESPONSE
1882
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1883
+ "Connection: upgrade\r\n"
1884
+ "Upgrade: h2c\r\n"
1885
+ "Content-Length: 4\r\n"
1886
+ "\r\n"
1887
+ "body"
1888
+ ,.should_keep_alive= TRUE
1889
+ ,.message_complete_on_eof= FALSE
1890
+ ,.http_major= 1
1891
+ ,.http_minor= 1
1892
+ ,.status_code= 200
1893
+ ,.response_status= "OK"
1894
+ ,.num_headers= 3
1895
+ ,.body= "body"
1896
+ ,.upgrade= NULL
1897
+ ,.headers=
1898
+ { { "Connection", "upgrade" }
1899
+ , { "Upgrade", "h2c" }
1900
+ , { "Content-Length", "4" }
1901
+ }
1902
+ }
1903
+
1904
+ #define HTTP_200_RESPONSE_WITH_UPGRADE_HEADER_AND_TRANSFER_ENCODING 27
1905
+ , {.name= "HTTP 200 response with Upgrade and Transfer-Encoding header"
1906
+ ,.type= HTTP_RESPONSE
1907
+ ,.raw= "HTTP/1.1 200 OK\r\n"
1908
+ "Connection: upgrade\r\n"
1909
+ "Upgrade: h2c\r\n"
1910
+ "Transfer-Encoding: chunked\r\n"
1911
+ "\r\n"
1912
+ "2\r\n"
1913
+ "bo\r\n"
1914
+ "2\r\n"
1915
+ "dy\r\n"
1916
+ "0\r\n"
1917
+ "\r\n"
1918
+ ,.should_keep_alive= TRUE
1919
+ ,.message_complete_on_eof= FALSE
1920
+ ,.http_major= 1
1921
+ ,.http_minor= 1
1922
+ ,.status_code= 200
1923
+ ,.response_status= "OK"
1924
+ ,.num_headers= 3
1925
+ ,.body= "body"
1926
+ ,.upgrade= NULL
1927
+ ,.headers=
1928
+ { { "Connection", "upgrade" }
1929
+ , { "Upgrade", "h2c" }
1930
+ , { "Transfer-Encoding", "chunked" }
1931
+ }
1932
+ ,.num_chunks_complete= 3
1933
+ ,.chunk_lengths= { 2, 2 }
1934
+ }
1935
+
1936
+ , {.name= NULL } /* sentinel */
1937
+ };
1938
+
1939
+ /* strnlen() is a POSIX.2008 addition. Can't rely on it being available so
1940
+ * define it ourselves.
1941
+ */
1942
+ size_t
1943
+ strnlen(const char *s, size_t maxlen)
1944
+ {
1945
+ const char *p;
1946
+
1947
+ p = memchr(s, '\0', maxlen);
1948
+ if (p == NULL)
1949
+ return maxlen;
1950
+
1951
+ return p - s;
1952
+ }
1953
+
1954
+ size_t
1955
+ strlncat(char *dst, size_t len, const char *src, size_t n)
1956
+ {
1957
+ size_t slen;
1958
+ size_t dlen;
1959
+ size_t rlen;
1960
+ size_t ncpy;
1961
+
1962
+ slen = strnlen(src, n);
1963
+ dlen = strnlen(dst, len);
1964
+
1965
+ if (dlen < len) {
1966
+ rlen = len - dlen;
1967
+ ncpy = slen < rlen ? slen : (rlen - 1);
1968
+ memcpy(dst + dlen, src, ncpy);
1969
+ dst[dlen + ncpy] = '\0';
1970
+ }
1971
+
1972
+ assert(len > slen + dlen);
1973
+ return slen + dlen;
1974
+ }
1975
+
1976
+ size_t
1977
+ strlcat(char *dst, const char *src, size_t len)
1978
+ {
1979
+ return strlncat(dst, len, src, (size_t) -1);
1980
+ }
1981
+
1982
+ size_t
1983
+ strlncpy(char *dst, size_t len, const char *src, size_t n)
1984
+ {
1985
+ size_t slen;
1986
+ size_t ncpy;
1987
+
1988
+ slen = strnlen(src, n);
1989
+
1990
+ if (len > 0) {
1991
+ ncpy = slen < len ? slen : (len - 1);
1992
+ memcpy(dst, src, ncpy);
1993
+ dst[ncpy] = '\0';
1994
+ }
1995
+
1996
+ assert(len > slen);
1997
+ return slen;
1998
+ }
1999
+
2000
+ size_t
2001
+ strlcpy(char *dst, const char *src, size_t len)
2002
+ {
2003
+ return strlncpy(dst, len, src, (size_t) -1);
2004
+ }
2005
+
2006
+ int
2007
+ request_url_cb (http_parser *p, const char *buf, size_t len)
2008
+ {
2009
+ assert(p == parser);
2010
+ strlncat(messages[num_messages].request_url,
2011
+ sizeof(messages[num_messages].request_url),
2012
+ buf,
2013
+ len);
2014
+ return 0;
2015
+ }
2016
+
2017
+ int
2018
+ header_field_cb (http_parser *p, const char *buf, size_t len)
2019
+ {
2020
+ assert(p == parser);
2021
+ struct message *m = &messages[num_messages];
2022
+
2023
+ if (m->last_header_element != FIELD)
2024
+ m->num_headers++;
2025
+
2026
+ strlncat(m->headers[m->num_headers-1][0],
2027
+ sizeof(m->headers[m->num_headers-1][0]),
2028
+ buf,
2029
+ len);
2030
+
2031
+ m->last_header_element = FIELD;
2032
+
2033
+ return 0;
2034
+ }
2035
+
2036
+ int
2037
+ header_value_cb (http_parser *p, const char *buf, size_t len)
2038
+ {
2039
+ assert(p == parser);
2040
+ struct message *m = &messages[num_messages];
2041
+
2042
+ strlncat(m->headers[m->num_headers-1][1],
2043
+ sizeof(m->headers[m->num_headers-1][1]),
2044
+ buf,
2045
+ len);
2046
+
2047
+ m->last_header_element = VALUE;
2048
+
2049
+ return 0;
2050
+ }
2051
+
2052
+ void
2053
+ check_body_is_final (const http_parser *p)
2054
+ {
2055
+ if (messages[num_messages].body_is_final) {
2056
+ fprintf(stderr, "\n\n *** Error http_body_is_final() should return 1 "
2057
+ "on last on_body callback call "
2058
+ "but it doesn't! ***\n\n");
2059
+ assert(0);
2060
+ abort();
2061
+ }
2062
+ messages[num_messages].body_is_final = http_body_is_final(p);
2063
+ }
2064
+
2065
+ int
2066
+ body_cb (http_parser *p, const char *buf, size_t len)
2067
+ {
2068
+ assert(p == parser);
2069
+ strlncat(messages[num_messages].body,
2070
+ sizeof(messages[num_messages].body),
2071
+ buf,
2072
+ len);
2073
+ messages[num_messages].body_size += len;
2074
+ check_body_is_final(p);
2075
+ // printf("body_cb: '%s'\n", requests[num_messages].body);
2076
+ return 0;
2077
+ }
2078
+
2079
+ int
2080
+ count_body_cb (http_parser *p, const char *buf, size_t len)
2081
+ {
2082
+ assert(p == parser);
2083
+ assert(buf);
2084
+ messages[num_messages].body_size += len;
2085
+ check_body_is_final(p);
2086
+ return 0;
2087
+ }
2088
+
2089
+ int
2090
+ message_begin_cb (http_parser *p)
2091
+ {
2092
+ assert(p == parser);
2093
+ messages[num_messages].message_begin_cb_called = TRUE;
2094
+ return 0;
2095
+ }
2096
+
2097
+ int
2098
+ headers_complete_cb (http_parser *p)
2099
+ {
2100
+ assert(p == parser);
2101
+ messages[num_messages].method = parser->method;
2102
+ messages[num_messages].status_code = parser->status_code;
2103
+ messages[num_messages].http_major = parser->http_major;
2104
+ messages[num_messages].http_minor = parser->http_minor;
2105
+ messages[num_messages].headers_complete_cb_called = TRUE;
2106
+ messages[num_messages].should_keep_alive = http_should_keep_alive(parser);
2107
+ return 0;
2108
+ }
2109
+
2110
+ int
2111
+ message_complete_cb (http_parser *p)
2112
+ {
2113
+ assert(p == parser);
2114
+ if (messages[num_messages].should_keep_alive != http_should_keep_alive(parser))
2115
+ {
2116
+ fprintf(stderr, "\n\n *** Error http_should_keep_alive() should have same "
2117
+ "value in both on_message_complete and on_headers_complete "
2118
+ "but it doesn't! ***\n\n");
2119
+ assert(0);
2120
+ abort();
2121
+ }
2122
+
2123
+ if (messages[num_messages].body_size &&
2124
+ http_body_is_final(p) &&
2125
+ !messages[num_messages].body_is_final)
2126
+ {
2127
+ fprintf(stderr, "\n\n *** Error http_body_is_final() should return 1 "
2128
+ "on last on_body callback call "
2129
+ "but it doesn't! ***\n\n");
2130
+ assert(0);
2131
+ abort();
2132
+ }
2133
+
2134
+ messages[num_messages].message_complete_cb_called = TRUE;
2135
+
2136
+ messages[num_messages].message_complete_on_eof = currently_parsing_eof;
2137
+
2138
+ num_messages++;
2139
+ return 0;
2140
+ }
2141
+
2142
+ int
2143
+ response_status_cb (http_parser *p, const char *buf, size_t len)
2144
+ {
2145
+ assert(p == parser);
2146
+
2147
+ messages[num_messages].status_cb_called = TRUE;
2148
+
2149
+ strlncat(messages[num_messages].response_status,
2150
+ sizeof(messages[num_messages].response_status),
2151
+ buf,
2152
+ len);
2153
+ return 0;
2154
+ }
2155
+
2156
+ int
2157
+ chunk_header_cb (http_parser *p)
2158
+ {
2159
+ assert(p == parser);
2160
+ int chunk_idx = messages[num_messages].num_chunks;
2161
+ messages[num_messages].num_chunks++;
2162
+ if (chunk_idx < MAX_CHUNKS) {
2163
+ messages[num_messages].chunk_lengths[chunk_idx] = p->content_length;
2164
+ }
2165
+
2166
+ return 0;
2167
+ }
2168
+
2169
+ int
2170
+ chunk_complete_cb (http_parser *p)
2171
+ {
2172
+ assert(p == parser);
2173
+
2174
+ /* Here we want to verify that each chunk_header_cb is matched by a
2175
+ * chunk_complete_cb, so not only should the total number of calls to
2176
+ * both callbacks be the same, but they also should be interleaved
2177
+ * properly */
2178
+ assert(messages[num_messages].num_chunks ==
2179
+ messages[num_messages].num_chunks_complete + 1);
2180
+
2181
+ messages[num_messages].num_chunks_complete++;
2182
+ return 0;
2183
+ }
2184
+
2185
+ /* These dontcall_* callbacks exist so that we can verify that when we're
2186
+ * paused, no additional callbacks are invoked */
2187
+ int
2188
+ dontcall_message_begin_cb (http_parser *p)
2189
+ {
2190
+ if (p) { } // gcc
2191
+ fprintf(stderr, "\n\n*** on_message_begin() called on paused parser ***\n\n");
2192
+ abort();
2193
+ }
2194
+
2195
+ int
2196
+ dontcall_header_field_cb (http_parser *p, const char *buf, size_t len)
2197
+ {
2198
+ if (p || buf || len) { } // gcc
2199
+ fprintf(stderr, "\n\n*** on_header_field() called on paused parser ***\n\n");
2200
+ abort();
2201
+ }
2202
+
2203
+ int
2204
+ dontcall_header_value_cb (http_parser *p, const char *buf, size_t len)
2205
+ {
2206
+ if (p || buf || len) { } // gcc
2207
+ fprintf(stderr, "\n\n*** on_header_value() called on paused parser ***\n\n");
2208
+ abort();
2209
+ }
2210
+
2211
+ int
2212
+ dontcall_request_url_cb (http_parser *p, const char *buf, size_t len)
2213
+ {
2214
+ if (p || buf || len) { } // gcc
2215
+ fprintf(stderr, "\n\n*** on_request_url() called on paused parser ***\n\n");
2216
+ abort();
2217
+ }
2218
+
2219
+ int
2220
+ dontcall_body_cb (http_parser *p, const char *buf, size_t len)
2221
+ {
2222
+ if (p || buf || len) { } // gcc
2223
+ fprintf(stderr, "\n\n*** on_body_cb() called on paused parser ***\n\n");
2224
+ abort();
2225
+ }
2226
+
2227
+ int
2228
+ dontcall_headers_complete_cb (http_parser *p)
2229
+ {
2230
+ if (p) { } // gcc
2231
+ fprintf(stderr, "\n\n*** on_headers_complete() called on paused "
2232
+ "parser ***\n\n");
2233
+ abort();
2234
+ }
2235
+
2236
+ int
2237
+ dontcall_message_complete_cb (http_parser *p)
2238
+ {
2239
+ if (p) { } // gcc
2240
+ fprintf(stderr, "\n\n*** on_message_complete() called on paused "
2241
+ "parser ***\n\n");
2242
+ abort();
2243
+ }
2244
+
2245
+ int
2246
+ dontcall_response_status_cb (http_parser *p, const char *buf, size_t len)
2247
+ {
2248
+ if (p || buf || len) { } // gcc
2249
+ fprintf(stderr, "\n\n*** on_status() called on paused parser ***\n\n");
2250
+ abort();
2251
+ }
2252
+
2253
+ int
2254
+ dontcall_chunk_header_cb (http_parser *p)
2255
+ {
2256
+ if (p) { } // gcc
2257
+ fprintf(stderr, "\n\n*** on_chunk_header() called on paused parser ***\n\n");
2258
+ exit(1);
2259
+ }
2260
+
2261
+ int
2262
+ dontcall_chunk_complete_cb (http_parser *p)
2263
+ {
2264
+ if (p) { } // gcc
2265
+ fprintf(stderr, "\n\n*** on_chunk_complete() "
2266
+ "called on paused parser ***\n\n");
2267
+ exit(1);
2268
+ }
2269
+
2270
+ static http_parser_settings settings_dontcall =
2271
+ {.on_message_begin = dontcall_message_begin_cb
2272
+ ,.on_header_field = dontcall_header_field_cb
2273
+ ,.on_header_value = dontcall_header_value_cb
2274
+ ,.on_url = dontcall_request_url_cb
2275
+ ,.on_status = dontcall_response_status_cb
2276
+ ,.on_body = dontcall_body_cb
2277
+ ,.on_headers_complete = dontcall_headers_complete_cb
2278
+ ,.on_message_complete = dontcall_message_complete_cb
2279
+ ,.on_chunk_header = dontcall_chunk_header_cb
2280
+ ,.on_chunk_complete = dontcall_chunk_complete_cb
2281
+ };
2282
+
2283
+ /* These pause_* callbacks always pause the parser and just invoke the regular
2284
+ * callback that tracks content. Before returning, we overwrite the parser
2285
+ * settings to point to the _dontcall variety so that we can verify that
2286
+ * the pause actually did, you know, pause. */
2287
+ int
2288
+ pause_message_begin_cb (http_parser *p)
2289
+ {
2290
+ http_parser_pause(p, 1);
2291
+ *current_pause_parser = settings_dontcall;
2292
+ return message_begin_cb(p);
2293
+ }
2294
+
2295
+ int
2296
+ pause_header_field_cb (http_parser *p, const char *buf, size_t len)
2297
+ {
2298
+ http_parser_pause(p, 1);
2299
+ *current_pause_parser = settings_dontcall;
2300
+ return header_field_cb(p, buf, len);
2301
+ }
2302
+
2303
+ int
2304
+ pause_header_value_cb (http_parser *p, const char *buf, size_t len)
2305
+ {
2306
+ http_parser_pause(p, 1);
2307
+ *current_pause_parser = settings_dontcall;
2308
+ return header_value_cb(p, buf, len);
2309
+ }
2310
+
2311
+ int
2312
+ pause_request_url_cb (http_parser *p, const char *buf, size_t len)
2313
+ {
2314
+ http_parser_pause(p, 1);
2315
+ *current_pause_parser = settings_dontcall;
2316
+ return request_url_cb(p, buf, len);
2317
+ }
2318
+
2319
+ int
2320
+ pause_body_cb (http_parser *p, const char *buf, size_t len)
2321
+ {
2322
+ http_parser_pause(p, 1);
2323
+ *current_pause_parser = settings_dontcall;
2324
+ return body_cb(p, buf, len);
2325
+ }
2326
+
2327
+ int
2328
+ pause_headers_complete_cb (http_parser *p)
2329
+ {
2330
+ http_parser_pause(p, 1);
2331
+ *current_pause_parser = settings_dontcall;
2332
+ return headers_complete_cb(p);
2333
+ }
2334
+
2335
+ int
2336
+ pause_message_complete_cb (http_parser *p)
2337
+ {
2338
+ http_parser_pause(p, 1);
2339
+ *current_pause_parser = settings_dontcall;
2340
+ return message_complete_cb(p);
2341
+ }
2342
+
2343
+ int
2344
+ pause_response_status_cb (http_parser *p, const char *buf, size_t len)
2345
+ {
2346
+ http_parser_pause(p, 1);
2347
+ *current_pause_parser = settings_dontcall;
2348
+ return response_status_cb(p, buf, len);
2349
+ }
2350
+
2351
+ int
2352
+ pause_chunk_header_cb (http_parser *p)
2353
+ {
2354
+ http_parser_pause(p, 1);
2355
+ *current_pause_parser = settings_dontcall;
2356
+ return chunk_header_cb(p);
2357
+ }
2358
+
2359
+ int
2360
+ pause_chunk_complete_cb (http_parser *p)
2361
+ {
2362
+ http_parser_pause(p, 1);
2363
+ *current_pause_parser = settings_dontcall;
2364
+ return chunk_complete_cb(p);
2365
+ }
2366
+
2367
+ int
2368
+ connect_headers_complete_cb (http_parser *p)
2369
+ {
2370
+ headers_complete_cb(p);
2371
+ return 1;
2372
+ }
2373
+
2374
+ int
2375
+ connect_message_complete_cb (http_parser *p)
2376
+ {
2377
+ messages[num_messages].should_keep_alive = http_should_keep_alive(parser);
2378
+ return message_complete_cb(p);
2379
+ }
2380
+
2381
+ static http_parser_settings settings_pause =
2382
+ {.on_message_begin = pause_message_begin_cb
2383
+ ,.on_header_field = pause_header_field_cb
2384
+ ,.on_header_value = pause_header_value_cb
2385
+ ,.on_url = pause_request_url_cb
2386
+ ,.on_status = pause_response_status_cb
2387
+ ,.on_body = pause_body_cb
2388
+ ,.on_headers_complete = pause_headers_complete_cb
2389
+ ,.on_message_complete = pause_message_complete_cb
2390
+ ,.on_chunk_header = pause_chunk_header_cb
2391
+ ,.on_chunk_complete = pause_chunk_complete_cb
2392
+ };
2393
+
2394
+ static http_parser_settings settings =
2395
+ {.on_message_begin = message_begin_cb
2396
+ ,.on_header_field = header_field_cb
2397
+ ,.on_header_value = header_value_cb
2398
+ ,.on_url = request_url_cb
2399
+ ,.on_status = response_status_cb
2400
+ ,.on_body = body_cb
2401
+ ,.on_headers_complete = headers_complete_cb
2402
+ ,.on_message_complete = message_complete_cb
2403
+ ,.on_chunk_header = chunk_header_cb
2404
+ ,.on_chunk_complete = chunk_complete_cb
2405
+ };
2406
+
2407
+ static http_parser_settings settings_count_body =
2408
+ {.on_message_begin = message_begin_cb
2409
+ ,.on_header_field = header_field_cb
2410
+ ,.on_header_value = header_value_cb
2411
+ ,.on_url = request_url_cb
2412
+ ,.on_status = response_status_cb
2413
+ ,.on_body = count_body_cb
2414
+ ,.on_headers_complete = headers_complete_cb
2415
+ ,.on_message_complete = message_complete_cb
2416
+ ,.on_chunk_header = chunk_header_cb
2417
+ ,.on_chunk_complete = chunk_complete_cb
2418
+ };
2419
+
2420
+ static http_parser_settings settings_connect =
2421
+ {.on_message_begin = message_begin_cb
2422
+ ,.on_header_field = header_field_cb
2423
+ ,.on_header_value = header_value_cb
2424
+ ,.on_url = request_url_cb
2425
+ ,.on_status = response_status_cb
2426
+ ,.on_body = dontcall_body_cb
2427
+ ,.on_headers_complete = connect_headers_complete_cb
2428
+ ,.on_message_complete = connect_message_complete_cb
2429
+ ,.on_chunk_header = chunk_header_cb
2430
+ ,.on_chunk_complete = chunk_complete_cb
2431
+ };
2432
+
2433
+ static http_parser_settings settings_null =
2434
+ {.on_message_begin = 0
2435
+ ,.on_header_field = 0
2436
+ ,.on_header_value = 0
2437
+ ,.on_url = 0
2438
+ ,.on_status = 0
2439
+ ,.on_body = 0
2440
+ ,.on_headers_complete = 0
2441
+ ,.on_message_complete = 0
2442
+ ,.on_chunk_header = 0
2443
+ ,.on_chunk_complete = 0
2444
+ };
2445
+
2446
+ void
2447
+ parser_init (enum http_parser_type type)
2448
+ {
2449
+ num_messages = 0;
2450
+
2451
+ assert(parser == NULL);
2452
+
2453
+ parser = malloc(sizeof(http_parser));
2454
+
2455
+ http_parser_init(parser, type);
2456
+
2457
+ memset(&messages, 0, sizeof messages);
2458
+
2459
+ }
2460
+
2461
+ void
2462
+ parser_free ()
2463
+ {
2464
+ assert(parser);
2465
+ free(parser);
2466
+ parser = NULL;
2467
+ }
2468
+
2469
+ size_t parse (const char *buf, size_t len)
2470
+ {
2471
+ size_t nparsed;
2472
+ currently_parsing_eof = (len == 0);
2473
+ nparsed = http_parser_execute(parser, &settings, buf, len);
2474
+ return nparsed;
2475
+ }
2476
+
2477
+ size_t parse_count_body (const char *buf, size_t len)
2478
+ {
2479
+ size_t nparsed;
2480
+ currently_parsing_eof = (len == 0);
2481
+ nparsed = http_parser_execute(parser, &settings_count_body, buf, len);
2482
+ return nparsed;
2483
+ }
2484
+
2485
+ size_t parse_pause (const char *buf, size_t len)
2486
+ {
2487
+ size_t nparsed;
2488
+ http_parser_settings s = settings_pause;
2489
+
2490
+ currently_parsing_eof = (len == 0);
2491
+ current_pause_parser = &s;
2492
+ nparsed = http_parser_execute(parser, current_pause_parser, buf, len);
2493
+ return nparsed;
2494
+ }
2495
+
2496
+ size_t parse_connect (const char *buf, size_t len)
2497
+ {
2498
+ size_t nparsed;
2499
+ currently_parsing_eof = (len == 0);
2500
+ nparsed = http_parser_execute(parser, &settings_connect, buf, len);
2501
+ return nparsed;
2502
+ }
2503
+
2504
+ static inline int
2505
+ check_str_eq (const struct message *m,
2506
+ const char *prop,
2507
+ const char *expected,
2508
+ const char *found) {
2509
+ if ((expected == NULL) != (found == NULL)) {
2510
+ printf("\n*** Error: %s in '%s' ***\n\n", prop, m->name);
2511
+ printf("expected %s\n", (expected == NULL) ? "NULL" : expected);
2512
+ printf(" found %s\n", (found == NULL) ? "NULL" : found);
2513
+ return 0;
2514
+ }
2515
+ if (expected != NULL && 0 != strcmp(expected, found)) {
2516
+ printf("\n*** Error: %s in '%s' ***\n\n", prop, m->name);
2517
+ printf("expected '%s'\n", expected);
2518
+ printf(" found '%s'\n", found);
2519
+ return 0;
2520
+ }
2521
+ return 1;
2522
+ }
2523
+
2524
+ static inline int
2525
+ check_num_eq (const struct message *m,
2526
+ const char *prop,
2527
+ int expected,
2528
+ int found) {
2529
+ if (expected != found) {
2530
+ printf("\n*** Error: %s in '%s' ***\n\n", prop, m->name);
2531
+ printf("expected %d\n", expected);
2532
+ printf(" found %d\n", found);
2533
+ return 0;
2534
+ }
2535
+ return 1;
2536
+ }
2537
+
2538
+ #define MESSAGE_CHECK_STR_EQ(expected, found, prop) \
2539
+ if (!check_str_eq(expected, #prop, expected->prop, found->prop)) return 0
2540
+
2541
+ #define MESSAGE_CHECK_NUM_EQ(expected, found, prop) \
2542
+ if (!check_num_eq(expected, #prop, expected->prop, found->prop)) return 0
2543
+
2544
+ #define MESSAGE_CHECK_URL_EQ(u, expected, found, prop, fn) \
2545
+ do { \
2546
+ char ubuf[256]; \
2547
+ \
2548
+ if ((u)->field_set & (1 << (fn))) { \
2549
+ memcpy(ubuf, (found)->request_url + (u)->field_data[(fn)].off, \
2550
+ (u)->field_data[(fn)].len); \
2551
+ ubuf[(u)->field_data[(fn)].len] = '\0'; \
2552
+ } else { \
2553
+ ubuf[0] = '\0'; \
2554
+ } \
2555
+ \
2556
+ check_str_eq(expected, #prop, expected->prop, ubuf); \
2557
+ } while(0)
2558
+
2559
+ int
2560
+ message_eq (int index, int connect, const struct message *expected)
2561
+ {
2562
+ int i;
2563
+ struct message *m = &messages[index];
2564
+
2565
+ MESSAGE_CHECK_NUM_EQ(expected, m, http_major);
2566
+ MESSAGE_CHECK_NUM_EQ(expected, m, http_minor);
2567
+
2568
+ if (expected->type == HTTP_REQUEST) {
2569
+ MESSAGE_CHECK_NUM_EQ(expected, m, method);
2570
+ } else {
2571
+ MESSAGE_CHECK_NUM_EQ(expected, m, status_code);
2572
+ MESSAGE_CHECK_STR_EQ(expected, m, response_status);
2573
+ assert(m->status_cb_called);
2574
+ }
2575
+
2576
+ if (!connect) {
2577
+ MESSAGE_CHECK_NUM_EQ(expected, m, should_keep_alive);
2578
+ MESSAGE_CHECK_NUM_EQ(expected, m, message_complete_on_eof);
2579
+ }
2580
+
2581
+ assert(m->message_begin_cb_called);
2582
+ assert(m->headers_complete_cb_called);
2583
+ assert(m->message_complete_cb_called);
2584
+
2585
+
2586
+ MESSAGE_CHECK_STR_EQ(expected, m, request_url);
2587
+
2588
+ /* Check URL components; we can't do this w/ CONNECT since it doesn't
2589
+ * send us a well-formed URL.
2590
+ */
2591
+ if (*m->request_url && m->method != HTTP_CONNECT) {
2592
+ struct http_parser_url u;
2593
+
2594
+ if (http_parser_parse_url(m->request_url, strlen(m->request_url), 0, &u)) {
2595
+ fprintf(stderr, "\n\n*** failed to parse URL %s ***\n\n",
2596
+ m->request_url);
2597
+ abort();
2598
+ }
2599
+
2600
+ if (expected->host) {
2601
+ MESSAGE_CHECK_URL_EQ(&u, expected, m, host, UF_HOST);
2602
+ }
2603
+
2604
+ if (expected->userinfo) {
2605
+ MESSAGE_CHECK_URL_EQ(&u, expected, m, userinfo, UF_USERINFO);
2606
+ }
2607
+
2608
+ m->port = (u.field_set & (1 << UF_PORT)) ?
2609
+ u.port : 0;
2610
+
2611
+ MESSAGE_CHECK_URL_EQ(&u, expected, m, query_string, UF_QUERY);
2612
+ MESSAGE_CHECK_URL_EQ(&u, expected, m, fragment, UF_FRAGMENT);
2613
+ MESSAGE_CHECK_URL_EQ(&u, expected, m, request_path, UF_PATH);
2614
+ MESSAGE_CHECK_NUM_EQ(expected, m, port);
2615
+ }
2616
+
2617
+ if (connect) {
2618
+ check_num_eq(m, "body_size", 0, m->body_size);
2619
+ } else if (expected->body_size) {
2620
+ MESSAGE_CHECK_NUM_EQ(expected, m, body_size);
2621
+ } else {
2622
+ MESSAGE_CHECK_STR_EQ(expected, m, body);
2623
+ }
2624
+
2625
+ if (connect) {
2626
+ check_num_eq(m, "num_chunks_complete", 0, m->num_chunks_complete);
2627
+ } else {
2628
+ assert(m->num_chunks == m->num_chunks_complete);
2629
+ MESSAGE_CHECK_NUM_EQ(expected, m, num_chunks_complete);
2630
+ for (i = 0; i < m->num_chunks && i < MAX_CHUNKS; i++) {
2631
+ MESSAGE_CHECK_NUM_EQ(expected, m, chunk_lengths[i]);
2632
+ }
2633
+ }
2634
+
2635
+ MESSAGE_CHECK_NUM_EQ(expected, m, num_headers);
2636
+
2637
+ int r;
2638
+ for (i = 0; i < m->num_headers; i++) {
2639
+ r = check_str_eq(expected, "header field", expected->headers[i][0], m->headers[i][0]);
2640
+ if (!r) return 0;
2641
+ r = check_str_eq(expected, "header value", expected->headers[i][1], m->headers[i][1]);
2642
+ if (!r) return 0;
2643
+ }
2644
+
2645
+ if (!connect) {
2646
+ MESSAGE_CHECK_STR_EQ(expected, m, upgrade);
2647
+ }
2648
+
2649
+ return 1;
2650
+ }
2651
+
2652
+ /* Given a sequence of varargs messages, return the number of them that the
2653
+ * parser should successfully parse, taking into account that upgraded
2654
+ * messages prevent all subsequent messages from being parsed.
2655
+ */
2656
+ size_t
2657
+ count_parsed_messages(const size_t nmsgs, ...) {
2658
+ size_t i;
2659
+ va_list ap;
2660
+
2661
+ va_start(ap, nmsgs);
2662
+
2663
+ for (i = 0; i < nmsgs; i++) {
2664
+ struct message *m = va_arg(ap, struct message *);
2665
+
2666
+ if (m->upgrade) {
2667
+ va_end(ap);
2668
+ return i + 1;
2669
+ }
2670
+ }
2671
+
2672
+ va_end(ap);
2673
+ return nmsgs;
2674
+ }
2675
+
2676
+ /* Given a sequence of bytes and the number of these that we were able to
2677
+ * parse, verify that upgrade bodies are correct.
2678
+ */
2679
+ void
2680
+ upgrade_message_fix(char *body, const size_t nread, const size_t nmsgs, ...) {
2681
+ va_list ap;
2682
+ size_t i;
2683
+ size_t off = 0;
2684
+
2685
+ va_start(ap, nmsgs);
2686
+
2687
+ for (i = 0; i < nmsgs; i++) {
2688
+ struct message *m = va_arg(ap, struct message *);
2689
+
2690
+ off += strlen(m->raw);
2691
+
2692
+ if (m->upgrade) {
2693
+ off -= strlen(m->upgrade);
2694
+
2695
+ /* Check the portion of the response after its specified upgrade */
2696
+ if (!check_str_eq(m, "upgrade", body + off, body + nread)) {
2697
+ abort();
2698
+ }
2699
+
2700
+ /* Fix up the response so that message_eq() will verify the beginning
2701
+ * of the upgrade */
2702
+ *(body + nread + strlen(m->upgrade)) = '\0';
2703
+ messages[num_messages -1 ].upgrade = body + nread;
2704
+
2705
+ va_end(ap);
2706
+ return;
2707
+ }
2708
+ }
2709
+
2710
+ va_end(ap);
2711
+ printf("\n\n*** Error: expected a message with upgrade ***\n");
2712
+
2713
+ abort();
2714
+ }
2715
+
2716
+ static void
2717
+ print_error (const char *raw, size_t error_location)
2718
+ {
2719
+ fprintf(stderr, "\n*** %s ***\n\n",
2720
+ http_errno_description(HTTP_PARSER_ERRNO(parser)));
2721
+
2722
+ int this_line = 0, char_len = 0;
2723
+ size_t i, j, len = strlen(raw), error_location_line = 0;
2724
+ for (i = 0; i < len; i++) {
2725
+ if (i == error_location) this_line = 1;
2726
+ switch (raw[i]) {
2727
+ case '\r':
2728
+ char_len = 2;
2729
+ fprintf(stderr, "\\r");
2730
+ break;
2731
+
2732
+ case '\n':
2733
+ fprintf(stderr, "\\n\n");
2734
+
2735
+ if (this_line) goto print;
2736
+
2737
+ error_location_line = 0;
2738
+ continue;
2739
+
2740
+ default:
2741
+ char_len = 1;
2742
+ fputc(raw[i], stderr);
2743
+ break;
2744
+ }
2745
+ if (!this_line) error_location_line += char_len;
2746
+ }
2747
+
2748
+ fprintf(stderr, "[eof]\n");
2749
+
2750
+ print:
2751
+ for (j = 0; j < error_location_line; j++) {
2752
+ fputc(' ', stderr);
2753
+ }
2754
+ fprintf(stderr, "^\n\nerror location: %u\n", (unsigned int)error_location);
2755
+ }
2756
+
2757
+ void
2758
+ test_preserve_data (void)
2759
+ {
2760
+ char my_data[] = "application-specific data";
2761
+ http_parser parser;
2762
+ parser.data = my_data;
2763
+ http_parser_init(&parser, HTTP_REQUEST);
2764
+ if (parser.data != my_data) {
2765
+ printf("\n*** parser.data not preserved accross http_parser_init ***\n\n");
2766
+ abort();
2767
+ }
2768
+ }
2769
+
2770
+ struct url_test {
2771
+ const char *name;
2772
+ const char *url;
2773
+ int is_connect;
2774
+ struct http_parser_url u;
2775
+ int rv;
2776
+ };
2777
+
2778
+ const struct url_test url_tests[] =
2779
+ { {.name="proxy request"
2780
+ ,.url="http://hostname/"
2781
+ ,.is_connect=0
2782
+ ,.u=
2783
+ {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PATH)
2784
+ ,.port=0
2785
+ ,.field_data=
2786
+ {{ 0, 4 } /* UF_SCHEMA */
2787
+ ,{ 7, 8 } /* UF_HOST */
2788
+ ,{ 0, 0 } /* UF_PORT */
2789
+ ,{ 15, 1 } /* UF_PATH */
2790
+ ,{ 0, 0 } /* UF_QUERY */
2791
+ ,{ 0, 0 } /* UF_FRAGMENT */
2792
+ ,{ 0, 0 } /* UF_USERINFO */
2793
+ }
2794
+ }
2795
+ ,.rv=0
2796
+ }
2797
+
2798
+ , {.name="proxy request with port"
2799
+ ,.url="http://hostname:444/"
2800
+ ,.is_connect=0
2801
+ ,.u=
2802
+ {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PORT) | (1 << UF_PATH)
2803
+ ,.port=444
2804
+ ,.field_data=
2805
+ {{ 0, 4 } /* UF_SCHEMA */
2806
+ ,{ 7, 8 } /* UF_HOST */
2807
+ ,{ 16, 3 } /* UF_PORT */
2808
+ ,{ 19, 1 } /* UF_PATH */
2809
+ ,{ 0, 0 } /* UF_QUERY */
2810
+ ,{ 0, 0 } /* UF_FRAGMENT */
2811
+ ,{ 0, 0 } /* UF_USERINFO */
2812
+ }
2813
+ }
2814
+ ,.rv=0
2815
+ }
2816
+
2817
+ , {.name="CONNECT request"
2818
+ ,.url="hostname:443"
2819
+ ,.is_connect=1
2820
+ ,.u=
2821
+ {.field_set=(1 << UF_HOST) | (1 << UF_PORT)
2822
+ ,.port=443
2823
+ ,.field_data=
2824
+ {{ 0, 0 } /* UF_SCHEMA */
2825
+ ,{ 0, 8 } /* UF_HOST */
2826
+ ,{ 9, 3 } /* UF_PORT */
2827
+ ,{ 0, 0 } /* UF_PATH */
2828
+ ,{ 0, 0 } /* UF_QUERY */
2829
+ ,{ 0, 0 } /* UF_FRAGMENT */
2830
+ ,{ 0, 0 } /* UF_USERINFO */
2831
+ }
2832
+ }
2833
+ ,.rv=0
2834
+ }
2835
+
2836
+ , {.name="CONNECT request but not connect"
2837
+ ,.url="hostname:443"
2838
+ ,.is_connect=0
2839
+ ,.rv=1
2840
+ }
2841
+
2842
+ , {.name="proxy ipv6 request"
2843
+ ,.url="http://[1:2::3:4]/"
2844
+ ,.is_connect=0
2845
+ ,.u=
2846
+ {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PATH)
2847
+ ,.port=0
2848
+ ,.field_data=
2849
+ {{ 0, 4 } /* UF_SCHEMA */
2850
+ ,{ 8, 8 } /* UF_HOST */
2851
+ ,{ 0, 0 } /* UF_PORT */
2852
+ ,{ 17, 1 } /* UF_PATH */
2853
+ ,{ 0, 0 } /* UF_QUERY */
2854
+ ,{ 0, 0 } /* UF_FRAGMENT */
2855
+ ,{ 0, 0 } /* UF_USERINFO */
2856
+ }
2857
+ }
2858
+ ,.rv=0
2859
+ }
2860
+
2861
+ , {.name="proxy ipv6 request with port"
2862
+ ,.url="http://[1:2::3:4]:67/"
2863
+ ,.is_connect=0
2864
+ ,.u=
2865
+ {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PORT) | (1 << UF_PATH)
2866
+ ,.port=67
2867
+ ,.field_data=
2868
+ {{ 0, 4 } /* UF_SCHEMA */
2869
+ ,{ 8, 8 } /* UF_HOST */
2870
+ ,{ 18, 2 } /* UF_PORT */
2871
+ ,{ 20, 1 } /* UF_PATH */
2872
+ ,{ 0, 0 } /* UF_QUERY */
2873
+ ,{ 0, 0 } /* UF_FRAGMENT */
2874
+ ,{ 0, 0 } /* UF_USERINFO */
2875
+ }
2876
+ }
2877
+ ,.rv=0
2878
+ }
2879
+
2880
+ , {.name="CONNECT ipv6 address"
2881
+ ,.url="[1:2::3:4]:443"
2882
+ ,.is_connect=1
2883
+ ,.u=
2884
+ {.field_set=(1 << UF_HOST) | (1 << UF_PORT)
2885
+ ,.port=443
2886
+ ,.field_data=
2887
+ {{ 0, 0 } /* UF_SCHEMA */
2888
+ ,{ 1, 8 } /* UF_HOST */
2889
+ ,{ 11, 3 } /* UF_PORT */
2890
+ ,{ 0, 0 } /* UF_PATH */
2891
+ ,{ 0, 0 } /* UF_QUERY */
2892
+ ,{ 0, 0 } /* UF_FRAGMENT */
2893
+ ,{ 0, 0 } /* UF_USERINFO */
2894
+ }
2895
+ }
2896
+ ,.rv=0
2897
+ }
2898
+
2899
+ , {.name="ipv4 in ipv6 address"
2900
+ ,.url="http://[2001:0000:0000:0000:0000:0000:1.9.1.1]/"
2901
+ ,.is_connect=0
2902
+ ,.u=
2903
+ {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PATH)
2904
+ ,.port=0
2905
+ ,.field_data=
2906
+ {{ 0, 4 } /* UF_SCHEMA */
2907
+ ,{ 8, 37 } /* UF_HOST */
2908
+ ,{ 0, 0 } /* UF_PORT */
2909
+ ,{ 46, 1 } /* UF_PATH */
2910
+ ,{ 0, 0 } /* UF_QUERY */
2911
+ ,{ 0, 0 } /* UF_FRAGMENT */
2912
+ ,{ 0, 0 } /* UF_USERINFO */
2913
+ }
2914
+ }
2915
+ ,.rv=0
2916
+ }
2917
+
2918
+ , {.name="extra ? in query string"
2919
+ ,.url="http://a.tbcdn.cn/p/fp/2010c/??fp-header-min.css,fp-base-min.css,"
2920
+ "fp-channel-min.css,fp-product-min.css,fp-mall-min.css,fp-category-min.css,"
2921
+ "fp-sub-min.css,fp-gdp4p-min.css,fp-css3-min.css,fp-misc-min.css?t=20101022.css"
2922
+ ,.is_connect=0
2923
+ ,.u=
2924
+ {.field_set=(1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_QUERY)
2925
+ ,.port=0
2926
+ ,.field_data=
2927
+ {{ 0, 4 } /* UF_SCHEMA */
2928
+ ,{ 7, 10 } /* UF_HOST */
2929
+ ,{ 0, 0 } /* UF_PORT */
2930
+ ,{ 17, 12 } /* UF_PATH */
2931
+ ,{ 30,187 } /* UF_QUERY */
2932
+ ,{ 0, 0 } /* UF_FRAGMENT */
2933
+ ,{ 0, 0 } /* UF_USERINFO */
2934
+ }
2935
+ }
2936
+ ,.rv=0
2937
+ }
2938
+
2939
+ , {.name="space URL encoded"
2940
+ ,.url="/toto.html?toto=a%20b"
2941
+ ,.is_connect=0
2942
+ ,.u=
2943
+ {.field_set= (1<<UF_PATH) | (1<<UF_QUERY)
2944
+ ,.port=0
2945
+ ,.field_data=
2946
+ {{ 0, 0 } /* UF_SCHEMA */
2947
+ ,{ 0, 0 } /* UF_HOST */
2948
+ ,{ 0, 0 } /* UF_PORT */
2949
+ ,{ 0, 10 } /* UF_PATH */
2950
+ ,{ 11, 10 } /* UF_QUERY */
2951
+ ,{ 0, 0 } /* UF_FRAGMENT */
2952
+ ,{ 0, 0 } /* UF_USERINFO */
2953
+ }
2954
+ }
2955
+ ,.rv=0
2956
+ }
2957
+
2958
+
2959
+ , {.name="URL fragment"
2960
+ ,.url="/toto.html#titi"
2961
+ ,.is_connect=0
2962
+ ,.u=
2963
+ {.field_set= (1<<UF_PATH) | (1<<UF_FRAGMENT)
2964
+ ,.port=0
2965
+ ,.field_data=
2966
+ {{ 0, 0 } /* UF_SCHEMA */
2967
+ ,{ 0, 0 } /* UF_HOST */
2968
+ ,{ 0, 0 } /* UF_PORT */
2969
+ ,{ 0, 10 } /* UF_PATH */
2970
+ ,{ 0, 0 } /* UF_QUERY */
2971
+ ,{ 11, 4 } /* UF_FRAGMENT */
2972
+ ,{ 0, 0 } /* UF_USERINFO */
2973
+ }
2974
+ }
2975
+ ,.rv=0
2976
+ }
2977
+
2978
+ , {.name="complex URL fragment"
2979
+ ,.url="http://www.webmasterworld.com/r.cgi?f=21&d=8405&url="
2980
+ "http://www.example.com/index.html?foo=bar&hello=world#midpage"
2981
+ ,.is_connect=0
2982
+ ,.u=
2983
+ {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_QUERY) |\
2984
+ (1<<UF_FRAGMENT)
2985
+ ,.port=0
2986
+ ,.field_data=
2987
+ {{ 0, 4 } /* UF_SCHEMA */
2988
+ ,{ 7, 22 } /* UF_HOST */
2989
+ ,{ 0, 0 } /* UF_PORT */
2990
+ ,{ 29, 6 } /* UF_PATH */
2991
+ ,{ 36, 69 } /* UF_QUERY */
2992
+ ,{106, 7 } /* UF_FRAGMENT */
2993
+ ,{ 0, 0 } /* UF_USERINFO */
2994
+ }
2995
+ }
2996
+ ,.rv=0
2997
+ }
2998
+
2999
+ , {.name="complex URL from node js url parser doc"
3000
+ ,.url="http://host.com:8080/p/a/t/h?query=string#hash"
3001
+ ,.is_connect=0
3002
+ ,.u=
3003
+ {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PORT) | (1<<UF_PATH) |\
3004
+ (1<<UF_QUERY) | (1<<UF_FRAGMENT)
3005
+ ,.port=8080
3006
+ ,.field_data=
3007
+ {{ 0, 4 } /* UF_SCHEMA */
3008
+ ,{ 7, 8 } /* UF_HOST */
3009
+ ,{ 16, 4 } /* UF_PORT */
3010
+ ,{ 20, 8 } /* UF_PATH */
3011
+ ,{ 29, 12 } /* UF_QUERY */
3012
+ ,{ 42, 4 } /* UF_FRAGMENT */
3013
+ ,{ 0, 0 } /* UF_USERINFO */
3014
+ }
3015
+ }
3016
+ ,.rv=0
3017
+ }
3018
+
3019
+ , {.name="complex URL with basic auth from node js url parser doc"
3020
+ ,.url="http://a:b@host.com:8080/p/a/t/h?query=string#hash"
3021
+ ,.is_connect=0
3022
+ ,.u=
3023
+ {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PORT) | (1<<UF_PATH) |\
3024
+ (1<<UF_QUERY) | (1<<UF_FRAGMENT) | (1<<UF_USERINFO)
3025
+ ,.port=8080
3026
+ ,.field_data=
3027
+ {{ 0, 4 } /* UF_SCHEMA */
3028
+ ,{ 11, 8 } /* UF_HOST */
3029
+ ,{ 20, 4 } /* UF_PORT */
3030
+ ,{ 24, 8 } /* UF_PATH */
3031
+ ,{ 33, 12 } /* UF_QUERY */
3032
+ ,{ 46, 4 } /* UF_FRAGMENT */
3033
+ ,{ 7, 3 } /* UF_USERINFO */
3034
+ }
3035
+ }
3036
+ ,.rv=0
3037
+ }
3038
+
3039
+ , {.name="double @"
3040
+ ,.url="http://a:b@@hostname:443/"
3041
+ ,.is_connect=0
3042
+ ,.rv=1
3043
+ }
3044
+
3045
+ , {.name="proxy empty host"
3046
+ ,.url="http://:443/"
3047
+ ,.is_connect=0
3048
+ ,.rv=1
3049
+ }
3050
+
3051
+ , {.name="proxy empty port"
3052
+ ,.url="http://hostname:/"
3053
+ ,.is_connect=0
3054
+ ,.rv=1
3055
+ }
3056
+
3057
+ , {.name="CONNECT with basic auth"
3058
+ ,.url="a:b@hostname:443"
3059
+ ,.is_connect=1
3060
+ ,.rv=1
3061
+ }
3062
+
3063
+ , {.name="CONNECT empty host"
3064
+ ,.url=":443"
3065
+ ,.is_connect=1
3066
+ ,.rv=1
3067
+ }
3068
+
3069
+ , {.name="CONNECT empty port"
3070
+ ,.url="hostname:"
3071
+ ,.is_connect=1
3072
+ ,.rv=1
3073
+ }
3074
+
3075
+ , {.name="CONNECT with extra bits"
3076
+ ,.url="hostname:443/"
3077
+ ,.is_connect=1
3078
+ ,.rv=1
3079
+ }
3080
+
3081
+ , {.name="space in URL"
3082
+ ,.url="/foo bar/"
3083
+ ,.rv=1 /* s_dead */
3084
+ }
3085
+
3086
+ , {.name="proxy basic auth with space url encoded"
3087
+ ,.url="http://a%20:b@host.com/"
3088
+ ,.is_connect=0
3089
+ ,.u=
3090
+ {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_USERINFO)
3091
+ ,.port=0
3092
+ ,.field_data=
3093
+ {{ 0, 4 } /* UF_SCHEMA */
3094
+ ,{ 14, 8 } /* UF_HOST */
3095
+ ,{ 0, 0 } /* UF_PORT */
3096
+ ,{ 22, 1 } /* UF_PATH */
3097
+ ,{ 0, 0 } /* UF_QUERY */
3098
+ ,{ 0, 0 } /* UF_FRAGMENT */
3099
+ ,{ 7, 6 } /* UF_USERINFO */
3100
+ }
3101
+ }
3102
+ ,.rv=0
3103
+ }
3104
+
3105
+ , {.name="carriage return in URL"
3106
+ ,.url="/foo\rbar/"
3107
+ ,.rv=1 /* s_dead */
3108
+ }
3109
+
3110
+ , {.name="proxy double : in URL"
3111
+ ,.url="http://hostname::443/"
3112
+ ,.rv=1 /* s_dead */
3113
+ }
3114
+
3115
+ , {.name="proxy basic auth with double :"
3116
+ ,.url="http://a::b@host.com/"
3117
+ ,.is_connect=0
3118
+ ,.u=
3119
+ {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_USERINFO)
3120
+ ,.port=0
3121
+ ,.field_data=
3122
+ {{ 0, 4 } /* UF_SCHEMA */
3123
+ ,{ 12, 8 } /* UF_HOST */
3124
+ ,{ 0, 0 } /* UF_PORT */
3125
+ ,{ 20, 1 } /* UF_PATH */
3126
+ ,{ 0, 0 } /* UF_QUERY */
3127
+ ,{ 0, 0 } /* UF_FRAGMENT */
3128
+ ,{ 7, 4 } /* UF_USERINFO */
3129
+ }
3130
+ }
3131
+ ,.rv=0
3132
+ }
3133
+
3134
+ , {.name="line feed in URL"
3135
+ ,.url="/foo\nbar/"
3136
+ ,.rv=1 /* s_dead */
3137
+ }
3138
+
3139
+ , {.name="proxy empty basic auth"
3140
+ ,.url="http://@hostname/fo"
3141
+ ,.u=
3142
+ {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH)
3143
+ ,.port=0
3144
+ ,.field_data=
3145
+ {{ 0, 4 } /* UF_SCHEMA */
3146
+ ,{ 8, 8 } /* UF_HOST */
3147
+ ,{ 0, 0 } /* UF_PORT */
3148
+ ,{ 16, 3 } /* UF_PATH */
3149
+ ,{ 0, 0 } /* UF_QUERY */
3150
+ ,{ 0, 0 } /* UF_FRAGMENT */
3151
+ ,{ 0, 0 } /* UF_USERINFO */
3152
+ }
3153
+ }
3154
+ ,.rv=0
3155
+ }
3156
+ , {.name="proxy line feed in hostname"
3157
+ ,.url="http://host\name/fo"
3158
+ ,.rv=1 /* s_dead */
3159
+ }
3160
+
3161
+ , {.name="proxy % in hostname"
3162
+ ,.url="http://host%name/fo"
3163
+ ,.rv=1 /* s_dead */
3164
+ }
3165
+
3166
+ , {.name="proxy ; in hostname"
3167
+ ,.url="http://host;ame/fo"
3168
+ ,.rv=1 /* s_dead */
3169
+ }
3170
+
3171
+ , {.name="proxy basic auth with unreservedchars"
3172
+ ,.url="http://a!;-_!=+$@host.com/"
3173
+ ,.is_connect=0
3174
+ ,.u=
3175
+ {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_USERINFO)
3176
+ ,.port=0
3177
+ ,.field_data=
3178
+ {{ 0, 4 } /* UF_SCHEMA */
3179
+ ,{ 17, 8 } /* UF_HOST */
3180
+ ,{ 0, 0 } /* UF_PORT */
3181
+ ,{ 25, 1 } /* UF_PATH */
3182
+ ,{ 0, 0 } /* UF_QUERY */
3183
+ ,{ 0, 0 } /* UF_FRAGMENT */
3184
+ ,{ 7, 9 } /* UF_USERINFO */
3185
+ }
3186
+ }
3187
+ ,.rv=0
3188
+ }
3189
+
3190
+ , {.name="proxy only empty basic auth"
3191
+ ,.url="http://@/fo"
3192
+ ,.rv=1 /* s_dead */
3193
+ }
3194
+
3195
+ , {.name="proxy only basic auth"
3196
+ ,.url="http://toto@/fo"
3197
+ ,.rv=1 /* s_dead */
3198
+ }
3199
+
3200
+ , {.name="proxy emtpy hostname"
3201
+ ,.url="http:///fo"
3202
+ ,.rv=1 /* s_dead */
3203
+ }
3204
+
3205
+ , {.name="proxy = in URL"
3206
+ ,.url="http://host=ame/fo"
3207
+ ,.rv=1 /* s_dead */
3208
+ }
3209
+
3210
+ , {.name="ipv6 address with Zone ID"
3211
+ ,.url="http://[fe80::a%25eth0]/"
3212
+ ,.is_connect=0
3213
+ ,.u=
3214
+ {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH)
3215
+ ,.port=0
3216
+ ,.field_data=
3217
+ {{ 0, 4 } /* UF_SCHEMA */
3218
+ ,{ 8, 14 } /* UF_HOST */
3219
+ ,{ 0, 0 } /* UF_PORT */
3220
+ ,{ 23, 1 } /* UF_PATH */
3221
+ ,{ 0, 0 } /* UF_QUERY */
3222
+ ,{ 0, 0 } /* UF_FRAGMENT */
3223
+ ,{ 0, 0 } /* UF_USERINFO */
3224
+ }
3225
+ }
3226
+ ,.rv=0
3227
+ }
3228
+
3229
+ , {.name="ipv6 address with Zone ID, but '%' is not percent-encoded"
3230
+ ,.url="http://[fe80::a%eth0]/"
3231
+ ,.is_connect=0
3232
+ ,.u=
3233
+ {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH)
3234
+ ,.port=0
3235
+ ,.field_data=
3236
+ {{ 0, 4 } /* UF_SCHEMA */
3237
+ ,{ 8, 12 } /* UF_HOST */
3238
+ ,{ 0, 0 } /* UF_PORT */
3239
+ ,{ 21, 1 } /* UF_PATH */
3240
+ ,{ 0, 0 } /* UF_QUERY */
3241
+ ,{ 0, 0 } /* UF_FRAGMENT */
3242
+ ,{ 0, 0 } /* UF_USERINFO */
3243
+ }
3244
+ }
3245
+ ,.rv=0
3246
+ }
3247
+
3248
+ , {.name="ipv6 address ending with '%'"
3249
+ ,.url="http://[fe80::a%]/"
3250
+ ,.rv=1 /* s_dead */
3251
+ }
3252
+
3253
+ , {.name="ipv6 address with Zone ID including bad character"
3254
+ ,.url="http://[fe80::a%$HOME]/"
3255
+ ,.rv=1 /* s_dead */
3256
+ }
3257
+
3258
+ , {.name="just ipv6 Zone ID"
3259
+ ,.url="http://[%eth0]/"
3260
+ ,.rv=1 /* s_dead */
3261
+ }
3262
+
3263
+ #if HTTP_PARSER_STRICT
3264
+
3265
+ , {.name="tab in URL"
3266
+ ,.url="/foo\tbar/"
3267
+ ,.rv=1 /* s_dead */
3268
+ }
3269
+
3270
+ , {.name="form feed in URL"
3271
+ ,.url="/foo\fbar/"
3272
+ ,.rv=1 /* s_dead */
3273
+ }
3274
+
3275
+ #else /* !HTTP_PARSER_STRICT */
3276
+
3277
+ , {.name="tab in URL"
3278
+ ,.url="/foo\tbar/"
3279
+ ,.u=
3280
+ {.field_set=(1 << UF_PATH)
3281
+ ,.field_data=
3282
+ {{ 0, 0 } /* UF_SCHEMA */
3283
+ ,{ 0, 0 } /* UF_HOST */
3284
+ ,{ 0, 0 } /* UF_PORT */
3285
+ ,{ 0, 9 } /* UF_PATH */
3286
+ ,{ 0, 0 } /* UF_QUERY */
3287
+ ,{ 0, 0 } /* UF_FRAGMENT */
3288
+ ,{ 0, 0 } /* UF_USERINFO */
3289
+ }
3290
+ }
3291
+ ,.rv=0
3292
+ }
3293
+
3294
+ , {.name="form feed in URL"
3295
+ ,.url="/foo\fbar/"
3296
+ ,.u=
3297
+ {.field_set=(1 << UF_PATH)
3298
+ ,.field_data=
3299
+ {{ 0, 0 } /* UF_SCHEMA */
3300
+ ,{ 0, 0 } /* UF_HOST */
3301
+ ,{ 0, 0 } /* UF_PORT */
3302
+ ,{ 0, 9 } /* UF_PATH */
3303
+ ,{ 0, 0 } /* UF_QUERY */
3304
+ ,{ 0, 0 } /* UF_FRAGMENT */
3305
+ ,{ 0, 0 } /* UF_USERINFO */
3306
+ }
3307
+ }
3308
+ ,.rv=0
3309
+ }
3310
+ #endif
3311
+ };
3312
+
3313
+ void
3314
+ dump_url (const char *url, const struct http_parser_url *u)
3315
+ {
3316
+ unsigned int i;
3317
+
3318
+ printf("\tfield_set: 0x%x, port: %u\n", u->field_set, u->port);
3319
+ for (i = 0; i < UF_MAX; i++) {
3320
+ if ((u->field_set & (1 << i)) == 0) {
3321
+ printf("\tfield_data[%u]: unset\n", i);
3322
+ continue;
3323
+ }
3324
+
3325
+ printf("\tfield_data[%u]: off: %u len: %u part: \"%.*s\n\"",
3326
+ i,
3327
+ u->field_data[i].off,
3328
+ u->field_data[i].len,
3329
+ u->field_data[i].len,
3330
+ url + u->field_data[i].off);
3331
+ }
3332
+ }
3333
+
3334
+ void
3335
+ test_parse_url (void)
3336
+ {
3337
+ struct http_parser_url u;
3338
+ const struct url_test *test;
3339
+ unsigned int i;
3340
+ int rv;
3341
+
3342
+ for (i = 0; i < (sizeof(url_tests) / sizeof(url_tests[0])); i++) {
3343
+ test = &url_tests[i];
3344
+ memset(&u, 0, sizeof(u));
3345
+
3346
+ rv = http_parser_parse_url(test->url,
3347
+ strlen(test->url),
3348
+ test->is_connect,
3349
+ &u);
3350
+
3351
+ if (test->rv == 0) {
3352
+ if (rv != 0) {
3353
+ printf("\n*** http_parser_parse_url(\"%s\") \"%s\" test failed, "
3354
+ "unexpected rv %d ***\n\n", test->url, test->name, rv);
3355
+ abort();
3356
+ }
3357
+
3358
+ if (memcmp(&u, &test->u, sizeof(u)) != 0) {
3359
+ printf("\n*** http_parser_parse_url(\"%s\") \"%s\" failed ***\n",
3360
+ test->url, test->name);
3361
+
3362
+ printf("target http_parser_url:\n");
3363
+ dump_url(test->url, &test->u);
3364
+ printf("result http_parser_url:\n");
3365
+ dump_url(test->url, &u);
3366
+
3367
+ abort();
3368
+ }
3369
+ } else {
3370
+ /* test->rv != 0 */
3371
+ if (rv == 0) {
3372
+ printf("\n*** http_parser_parse_url(\"%s\") \"%s\" test failed, "
3373
+ "unexpected rv %d ***\n\n", test->url, test->name, rv);
3374
+ abort();
3375
+ }
3376
+ }
3377
+ }
3378
+ }
3379
+
3380
+ void
3381
+ test_method_str (void)
3382
+ {
3383
+ assert(0 == strcmp("GET", http_method_str(HTTP_GET)));
3384
+ assert(0 == strcmp("<unknown>", http_method_str(1337)));
3385
+ }
3386
+
3387
+ void
3388
+ test_message (const struct message *message)
3389
+ {
3390
+ size_t raw_len = strlen(message->raw);
3391
+ size_t msg1len;
3392
+ for (msg1len = 0; msg1len < raw_len; msg1len++) {
3393
+ parser_init(message->type);
3394
+
3395
+ size_t read;
3396
+ const char *msg1 = message->raw;
3397
+ const char *msg2 = msg1 + msg1len;
3398
+ size_t msg2len = raw_len - msg1len;
3399
+
3400
+ if (msg1len) {
3401
+ read = parse(msg1, msg1len);
3402
+
3403
+ if (message->upgrade && parser->upgrade && num_messages > 0) {
3404
+ messages[num_messages - 1].upgrade = msg1 + read;
3405
+ goto test;
3406
+ }
3407
+
3408
+ if (read != msg1len) {
3409
+ print_error(msg1, read);
3410
+ abort();
3411
+ }
3412
+ }
3413
+
3414
+
3415
+ read = parse(msg2, msg2len);
3416
+
3417
+ if (message->upgrade && parser->upgrade) {
3418
+ messages[num_messages - 1].upgrade = msg2 + read;
3419
+ goto test;
3420
+ }
3421
+
3422
+ if (read != msg2len) {
3423
+ print_error(msg2, read);
3424
+ abort();
3425
+ }
3426
+
3427
+ read = parse(NULL, 0);
3428
+
3429
+ if (read != 0) {
3430
+ print_error(message->raw, read);
3431
+ abort();
3432
+ }
3433
+
3434
+ test:
3435
+
3436
+ if (num_messages != 1) {
3437
+ printf("\n*** num_messages != 1 after testing '%s' ***\n\n", message->name);
3438
+ abort();
3439
+ }
3440
+
3441
+ if(!message_eq(0, 0, message)) abort();
3442
+
3443
+ parser_free();
3444
+ }
3445
+ }
3446
+
3447
+ void
3448
+ test_message_count_body (const struct message *message)
3449
+ {
3450
+ parser_init(message->type);
3451
+
3452
+ size_t read;
3453
+ size_t l = strlen(message->raw);
3454
+ size_t i, toread;
3455
+ size_t chunk = 4024;
3456
+
3457
+ for (i = 0; i < l; i+= chunk) {
3458
+ toread = MIN(l-i, chunk);
3459
+ read = parse_count_body(message->raw + i, toread);
3460
+ if (read != toread) {
3461
+ print_error(message->raw, read);
3462
+ abort();
3463
+ }
3464
+ }
3465
+
3466
+
3467
+ read = parse_count_body(NULL, 0);
3468
+ if (read != 0) {
3469
+ print_error(message->raw, read);
3470
+ abort();
3471
+ }
3472
+
3473
+ if (num_messages != 1) {
3474
+ printf("\n*** num_messages != 1 after testing '%s' ***\n\n", message->name);
3475
+ abort();
3476
+ }
3477
+
3478
+ if(!message_eq(0, 0, message)) abort();
3479
+
3480
+ parser_free();
3481
+ }
3482
+
3483
+ void
3484
+ test_simple_type (const char *buf,
3485
+ enum http_errno err_expected,
3486
+ enum http_parser_type type)
3487
+ {
3488
+ parser_init(type);
3489
+
3490
+ enum http_errno err;
3491
+
3492
+ parse(buf, strlen(buf));
3493
+ err = HTTP_PARSER_ERRNO(parser);
3494
+ parse(NULL, 0);
3495
+
3496
+ parser_free();
3497
+
3498
+ /* In strict mode, allow us to pass with an unexpected HPE_STRICT as
3499
+ * long as the caller isn't expecting success.
3500
+ */
3501
+ #if HTTP_PARSER_STRICT
3502
+ if (err_expected != err && err_expected != HPE_OK && err != HPE_STRICT) {
3503
+ #else
3504
+ if (err_expected != err) {
3505
+ #endif
3506
+ fprintf(stderr, "\n*** test_simple expected %s, but saw %s ***\n\n%s\n",
3507
+ http_errno_name(err_expected), http_errno_name(err), buf);
3508
+ abort();
3509
+ }
3510
+ }
3511
+
3512
+ void
3513
+ test_simple (const char *buf, enum http_errno err_expected)
3514
+ {
3515
+ test_simple_type(buf, err_expected, HTTP_REQUEST);
3516
+ }
3517
+
3518
+ void
3519
+ test_invalid_header_content (int req, const char* str)
3520
+ {
3521
+ http_parser parser;
3522
+ http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
3523
+ size_t parsed;
3524
+ const char *buf;
3525
+ buf = req ?
3526
+ "GET / HTTP/1.1\r\n" :
3527
+ "HTTP/1.1 200 OK\r\n";
3528
+ parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
3529
+ assert(parsed == strlen(buf));
3530
+
3531
+ buf = str;
3532
+ size_t buflen = strlen(buf);
3533
+
3534
+ parsed = http_parser_execute(&parser, &settings_null, buf, buflen);
3535
+ if (parsed != buflen) {
3536
+ assert(HTTP_PARSER_ERRNO(&parser) == HPE_INVALID_HEADER_TOKEN);
3537
+ return;
3538
+ }
3539
+
3540
+ fprintf(stderr,
3541
+ "\n*** Error expected but none in invalid header content test ***\n");
3542
+ abort();
3543
+ }
3544
+
3545
+ void
3546
+ test_invalid_header_field_content_error (int req)
3547
+ {
3548
+ test_invalid_header_content(req, "Foo: F\01ailure");
3549
+ test_invalid_header_content(req, "Foo: B\02ar");
3550
+ }
3551
+
3552
+ void
3553
+ test_invalid_header_field (int req, const char* str)
3554
+ {
3555
+ http_parser parser;
3556
+ http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
3557
+ size_t parsed;
3558
+ const char *buf;
3559
+ buf = req ?
3560
+ "GET / HTTP/1.1\r\n" :
3561
+ "HTTP/1.1 200 OK\r\n";
3562
+ parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
3563
+ assert(parsed == strlen(buf));
3564
+
3565
+ buf = str;
3566
+ size_t buflen = strlen(buf);
3567
+
3568
+ parsed = http_parser_execute(&parser, &settings_null, buf, buflen);
3569
+ if (parsed != buflen) {
3570
+ assert(HTTP_PARSER_ERRNO(&parser) == HPE_INVALID_HEADER_TOKEN);
3571
+ return;
3572
+ }
3573
+
3574
+ fprintf(stderr,
3575
+ "\n*** Error expected but none in invalid header token test ***\n");
3576
+ abort();
3577
+ }
3578
+
3579
+ void
3580
+ test_invalid_header_field_token_error (int req)
3581
+ {
3582
+ test_invalid_header_field(req, "Fo@: Failure");
3583
+ test_invalid_header_field(req, "Foo\01\test: Bar");
3584
+ }
3585
+
3586
+ void
3587
+ test_double_content_length_error (int req)
3588
+ {
3589
+ http_parser parser;
3590
+ http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
3591
+ size_t parsed;
3592
+ const char *buf;
3593
+ buf = req ?
3594
+ "GET / HTTP/1.1\r\n" :
3595
+ "HTTP/1.1 200 OK\r\n";
3596
+ parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
3597
+ assert(parsed == strlen(buf));
3598
+
3599
+ buf = "Content-Length: 0\r\nContent-Length: 1\r\n\r\n";
3600
+ size_t buflen = strlen(buf);
3601
+
3602
+ parsed = http_parser_execute(&parser, &settings_null, buf, buflen);
3603
+ if (parsed != buflen) {
3604
+ assert(HTTP_PARSER_ERRNO(&parser) == HPE_UNEXPECTED_CONTENT_LENGTH);
3605
+ return;
3606
+ }
3607
+
3608
+ fprintf(stderr,
3609
+ "\n*** Error expected but none in double content-length test ***\n");
3610
+ abort();
3611
+ }
3612
+
3613
+ void
3614
+ test_chunked_content_length_error (int req)
3615
+ {
3616
+ http_parser parser;
3617
+ http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
3618
+ size_t parsed;
3619
+ const char *buf;
3620
+ buf = req ?
3621
+ "GET / HTTP/1.1\r\n" :
3622
+ "HTTP/1.1 200 OK\r\n";
3623
+ parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
3624
+ assert(parsed == strlen(buf));
3625
+
3626
+ buf = "Transfer-Encoding: chunked\r\nContent-Length: 1\r\n\r\n";
3627
+ size_t buflen = strlen(buf);
3628
+
3629
+ parsed = http_parser_execute(&parser, &settings_null, buf, buflen);
3630
+ if (parsed != buflen) {
3631
+ assert(HTTP_PARSER_ERRNO(&parser) == HPE_UNEXPECTED_CONTENT_LENGTH);
3632
+ return;
3633
+ }
3634
+
3635
+ fprintf(stderr,
3636
+ "\n*** Error expected but none in chunked content-length test ***\n");
3637
+ abort();
3638
+ }
3639
+
3640
+ void
3641
+ test_header_cr_no_lf_error (int req)
3642
+ {
3643
+ http_parser parser;
3644
+ http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
3645
+ size_t parsed;
3646
+ const char *buf;
3647
+ buf = req ?
3648
+ "GET / HTTP/1.1\r\n" :
3649
+ "HTTP/1.1 200 OK\r\n";
3650
+ parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
3651
+ assert(parsed == strlen(buf));
3652
+
3653
+ buf = "Foo: 1\rBar: 1\r\n\r\n";
3654
+ size_t buflen = strlen(buf);
3655
+
3656
+ parsed = http_parser_execute(&parser, &settings_null, buf, buflen);
3657
+ if (parsed != buflen) {
3658
+ assert(HTTP_PARSER_ERRNO(&parser) == HPE_LF_EXPECTED);
3659
+ return;
3660
+ }
3661
+
3662
+ fprintf(stderr,
3663
+ "\n*** Error expected but none in header whitespace test ***\n");
3664
+ abort();
3665
+ }
3666
+
3667
+ void
3668
+ test_header_overflow_error (int req)
3669
+ {
3670
+ http_parser parser;
3671
+ http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
3672
+ size_t parsed;
3673
+ const char *buf;
3674
+ buf = req ? "GET / HTTP/1.1\r\n" : "HTTP/1.0 200 OK\r\n";
3675
+ parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
3676
+ assert(parsed == strlen(buf));
3677
+
3678
+ buf = "header-key: header-value\r\n";
3679
+ size_t buflen = strlen(buf);
3680
+
3681
+ int i;
3682
+ for (i = 0; i < 10000; i++) {
3683
+ parsed = http_parser_execute(&parser, &settings_null, buf, buflen);
3684
+ if (parsed != buflen) {
3685
+ //fprintf(stderr, "error found on iter %d\n", i);
3686
+ assert(HTTP_PARSER_ERRNO(&parser) == HPE_HEADER_OVERFLOW);
3687
+ return;
3688
+ }
3689
+ }
3690
+
3691
+ fprintf(stderr, "\n*** Error expected but none in header overflow test ***\n");
3692
+ abort();
3693
+ }
3694
+
3695
+
3696
+ void
3697
+ test_header_nread_value ()
3698
+ {
3699
+ http_parser parser;
3700
+ http_parser_init(&parser, HTTP_REQUEST);
3701
+ size_t parsed;
3702
+ const char *buf;
3703
+ buf = "GET / HTTP/1.1\r\nheader: value\nhdr: value\r\n";
3704
+ parsed = http_parser_execute(&parser, &settings_null, buf, strlen(buf));
3705
+ assert(parsed == strlen(buf));
3706
+
3707
+ assert(parser.nread == strlen(buf));
3708
+ }
3709
+
3710
+
3711
+ static void
3712
+ test_content_length_overflow (const char *buf, size_t buflen, int expect_ok)
3713
+ {
3714
+ http_parser parser;
3715
+ http_parser_init(&parser, HTTP_RESPONSE);
3716
+ http_parser_execute(&parser, &settings_null, buf, buflen);
3717
+
3718
+ if (expect_ok)
3719
+ assert(HTTP_PARSER_ERRNO(&parser) == HPE_OK);
3720
+ else
3721
+ assert(HTTP_PARSER_ERRNO(&parser) == HPE_INVALID_CONTENT_LENGTH);
3722
+ }
3723
+
3724
+ void
3725
+ test_header_content_length_overflow_error (void)
3726
+ {
3727
+ #define X(size) \
3728
+ "HTTP/1.1 200 OK\r\n" \
3729
+ "Content-Length: " #size "\r\n" \
3730
+ "\r\n"
3731
+ const char a[] = X(1844674407370955160); /* 2^64 / 10 - 1 */
3732
+ const char b[] = X(18446744073709551615); /* 2^64-1 */
3733
+ const char c[] = X(18446744073709551616); /* 2^64 */
3734
+ #undef X
3735
+ test_content_length_overflow(a, sizeof(a) - 1, 1); /* expect ok */
3736
+ test_content_length_overflow(b, sizeof(b) - 1, 0); /* expect failure */
3737
+ test_content_length_overflow(c, sizeof(c) - 1, 0); /* expect failure */
3738
+ }
3739
+
3740
+ void
3741
+ test_chunk_content_length_overflow_error (void)
3742
+ {
3743
+ #define X(size) \
3744
+ "HTTP/1.1 200 OK\r\n" \
3745
+ "Transfer-Encoding: chunked\r\n" \
3746
+ "\r\n" \
3747
+ #size "\r\n" \
3748
+ "..."
3749
+ const char a[] = X(FFFFFFFFFFFFFFE); /* 2^64 / 16 - 1 */
3750
+ const char b[] = X(FFFFFFFFFFFFFFFF); /* 2^64-1 */
3751
+ const char c[] = X(10000000000000000); /* 2^64 */
3752
+ #undef X
3753
+ test_content_length_overflow(a, sizeof(a) - 1, 1); /* expect ok */
3754
+ test_content_length_overflow(b, sizeof(b) - 1, 0); /* expect failure */
3755
+ test_content_length_overflow(c, sizeof(c) - 1, 0); /* expect failure */
3756
+ }
3757
+
3758
+ void
3759
+ test_no_overflow_long_body (int req, size_t length)
3760
+ {
3761
+ http_parser parser;
3762
+ http_parser_init(&parser, req ? HTTP_REQUEST : HTTP_RESPONSE);
3763
+ size_t parsed;
3764
+ size_t i;
3765
+ char buf1[3000];
3766
+ size_t buf1len = sprintf(buf1, "%s\r\nConnection: Keep-Alive\r\nContent-Length: %lu\r\n\r\n",
3767
+ req ? "POST / HTTP/1.0" : "HTTP/1.0 200 OK", (unsigned long)length);
3768
+ parsed = http_parser_execute(&parser, &settings_null, buf1, buf1len);
3769
+ if (parsed != buf1len)
3770
+ goto err;
3771
+
3772
+ for (i = 0; i < length; i++) {
3773
+ char foo = 'a';
3774
+ parsed = http_parser_execute(&parser, &settings_null, &foo, 1);
3775
+ if (parsed != 1)
3776
+ goto err;
3777
+ }
3778
+
3779
+ parsed = http_parser_execute(&parser, &settings_null, buf1, buf1len);
3780
+ if (parsed != buf1len) goto err;
3781
+ return;
3782
+
3783
+ err:
3784
+ fprintf(stderr,
3785
+ "\n*** error in test_no_overflow_long_body %s of length %lu ***\n",
3786
+ req ? "REQUEST" : "RESPONSE",
3787
+ (unsigned long)length);
3788
+ abort();
3789
+ }
3790
+
3791
+ void
3792
+ test_multiple3 (const struct message *r1, const struct message *r2, const struct message *r3)
3793
+ {
3794
+ int message_count = count_parsed_messages(3, r1, r2, r3);
3795
+
3796
+ char total[ strlen(r1->raw)
3797
+ + strlen(r2->raw)
3798
+ + strlen(r3->raw)
3799
+ + 1
3800
+ ];
3801
+ total[0] = '\0';
3802
+
3803
+ strcat(total, r1->raw);
3804
+ strcat(total, r2->raw);
3805
+ strcat(total, r3->raw);
3806
+
3807
+ parser_init(r1->type);
3808
+
3809
+ size_t read;
3810
+
3811
+ read = parse(total, strlen(total));
3812
+
3813
+ if (parser->upgrade) {
3814
+ upgrade_message_fix(total, read, 3, r1, r2, r3);
3815
+ goto test;
3816
+ }
3817
+
3818
+ if (read != strlen(total)) {
3819
+ print_error(total, read);
3820
+ abort();
3821
+ }
3822
+
3823
+ read = parse(NULL, 0);
3824
+
3825
+ if (read != 0) {
3826
+ print_error(total, read);
3827
+ abort();
3828
+ }
3829
+
3830
+ test:
3831
+
3832
+ if (message_count != num_messages) {
3833
+ fprintf(stderr, "\n\n*** Parser didn't see 3 messages only %d *** \n", num_messages);
3834
+ abort();
3835
+ }
3836
+
3837
+ if (!message_eq(0, 0, r1)) abort();
3838
+ if (message_count > 1 && !message_eq(1, 0, r2)) abort();
3839
+ if (message_count > 2 && !message_eq(2, 0, r3)) abort();
3840
+
3841
+ parser_free();
3842
+ }
3843
+
3844
+ /* SCAN through every possible breaking to make sure the
3845
+ * parser can handle getting the content in any chunks that
3846
+ * might come from the socket
3847
+ */
3848
+ void
3849
+ test_scan (const struct message *r1, const struct message *r2, const struct message *r3)
3850
+ {
3851
+ char total[80*1024] = "\0";
3852
+ char buf1[80*1024] = "\0";
3853
+ char buf2[80*1024] = "\0";
3854
+ char buf3[80*1024] = "\0";
3855
+
3856
+ strcat(total, r1->raw);
3857
+ strcat(total, r2->raw);
3858
+ strcat(total, r3->raw);
3859
+
3860
+ size_t read;
3861
+
3862
+ int total_len = strlen(total);
3863
+
3864
+ int total_ops = 2 * (total_len - 1) * (total_len - 2) / 2;
3865
+ int ops = 0 ;
3866
+
3867
+ size_t buf1_len, buf2_len, buf3_len;
3868
+ int message_count = count_parsed_messages(3, r1, r2, r3);
3869
+
3870
+ int i,j,type_both;
3871
+ for (type_both = 0; type_both < 2; type_both ++ ) {
3872
+ for (j = 2; j < total_len; j ++ ) {
3873
+ for (i = 1; i < j; i ++ ) {
3874
+
3875
+ if (ops % 1000 == 0) {
3876
+ printf("\b\b\b\b%3.0f%%", 100 * (float)ops /(float)total_ops);
3877
+ fflush(stdout);
3878
+ }
3879
+ ops += 1;
3880
+
3881
+ parser_init(type_both ? HTTP_BOTH : r1->type);
3882
+
3883
+ buf1_len = i;
3884
+ strlncpy(buf1, sizeof(buf1), total, buf1_len);
3885
+ buf1[buf1_len] = 0;
3886
+
3887
+ buf2_len = j - i;
3888
+ strlncpy(buf2, sizeof(buf1), total+i, buf2_len);
3889
+ buf2[buf2_len] = 0;
3890
+
3891
+ buf3_len = total_len - j;
3892
+ strlncpy(buf3, sizeof(buf1), total+j, buf3_len);
3893
+ buf3[buf3_len] = 0;
3894
+
3895
+ read = parse(buf1, buf1_len);
3896
+
3897
+ if (parser->upgrade) goto test;
3898
+
3899
+ if (read != buf1_len) {
3900
+ print_error(buf1, read);
3901
+ goto error;
3902
+ }
3903
+
3904
+ read += parse(buf2, buf2_len);
3905
+
3906
+ if (parser->upgrade) goto test;
3907
+
3908
+ if (read != buf1_len + buf2_len) {
3909
+ print_error(buf2, read);
3910
+ goto error;
3911
+ }
3912
+
3913
+ read += parse(buf3, buf3_len);
3914
+
3915
+ if (parser->upgrade) goto test;
3916
+
3917
+ if (read != buf1_len + buf2_len + buf3_len) {
3918
+ print_error(buf3, read);
3919
+ goto error;
3920
+ }
3921
+
3922
+ parse(NULL, 0);
3923
+
3924
+ test:
3925
+ if (parser->upgrade) {
3926
+ upgrade_message_fix(total, read, 3, r1, r2, r3);
3927
+ }
3928
+
3929
+ if (message_count != num_messages) {
3930
+ fprintf(stderr, "\n\nParser didn't see %d messages only %d\n",
3931
+ message_count, num_messages);
3932
+ goto error;
3933
+ }
3934
+
3935
+ if (!message_eq(0, 0, r1)) {
3936
+ fprintf(stderr, "\n\nError matching messages[0] in test_scan.\n");
3937
+ goto error;
3938
+ }
3939
+
3940
+ if (message_count > 1 && !message_eq(1, 0, r2)) {
3941
+ fprintf(stderr, "\n\nError matching messages[1] in test_scan.\n");
3942
+ goto error;
3943
+ }
3944
+
3945
+ if (message_count > 2 && !message_eq(2, 0, r3)) {
3946
+ fprintf(stderr, "\n\nError matching messages[2] in test_scan.\n");
3947
+ goto error;
3948
+ }
3949
+
3950
+ parser_free();
3951
+ }
3952
+ }
3953
+ }
3954
+ puts("\b\b\b\b100%");
3955
+ return;
3956
+
3957
+ error:
3958
+ fprintf(stderr, "i=%d j=%d\n", i, j);
3959
+ fprintf(stderr, "buf1 (%u) %s\n\n", (unsigned int)buf1_len, buf1);
3960
+ fprintf(stderr, "buf2 (%u) %s\n\n", (unsigned int)buf2_len , buf2);
3961
+ fprintf(stderr, "buf3 (%u) %s\n", (unsigned int)buf3_len, buf3);
3962
+ abort();
3963
+ }
3964
+
3965
+ // user required to free the result
3966
+ // string terminated by \0
3967
+ char *
3968
+ create_large_chunked_message (int body_size_in_kb, const char* headers)
3969
+ {
3970
+ int i;
3971
+ size_t wrote = 0;
3972
+ size_t headers_len = strlen(headers);
3973
+ size_t bufsize = headers_len + (5+1024+2)*body_size_in_kb + 6;
3974
+ char * buf = malloc(bufsize);
3975
+
3976
+ memcpy(buf, headers, headers_len);
3977
+ wrote += headers_len;
3978
+
3979
+ for (i = 0; i < body_size_in_kb; i++) {
3980
+ // write 1kb chunk into the body.
3981
+ memcpy(buf + wrote, "400\r\n", 5);
3982
+ wrote += 5;
3983
+ memset(buf + wrote, 'C', 1024);
3984
+ wrote += 1024;
3985
+ strcpy(buf + wrote, "\r\n");
3986
+ wrote += 2;
3987
+ }
3988
+
3989
+ memcpy(buf + wrote, "0\r\n\r\n", 6);
3990
+ wrote += 6;
3991
+ assert(wrote == bufsize);
3992
+
3993
+ return buf;
3994
+ }
3995
+
3996
+ /* Verify that we can pause parsing at any of the bytes in the
3997
+ * message and still get the result that we're expecting. */
3998
+ void
3999
+ test_message_pause (const struct message *msg)
4000
+ {
4001
+ char *buf = (char*) msg->raw;
4002
+ size_t buflen = strlen(msg->raw);
4003
+ size_t nread;
4004
+
4005
+ parser_init(msg->type);
4006
+
4007
+ do {
4008
+ nread = parse_pause(buf, buflen);
4009
+
4010
+ // We can only set the upgrade buffer once we've gotten our message
4011
+ // completion callback.
4012
+ if (messages[0].message_complete_cb_called &&
4013
+ msg->upgrade &&
4014
+ parser->upgrade) {
4015
+ messages[0].upgrade = buf + nread;
4016
+ goto test;
4017
+ }
4018
+
4019
+ if (nread < buflen) {
4020
+
4021
+ // Not much do to if we failed a strict-mode check
4022
+ if (HTTP_PARSER_ERRNO(parser) == HPE_STRICT) {
4023
+ parser_free();
4024
+ return;
4025
+ }
4026
+
4027
+ assert (HTTP_PARSER_ERRNO(parser) == HPE_PAUSED);
4028
+ }
4029
+
4030
+ buf += nread;
4031
+ buflen -= nread;
4032
+ http_parser_pause(parser, 0);
4033
+ } while (buflen > 0);
4034
+
4035
+ nread = parse_pause(NULL, 0);
4036
+ assert (nread == 0);
4037
+
4038
+ test:
4039
+ if (num_messages != 1) {
4040
+ printf("\n*** num_messages != 1 after testing '%s' ***\n\n", msg->name);
4041
+ abort();
4042
+ }
4043
+
4044
+ if(!message_eq(0, 0, msg)) abort();
4045
+
4046
+ parser_free();
4047
+ }
4048
+
4049
+ /* Verify that body and next message won't be parsed in responses to CONNECT */
4050
+ void
4051
+ test_message_connect (const struct message *msg)
4052
+ {
4053
+ char *buf = (char*) msg->raw;
4054
+ size_t buflen = strlen(msg->raw);
4055
+
4056
+ parser_init(msg->type);
4057
+
4058
+ parse_connect(buf, buflen);
4059
+
4060
+ if (num_messages != 1) {
4061
+ printf("\n*** num_messages != 1 after testing '%s' ***\n\n", msg->name);
4062
+ abort();
4063
+ }
4064
+
4065
+ if(!message_eq(0, 1, msg)) abort();
4066
+
4067
+ parser_free();
4068
+ }
4069
+
4070
+ int
4071
+ main (void)
4072
+ {
4073
+ parser = NULL;
4074
+ int i, j, k;
4075
+ int request_count;
4076
+ int response_count;
4077
+ unsigned long version;
4078
+ unsigned major;
4079
+ unsigned minor;
4080
+ unsigned patch;
4081
+
4082
+ version = http_parser_version();
4083
+ major = (version >> 16) & 255;
4084
+ minor = (version >> 8) & 255;
4085
+ patch = version & 255;
4086
+ printf("http_parser v%u.%u.%u (0x%06lx)\n", major, minor, patch, version);
4087
+
4088
+ printf("sizeof(http_parser) = %u\n", (unsigned int)sizeof(http_parser));
4089
+
4090
+ for (request_count = 0; requests[request_count].name; request_count++);
4091
+ for (response_count = 0; responses[response_count].name; response_count++);
4092
+
4093
+ //// API
4094
+ test_preserve_data();
4095
+ test_parse_url();
4096
+ test_method_str();
4097
+
4098
+ //// NREAD
4099
+ test_header_nread_value();
4100
+
4101
+ //// OVERFLOW CONDITIONS
4102
+
4103
+ test_header_overflow_error(HTTP_REQUEST);
4104
+ test_no_overflow_long_body(HTTP_REQUEST, 1000);
4105
+ test_no_overflow_long_body(HTTP_REQUEST, 100000);
4106
+
4107
+ test_header_overflow_error(HTTP_RESPONSE);
4108
+ test_no_overflow_long_body(HTTP_RESPONSE, 1000);
4109
+ test_no_overflow_long_body(HTTP_RESPONSE, 100000);
4110
+
4111
+ test_header_content_length_overflow_error();
4112
+ test_chunk_content_length_overflow_error();
4113
+
4114
+ //// HEADER FIELD CONDITIONS
4115
+ test_double_content_length_error(HTTP_REQUEST);
4116
+ test_chunked_content_length_error(HTTP_REQUEST);
4117
+ test_header_cr_no_lf_error(HTTP_REQUEST);
4118
+ test_invalid_header_field_token_error(HTTP_REQUEST);
4119
+ test_invalid_header_field_content_error(HTTP_REQUEST);
4120
+ test_double_content_length_error(HTTP_RESPONSE);
4121
+ test_chunked_content_length_error(HTTP_RESPONSE);
4122
+ test_header_cr_no_lf_error(HTTP_RESPONSE);
4123
+ test_invalid_header_field_token_error(HTTP_RESPONSE);
4124
+ test_invalid_header_field_content_error(HTTP_RESPONSE);
4125
+
4126
+ //// RESPONSES
4127
+
4128
+ test_simple_type("HTP/1.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
4129
+ test_simple_type("HTTP/01.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
4130
+ test_simple_type("HTTP/11.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
4131
+ test_simple_type("HTTP/1.01 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
4132
+ test_simple_type("HTTP/1.1\t200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
4133
+
4134
+ for (i = 0; i < response_count; i++) {
4135
+ test_message(&responses[i]);
4136
+ }
4137
+
4138
+ for (i = 0; i < response_count; i++) {
4139
+ test_message_pause(&responses[i]);
4140
+ }
4141
+
4142
+ for (i = 0; i < response_count; i++) {
4143
+ test_message_connect(&responses[i]);
4144
+ }
4145
+
4146
+ for (i = 0; i < response_count; i++) {
4147
+ if (!responses[i].should_keep_alive) continue;
4148
+ for (j = 0; j < response_count; j++) {
4149
+ if (!responses[j].should_keep_alive) continue;
4150
+ for (k = 0; k < response_count; k++) {
4151
+ test_multiple3(&responses[i], &responses[j], &responses[k]);
4152
+ }
4153
+ }
4154
+ }
4155
+
4156
+ test_message_count_body(&responses[NO_HEADERS_NO_BODY_404]);
4157
+ test_message_count_body(&responses[TRAILING_SPACE_ON_CHUNKED_BODY]);
4158
+
4159
+ // test very large chunked response
4160
+ {
4161
+ char * msg = create_large_chunked_message(31337,
4162
+ "HTTP/1.0 200 OK\r\n"
4163
+ "Transfer-Encoding: chunked\r\n"
4164
+ "Content-Type: text/plain\r\n"
4165
+ "\r\n");
4166
+ struct message large_chunked =
4167
+ {.name= "large chunked"
4168
+ ,.type= HTTP_RESPONSE
4169
+ ,.raw= msg
4170
+ ,.should_keep_alive= FALSE
4171
+ ,.message_complete_on_eof= FALSE
4172
+ ,.http_major= 1
4173
+ ,.http_minor= 0
4174
+ ,.status_code= 200
4175
+ ,.response_status= "OK"
4176
+ ,.num_headers= 2
4177
+ ,.headers=
4178
+ { { "Transfer-Encoding", "chunked" }
4179
+ , { "Content-Type", "text/plain" }
4180
+ }
4181
+ ,.body_size= 31337*1024
4182
+ ,.num_chunks_complete= 31338
4183
+ };
4184
+ for (i = 0; i < MAX_CHUNKS; i++) {
4185
+ large_chunked.chunk_lengths[i] = 1024;
4186
+ }
4187
+ test_message_count_body(&large_chunked);
4188
+ free(msg);
4189
+ }
4190
+
4191
+
4192
+
4193
+ printf("response scan 1/2 ");
4194
+ test_scan( &responses[TRAILING_SPACE_ON_CHUNKED_BODY]
4195
+ , &responses[NO_BODY_HTTP10_KA_204]
4196
+ , &responses[NO_REASON_PHRASE]
4197
+ );
4198
+
4199
+ printf("response scan 2/2 ");
4200
+ test_scan( &responses[BONJOUR_MADAME_FR]
4201
+ , &responses[UNDERSTORE_HEADER_KEY]
4202
+ , &responses[NO_CARRIAGE_RET]
4203
+ );
4204
+
4205
+ puts("responses okay");
4206
+
4207
+
4208
+ /// REQUESTS
4209
+
4210
+ test_simple("GET / HTP/1.1\r\n\r\n", HPE_INVALID_VERSION);
4211
+ test_simple("GET / HTTP/01.1\r\n\r\n", HPE_INVALID_VERSION);
4212
+ test_simple("GET / HTTP/11.1\r\n\r\n", HPE_INVALID_VERSION);
4213
+ test_simple("GET / HTTP/1.01\r\n\r\n", HPE_INVALID_VERSION);
4214
+
4215
+ // Extended characters - see nodejs/test/parallel/test-http-headers-obstext.js
4216
+ test_simple("GET / HTTP/1.1\r\n"
4217
+ "Test: Düsseldorf\r\n",
4218
+ HPE_OK);
4219
+
4220
+ // Well-formed but incomplete
4221
+ test_simple("GET / HTTP/1.1\r\n"
4222
+ "Content-Type: text/plain\r\n"
4223
+ "Content-Length: 6\r\n"
4224
+ "\r\n"
4225
+ "fooba",
4226
+ HPE_OK);
4227
+
4228
+ static const char *all_methods[] = {
4229
+ "DELETE",
4230
+ "GET",
4231
+ "HEAD",
4232
+ "POST",
4233
+ "PUT",
4234
+ //"CONNECT", //CONNECT can't be tested like other methods, it's a tunnel
4235
+ "OPTIONS",
4236
+ "TRACE",
4237
+ "COPY",
4238
+ "LOCK",
4239
+ "MKCOL",
4240
+ "MOVE",
4241
+ "PROPFIND",
4242
+ "PROPPATCH",
4243
+ "SEARCH",
4244
+ "UNLOCK",
4245
+ "BIND",
4246
+ "REBIND",
4247
+ "UNBIND",
4248
+ "ACL",
4249
+ "REPORT",
4250
+ "MKACTIVITY",
4251
+ "CHECKOUT",
4252
+ "MERGE",
4253
+ "M-SEARCH",
4254
+ "NOTIFY",
4255
+ "SUBSCRIBE",
4256
+ "UNSUBSCRIBE",
4257
+ "PATCH",
4258
+ "PURGE",
4259
+ "MKCALENDAR",
4260
+ "LINK",
4261
+ "UNLINK",
4262
+ 0 };
4263
+ const char **this_method;
4264
+ for (this_method = all_methods; *this_method; this_method++) {
4265
+ char buf[200];
4266
+ sprintf(buf, "%s / HTTP/1.1\r\n\r\n", *this_method);
4267
+ test_simple(buf, HPE_OK);
4268
+ }
4269
+
4270
+ static const char *bad_methods[] = {
4271
+ "ASDF",
4272
+ "C******",
4273
+ "COLA",
4274
+ "GEM",
4275
+ "GETA",
4276
+ "M****",
4277
+ "MKCOLA",
4278
+ "PROPPATCHA",
4279
+ "PUN",
4280
+ "PX",
4281
+ "SA",
4282
+ "hello world",
4283
+ 0 };
4284
+ for (this_method = bad_methods; *this_method; this_method++) {
4285
+ char buf[200];
4286
+ sprintf(buf, "%s / HTTP/1.1\r\n\r\n", *this_method);
4287
+ test_simple(buf, HPE_INVALID_METHOD);
4288
+ }
4289
+
4290
+ // illegal header field name line folding
4291
+ test_simple("GET / HTTP/1.1\r\n"
4292
+ "name\r\n"
4293
+ " : value\r\n"
4294
+ "\r\n",
4295
+ HPE_INVALID_HEADER_TOKEN);
4296
+
4297
+ const char *dumbfuck2 =
4298
+ "GET / HTTP/1.1\r\n"
4299
+ "X-SSL-Bullshit: -----BEGIN CERTIFICATE-----\r\n"
4300
+ "\tMIIFbTCCBFWgAwIBAgICH4cwDQYJKoZIhvcNAQEFBQAwcDELMAkGA1UEBhMCVUsx\r\n"
4301
+ "\tETAPBgNVBAoTCGVTY2llbmNlMRIwEAYDVQQLEwlBdXRob3JpdHkxCzAJBgNVBAMT\r\n"
4302
+ "\tAkNBMS0wKwYJKoZIhvcNAQkBFh5jYS1vcGVyYXRvckBncmlkLXN1cHBvcnQuYWMu\r\n"
4303
+ "\tdWswHhcNMDYwNzI3MTQxMzI4WhcNMDcwNzI3MTQxMzI4WjBbMQswCQYDVQQGEwJV\r\n"
4304
+ "\tSzERMA8GA1UEChMIZVNjaWVuY2UxEzARBgNVBAsTCk1hbmNoZXN0ZXIxCzAJBgNV\r\n"
4305
+ "\tBAcTmrsogriqMWLAk1DMRcwFQYDVQQDEw5taWNoYWVsIHBhcmQYJKoZIhvcNAQEB\r\n"
4306
+ "\tBQADggEPADCCAQoCggEBANPEQBgl1IaKdSS1TbhF3hEXSl72G9J+WC/1R64fAcEF\r\n"
4307
+ "\tW51rEyFYiIeZGx/BVzwXbeBoNUK41OK65sxGuflMo5gLflbwJtHBRIEKAfVVp3YR\r\n"
4308
+ "\tgW7cMA/s/XKgL1GEC7rQw8lIZT8RApukCGqOVHSi/F1SiFlPDxuDfmdiNzL31+sL\r\n"
4309
+ "\t0iwHDdNkGjy5pyBSB8Y79dsSJtCW/iaLB0/n8Sj7HgvvZJ7x0fr+RQjYOUUfrePP\r\n"
4310
+ "\tu2MSpFyf+9BbC/aXgaZuiCvSR+8Snv3xApQY+fULK/xY8h8Ua51iXoQ5jrgu2SqR\r\n"
4311
+ "\twgA7BUi3G8LFzMBl8FRCDYGUDy7M6QaHXx1ZWIPWNKsCAwEAAaOCAiQwggIgMAwG\r\n"
4312
+ "\tA1UdEwEB/wQCMAAwEQYJYIZIAYb4QgHTTPAQDAgWgMA4GA1UdDwEB/wQEAwID6DAs\r\n"
4313
+ "\tBglghkgBhvhCAQ0EHxYdVUsgZS1TY2llbmNlIFVzZXIgQ2VydGlmaWNhdGUwHQYD\r\n"
4314
+ "\tVR0OBBYEFDTt/sf9PeMaZDHkUIldrDYMNTBZMIGaBgNVHSMEgZIwgY+AFAI4qxGj\r\n"
4315
+ "\tloCLDdMVKwiljjDastqooXSkcjBwMQswCQYDVQQGEwJVSzERMA8GA1UEChMIZVNj\r\n"
4316
+ "\taWVuY2UxEjAQBgNVBAsTCUF1dGhvcml0eTELMAkGA1UEAxMCQ0ExLTArBgkqhkiG\r\n"
4317
+ "\t9w0BCQEWHmNhLW9wZXJhdG9yQGdyaWQtc3VwcG9ydC5hYy51a4IBADApBgNVHRIE\r\n"
4318
+ "\tIjAggR5jYS1vcGVyYXRvckBncmlkLXN1cHBvcnQuYWMudWswGQYDVR0gBBIwEDAO\r\n"
4319
+ "\tBgwrBgEEAdkvAQEBAQYwPQYJYIZIAYb4QgEEBDAWLmh0dHA6Ly9jYS5ncmlkLXN1\r\n"
4320
+ "\tcHBvcnQuYWMudmT4sopwqlBWsvcHViL2NybC9jYWNybC5jcmwwPQYJYIZIAYb4QgEDBDAWLmh0\r\n"
4321
+ "\tdHA6Ly9jYS5ncmlkLXN1cHBvcnQuYWMudWsvcHViL2NybC9jYWNybC5jcmwwPwYD\r\n"
4322
+ "\tVR0fBDgwNjA0oDKgMIYuaHR0cDovL2NhLmdyaWQt5hYy51ay9wdWIv\r\n"
4323
+ "\tY3JsL2NhY3JsLmNybDANBgkqhkiG9w0BAQUFAAOCAQEAS/U4iiooBENGW/Hwmmd3\r\n"
4324
+ "\tXCy6Zrt08YjKCzGNjorT98g8uGsqYjSxv/hmi0qlnlHs+k/3Iobc3LjS5AMYr5L8\r\n"
4325
+ "\tUO7OSkgFFlLHQyC9JzPfmLCAugvzEbyv4Olnsr8hbxF1MbKZoQxUZtMVu29wjfXk\r\n"
4326
+ "\thTeApBv7eaKCWpSp7MCbvgzm74izKhu3vlDk9w6qVrxePfGgpKPqfHiOoGhFnbTK\r\n"
4327
+ "\twTC6o2xq5y0qZ03JonF7OJspEd3I5zKY3E+ov7/ZhW6DqT8UFvsAdjvQbXyhV8Eu\r\n"
4328
+ "\tYhixw1aKEPzNjNowuIseVogKOLXxWI5vAi5HgXdS0/ES5gDGsABo4fqovUKlgop3\r\n"
4329
+ "\tRA==\r\n"
4330
+ "\t-----END CERTIFICATE-----\r\n"
4331
+ "\r\n";
4332
+ test_simple(dumbfuck2, HPE_OK);
4333
+
4334
+ const char *corrupted_connection =
4335
+ "GET / HTTP/1.1\r\n"
4336
+ "Host: www.example.com\r\n"
4337
+ "Connection\r\033\065\325eep-Alive\r\n"
4338
+ "Accept-Encoding: gzip\r\n"
4339
+ "\r\n";
4340
+ test_simple(corrupted_connection, HPE_INVALID_HEADER_TOKEN);
4341
+
4342
+ const char *corrupted_header_name =
4343
+ "GET / HTTP/1.1\r\n"
4344
+ "Host: www.example.com\r\n"
4345
+ "X-Some-Header\r\033\065\325eep-Alive\r\n"
4346
+ "Accept-Encoding: gzip\r\n"
4347
+ "\r\n";
4348
+ test_simple(corrupted_header_name, HPE_INVALID_HEADER_TOKEN);
4349
+
4350
+ #if 0
4351
+ // NOTE(Wed Nov 18 11:57:27 CET 2009) this seems okay. we just read body
4352
+ // until EOF.
4353
+ //
4354
+ // no content-length
4355
+ // error if there is a body without content length
4356
+ const char *bad_get_no_headers_no_body = "GET /bad_get_no_headers_no_body/world HTTP/1.1\r\n"
4357
+ "Accept: */*\r\n"
4358
+ "\r\n"
4359
+ "HELLO";
4360
+ test_simple(bad_get_no_headers_no_body, 0);
4361
+ #endif
4362
+ /* TODO sending junk and large headers gets rejected */
4363
+
4364
+
4365
+ /* check to make sure our predefined requests are okay */
4366
+ for (i = 0; requests[i].name; i++) {
4367
+ test_message(&requests[i]);
4368
+ }
4369
+
4370
+ for (i = 0; i < request_count; i++) {
4371
+ test_message_pause(&requests[i]);
4372
+ }
4373
+
4374
+ for (i = 0; i < request_count; i++) {
4375
+ if (!requests[i].should_keep_alive) continue;
4376
+ for (j = 0; j < request_count; j++) {
4377
+ if (!requests[j].should_keep_alive) continue;
4378
+ for (k = 0; k < request_count; k++) {
4379
+ test_multiple3(&requests[i], &requests[j], &requests[k]);
4380
+ }
4381
+ }
4382
+ }
4383
+
4384
+ printf("request scan 1/4 ");
4385
+ test_scan( &requests[GET_NO_HEADERS_NO_BODY]
4386
+ , &requests[GET_ONE_HEADER_NO_BODY]
4387
+ , &requests[GET_NO_HEADERS_NO_BODY]
4388
+ );
4389
+
4390
+ printf("request scan 2/4 ");
4391
+ test_scan( &requests[POST_CHUNKED_ALL_YOUR_BASE]
4392
+ , &requests[POST_IDENTITY_BODY_WORLD]
4393
+ , &requests[GET_FUNKY_CONTENT_LENGTH]
4394
+ );
4395
+
4396
+ printf("request scan 3/4 ");
4397
+ test_scan( &requests[TWO_CHUNKS_MULT_ZERO_END]
4398
+ , &requests[CHUNKED_W_TRAILING_HEADERS]
4399
+ , &requests[CHUNKED_W_BULLSHIT_AFTER_LENGTH]
4400
+ );
4401
+
4402
+ printf("request scan 4/4 ");
4403
+ test_scan( &requests[QUERY_URL_WITH_QUESTION_MARK_GET]
4404
+ , &requests[PREFIX_NEWLINE_GET ]
4405
+ , &requests[CONNECT_REQUEST]
4406
+ );
4407
+
4408
+ puts("requests okay");
4409
+
4410
+ return 0;
4411
+ }