protocol-quic 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/ext/ngtcp2/AUTHORS +44 -0
- data/ext/ngtcp2/CMakeLists.txt +431 -0
- data/ext/ngtcp2/CMakeOptions.txt +17 -0
- data/ext/ngtcp2/COPYING +22 -0
- data/ext/ngtcp2/ChangeLog +0 -0
- data/ext/ngtcp2/Makefile.am +60 -0
- data/ext/ngtcp2/NEWS +0 -0
- data/ext/ngtcp2/README +1 -0
- data/ext/ngtcp2/README.rst +258 -0
- data/ext/ngtcp2/ci/build_boringssl.sh +10 -0
- data/ext/ngtcp2/ci/build_nghttp3.sh +9 -0
- data/ext/ngtcp2/ci/build_openssl1.sh +8 -0
- data/ext/ngtcp2/ci/build_openssl1_cross.sh +9 -0
- data/ext/ngtcp2/ci/build_openssl3.sh +8 -0
- data/ext/ngtcp2/ci/build_picotls.sh +26 -0
- data/ext/ngtcp2/ci/build_wolfssl.sh +9 -0
- data/ext/ngtcp2/ci/gen-certificate.sh +8 -0
- data/ext/ngtcp2/cmake/ExtractValidFlags.cmake +31 -0
- data/ext/ngtcp2/cmake/FindCUnit.cmake +40 -0
- data/ext/ngtcp2/cmake/FindJemalloc.cmake +40 -0
- data/ext/ngtcp2/cmake/FindLibev.cmake +38 -0
- data/ext/ngtcp2/cmake/FindLibnghttp3.cmake +41 -0
- data/ext/ngtcp2/cmake/Findwolfssl.cmake +41 -0
- data/ext/ngtcp2/cmake/Version.cmake +11 -0
- data/ext/ngtcp2/cmakeconfig.h.in +36 -0
- data/ext/ngtcp2/configure.ac +755 -0
- data/ext/ngtcp2/crypto/CMakeLists.txt +56 -0
- data/ext/ngtcp2/crypto/Makefile.am +49 -0
- data/ext/ngtcp2/crypto/boringssl/CMakeLists.txt +64 -0
- data/ext/ngtcp2/crypto/boringssl/Makefile.am +39 -0
- data/ext/ngtcp2/crypto/boringssl/boringssl.c +630 -0
- data/ext/ngtcp2/crypto/boringssl/libngtcp2_crypto_boringssl.pc.in +33 -0
- data/ext/ngtcp2/crypto/gnutls/CMakeLists.txt +86 -0
- data/ext/ngtcp2/crypto/gnutls/Makefile.am +43 -0
- data/ext/ngtcp2/crypto/gnutls/gnutls.c +644 -0
- data/ext/ngtcp2/crypto/gnutls/libngtcp2_crypto_gnutls.pc.in +33 -0
- data/ext/ngtcp2/crypto/includes/CMakeLists.txt +56 -0
- data/ext/ngtcp2/crypto/includes/Makefile.am +45 -0
- data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto.h +893 -0
- data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_boringssl.h +104 -0
- data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_gnutls.h +107 -0
- data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h +132 -0
- data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_picotls.h +246 -0
- data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_wolfssl.h +106 -0
- data/ext/ngtcp2/crypto/openssl/CMakeLists.txt +86 -0
- data/ext/ngtcp2/crypto/openssl/Makefile.am +43 -0
- data/ext/ngtcp2/crypto/openssl/libngtcp2_crypto_openssl.pc.in +33 -0
- data/ext/ngtcp2/crypto/openssl/openssl.c +807 -0
- data/ext/ngtcp2/crypto/picotls/CMakeLists.txt +65 -0
- data/ext/ngtcp2/crypto/picotls/Makefile.am +39 -0
- data/ext/ngtcp2/crypto/picotls/libngtcp2_crypto_picotls.pc.in +33 -0
- data/ext/ngtcp2/crypto/picotls/picotls.c +707 -0
- data/ext/ngtcp2/crypto/shared.c +1431 -0
- data/ext/ngtcp2/crypto/shared.h +350 -0
- data/ext/ngtcp2/crypto/wolfssl/CMakeLists.txt +84 -0
- data/ext/ngtcp2/crypto/wolfssl/Makefile.am +43 -0
- data/ext/ngtcp2/crypto/wolfssl/libngtcp2_crypto_wolfssl.pc.in +33 -0
- data/ext/ngtcp2/crypto/wolfssl/wolfssl.c +534 -0
- data/ext/ngtcp2/doc/Makefile.am +65 -0
- data/ext/ngtcp2/doc/make.bat +35 -0
- data/ext/ngtcp2/doc/mkapiref.py +356 -0
- data/ext/ngtcp2/doc/source/conf.py.in +94 -0
- data/ext/ngtcp2/doc/source/index.rst +22 -0
- data/ext/ngtcp2/doc/source/programmers-guide.rst +476 -0
- data/ext/ngtcp2/docker/Dockerfile +39 -0
- data/ext/ngtcp2/examples/CMakeLists.txt +361 -0
- data/ext/ngtcp2/examples/Makefile.am +228 -0
- data/ext/ngtcp2/examples/client.cc +3049 -0
- data/ext/ngtcp2/examples/client.h +192 -0
- data/ext/ngtcp2/examples/client_base.cc +202 -0
- data/ext/ngtcp2/examples/client_base.h +213 -0
- data/ext/ngtcp2/examples/debug.cc +298 -0
- data/ext/ngtcp2/examples/debug.h +124 -0
- data/ext/ngtcp2/examples/examplestest.cc +84 -0
- data/ext/ngtcp2/examples/gtlssimpleclient.c +720 -0
- data/ext/ngtcp2/examples/h09client.cc +2601 -0
- data/ext/ngtcp2/examples/h09client.h +196 -0
- data/ext/ngtcp2/examples/h09server.cc +3024 -0
- data/ext/ngtcp2/examples/h09server.h +237 -0
- data/ext/ngtcp2/examples/http.cc +138 -0
- data/ext/ngtcp2/examples/http.h +44 -0
- data/ext/ngtcp2/examples/network.h +80 -0
- data/ext/ngtcp2/examples/server.cc +3731 -0
- data/ext/ngtcp2/examples/server.h +256 -0
- data/ext/ngtcp2/examples/server_base.cc +58 -0
- data/ext/ngtcp2/examples/server_base.h +195 -0
- data/ext/ngtcp2/examples/shared.cc +385 -0
- data/ext/ngtcp2/examples/shared.h +96 -0
- data/ext/ngtcp2/examples/simpleclient.c +683 -0
- data/ext/ngtcp2/examples/template.h +71 -0
- data/ext/ngtcp2/examples/tests/README.rst +60 -0
- data/ext/ngtcp2/examples/tests/__init__.py +0 -0
- data/ext/ngtcp2/examples/tests/config.ini.in +32 -0
- data/ext/ngtcp2/examples/tests/conftest.py +28 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/__init__.py +6 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/certs.py +476 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/client.py +187 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/env.py +191 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/log.py +101 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/server.py +137 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/tls.py +983 -0
- data/ext/ngtcp2/examples/tests/test_01_handshake.py +30 -0
- data/ext/ngtcp2/examples/tests/test_02_resume.py +46 -0
- data/ext/ngtcp2/examples/tests/test_03_earlydata.py +56 -0
- data/ext/ngtcp2/examples/tests/test_04_clientcert.py +57 -0
- data/ext/ngtcp2/examples/tests/test_05_ciphers.py +46 -0
- data/ext/ngtcp2/examples/tls_client_context.h +52 -0
- data/ext/ngtcp2/examples/tls_client_context_boringssl.cc +126 -0
- data/ext/ngtcp2/examples/tls_client_context_boringssl.h +49 -0
- data/ext/ngtcp2/examples/tls_client_context_gnutls.cc +74 -0
- data/ext/ngtcp2/examples/tls_client_context_gnutls.h +50 -0
- data/ext/ngtcp2/examples/tls_client_context_openssl.cc +137 -0
- data/ext/ngtcp2/examples/tls_client_context_openssl.h +49 -0
- data/ext/ngtcp2/examples/tls_client_context_picotls.cc +158 -0
- data/ext/ngtcp2/examples/tls_client_context_picotls.h +53 -0
- data/ext/ngtcp2/examples/tls_client_context_wolfssl.cc +177 -0
- data/ext/ngtcp2/examples/tls_client_context_wolfssl.h +51 -0
- data/ext/ngtcp2/examples/tls_client_session.h +52 -0
- data/ext/ngtcp2/examples/tls_client_session_boringssl.cc +110 -0
- data/ext/ngtcp2/examples/tls_client_session_boringssl.h +52 -0
- data/ext/ngtcp2/examples/tls_client_session_gnutls.cc +190 -0
- data/ext/ngtcp2/examples/tls_client_session_gnutls.h +52 -0
- data/ext/ngtcp2/examples/tls_client_session_openssl.cc +113 -0
- data/ext/ngtcp2/examples/tls_client_session_openssl.h +52 -0
- data/ext/ngtcp2/examples/tls_client_session_picotls.cc +147 -0
- data/ext/ngtcp2/examples/tls_client_session_picotls.h +52 -0
- data/ext/ngtcp2/examples/tls_client_session_wolfssl.cc +160 -0
- data/ext/ngtcp2/examples/tls_client_session_wolfssl.h +52 -0
- data/ext/ngtcp2/examples/tls_server_context.h +52 -0
- data/ext/ngtcp2/examples/tls_server_context_boringssl.cc +257 -0
- data/ext/ngtcp2/examples/tls_server_context_boringssl.h +54 -0
- data/ext/ngtcp2/examples/tls_server_context_gnutls.cc +99 -0
- data/ext/ngtcp2/examples/tls_server_context_gnutls.h +59 -0
- data/ext/ngtcp2/examples/tls_server_context_openssl.cc +338 -0
- data/ext/ngtcp2/examples/tls_server_context_openssl.h +54 -0
- data/ext/ngtcp2/examples/tls_server_context_picotls.cc +321 -0
- data/ext/ngtcp2/examples/tls_server_context_picotls.h +58 -0
- data/ext/ngtcp2/examples/tls_server_context_wolfssl.cc +284 -0
- data/ext/ngtcp2/examples/tls_server_context_wolfssl.h +55 -0
- data/ext/ngtcp2/examples/tls_server_session.h +52 -0
- data/ext/ngtcp2/examples/tls_server_session_boringssl.cc +84 -0
- data/ext/ngtcp2/examples/tls_server_session_boringssl.h +47 -0
- data/ext/ngtcp2/examples/tls_server_session_gnutls.cc +155 -0
- data/ext/ngtcp2/examples/tls_server_session_gnutls.h +46 -0
- data/ext/ngtcp2/examples/tls_server_session_openssl.cc +54 -0
- data/ext/ngtcp2/examples/tls_server_session_openssl.h +47 -0
- data/ext/ngtcp2/examples/tls_server_session_picotls.cc +70 -0
- data/ext/ngtcp2/examples/tls_server_session_picotls.h +47 -0
- data/ext/ngtcp2/examples/tls_server_session_wolfssl.cc +55 -0
- data/ext/ngtcp2/examples/tls_server_session_wolfssl.h +47 -0
- data/ext/ngtcp2/examples/tls_session_base_gnutls.cc +87 -0
- data/ext/ngtcp2/examples/tls_session_base_gnutls.h +51 -0
- data/ext/ngtcp2/examples/tls_session_base_openssl.cc +54 -0
- data/ext/ngtcp2/examples/tls_session_base_openssl.h +52 -0
- data/ext/ngtcp2/examples/tls_session_base_picotls.cc +56 -0
- data/ext/ngtcp2/examples/tls_session_base_picotls.h +54 -0
- data/ext/ngtcp2/examples/tls_session_base_wolfssl.cc +54 -0
- data/ext/ngtcp2/examples/tls_session_base_wolfssl.h +54 -0
- data/ext/ngtcp2/examples/tls_shared_picotls.cc +59 -0
- data/ext/ngtcp2/examples/tls_shared_picotls.h +36 -0
- data/ext/ngtcp2/examples/util.cc +646 -0
- data/ext/ngtcp2/examples/util.h +361 -0
- data/ext/ngtcp2/examples/util_gnutls.cc +136 -0
- data/ext/ngtcp2/examples/util_openssl.cc +131 -0
- data/ext/ngtcp2/examples/util_test.cc +237 -0
- data/ext/ngtcp2/examples/util_test.h +45 -0
- data/ext/ngtcp2/examples/util_wolfssl.cc +130 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/ack +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/ack_ecn +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/connection_close +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/crypto +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/data_blocked +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/datagram +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/datagram_len +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/max_data +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/max_stream_data +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/max_streams +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/new_connection_id +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/new_token +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/path_challenge +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/path_response +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/reset_stream +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/retire_connection_id +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/stop_sending +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/stream +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/stream_data_blocked +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/stream_len +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/streams_blocked +0 -0
- data/ext/ngtcp2/fuzz/corpus/ksl/random +0 -0
- data/ext/ngtcp2/fuzz/decode_frame.cc +25 -0
- data/ext/ngtcp2/fuzz/ksl.cc +77 -0
- data/ext/ngtcp2/interop/Dockerfile +39 -0
- data/ext/ngtcp2/interop/run_endpoint.sh +93 -0
- data/ext/ngtcp2/lib/CMakeLists.txt +110 -0
- data/ext/ngtcp2/lib/Makefile.am +122 -0
- data/ext/ngtcp2/lib/includes/CMakeLists.txt +4 -0
- data/ext/ngtcp2/lib/includes/Makefile.am +25 -0
- data/ext/ngtcp2/lib/includes/ngtcp2/ngtcp2.h +5843 -0
- data/ext/ngtcp2/lib/includes/ngtcp2/version.h.in +51 -0
- data/ext/ngtcp2/lib/libngtcp2.pc.in +33 -0
- data/ext/ngtcp2/lib/ngtcp2_acktr.c +335 -0
- data/ext/ngtcp2/lib/ngtcp2_acktr.h +221 -0
- data/ext/ngtcp2/lib/ngtcp2_addr.c +117 -0
- data/ext/ngtcp2/lib/ngtcp2_addr.h +69 -0
- data/ext/ngtcp2/lib/ngtcp2_balloc.c +90 -0
- data/ext/ngtcp2/lib/ngtcp2_balloc.h +91 -0
- data/ext/ngtcp2/lib/ngtcp2_bbr.c +693 -0
- data/ext/ngtcp2/lib/ngtcp2_bbr.h +157 -0
- data/ext/ngtcp2/lib/ngtcp2_bbr2.c +1490 -0
- data/ext/ngtcp2/lib/ngtcp2_bbr2.h +149 -0
- data/ext/ngtcp2/lib/ngtcp2_buf.c +56 -0
- data/ext/ngtcp2/lib/ngtcp2_buf.h +108 -0
- data/ext/ngtcp2/lib/ngtcp2_cc.c +616 -0
- data/ext/ngtcp2/lib/ngtcp2_cc.h +422 -0
- data/ext/ngtcp2/lib/ngtcp2_cid.c +147 -0
- data/ext/ngtcp2/lib/ngtcp2_cid.h +175 -0
- data/ext/ngtcp2/lib/ngtcp2_conn.c +13731 -0
- data/ext/ngtcp2/lib/ngtcp2_conn.h +1119 -0
- data/ext/ngtcp2/lib/ngtcp2_conn_stat.h +131 -0
- data/ext/ngtcp2/lib/ngtcp2_conv.c +291 -0
- data/ext/ngtcp2/lib/ngtcp2_conv.h +208 -0
- data/ext/ngtcp2/lib/ngtcp2_crypto.c +895 -0
- data/ext/ngtcp2/lib/ngtcp2_crypto.h +148 -0
- data/ext/ngtcp2/lib/ngtcp2_err.c +154 -0
- data/ext/ngtcp2/lib/ngtcp2_err.h +34 -0
- data/ext/ngtcp2/lib/ngtcp2_gaptr.c +167 -0
- data/ext/ngtcp2/lib/ngtcp2_gaptr.h +98 -0
- data/ext/ngtcp2/lib/ngtcp2_idtr.c +79 -0
- data/ext/ngtcp2/lib/ngtcp2_idtr.h +89 -0
- data/ext/ngtcp2/lib/ngtcp2_ksl.c +819 -0
- data/ext/ngtcp2/lib/ngtcp2_ksl.h +345 -0
- data/ext/ngtcp2/lib/ngtcp2_log.c +822 -0
- data/ext/ngtcp2/lib/ngtcp2_log.h +123 -0
- data/ext/ngtcp2/lib/ngtcp2_macro.h +58 -0
- data/ext/ngtcp2/lib/ngtcp2_map.c +336 -0
- data/ext/ngtcp2/lib/ngtcp2_map.h +136 -0
- data/ext/ngtcp2/lib/ngtcp2_mem.c +113 -0
- data/ext/ngtcp2/lib/ngtcp2_mem.h +72 -0
- data/ext/ngtcp2/lib/ngtcp2_net.h +136 -0
- data/ext/ngtcp2/lib/ngtcp2_objalloc.c +40 -0
- data/ext/ngtcp2/lib/ngtcp2_objalloc.h +140 -0
- data/ext/ngtcp2/lib/ngtcp2_opl.c +46 -0
- data/ext/ngtcp2/lib/ngtcp2_opl.h +65 -0
- data/ext/ngtcp2/lib/ngtcp2_path.c +77 -0
- data/ext/ngtcp2/lib/ngtcp2_path.h +49 -0
- data/ext/ngtcp2/lib/ngtcp2_pkt.c +2527 -0
- data/ext/ngtcp2/lib/ngtcp2_pkt.h +1235 -0
- data/ext/ngtcp2/lib/ngtcp2_pmtud.c +160 -0
- data/ext/ngtcp2/lib/ngtcp2_pmtud.h +123 -0
- data/ext/ngtcp2/lib/ngtcp2_ppe.c +230 -0
- data/ext/ngtcp2/lib/ngtcp2_ppe.h +153 -0
- data/ext/ngtcp2/lib/ngtcp2_pq.c +164 -0
- data/ext/ngtcp2/lib/ngtcp2_pq.h +126 -0
- data/ext/ngtcp2/lib/ngtcp2_pv.c +172 -0
- data/ext/ngtcp2/lib/ngtcp2_pv.h +194 -0
- data/ext/ngtcp2/lib/ngtcp2_qlog.c +1219 -0
- data/ext/ngtcp2/lib/ngtcp2_qlog.h +161 -0
- data/ext/ngtcp2/lib/ngtcp2_range.c +61 -0
- data/ext/ngtcp2/lib/ngtcp2_range.h +80 -0
- data/ext/ngtcp2/lib/ngtcp2_rcvry.h +40 -0
- data/ext/ngtcp2/lib/ngtcp2_ringbuf.c +121 -0
- data/ext/ngtcp2/lib/ngtcp2_ringbuf.h +132 -0
- data/ext/ngtcp2/lib/ngtcp2_rob.c +319 -0
- data/ext/ngtcp2/lib/ngtcp2_rob.h +197 -0
- data/ext/ngtcp2/lib/ngtcp2_rst.c +138 -0
- data/ext/ngtcp2/lib/ngtcp2_rst.h +86 -0
- data/ext/ngtcp2/lib/ngtcp2_rtb.c +1676 -0
- data/ext/ngtcp2/lib/ngtcp2_rtb.h +468 -0
- data/ext/ngtcp2/lib/ngtcp2_str.c +233 -0
- data/ext/ngtcp2/lib/ngtcp2_str.h +94 -0
- data/ext/ngtcp2/lib/ngtcp2_strm.c +698 -0
- data/ext/ngtcp2/lib/ngtcp2_strm.h +310 -0
- data/ext/ngtcp2/lib/ngtcp2_unreachable.c +71 -0
- data/ext/ngtcp2/lib/ngtcp2_unreachable.h +46 -0
- data/ext/ngtcp2/lib/ngtcp2_vec.c +243 -0
- data/ext/ngtcp2/lib/ngtcp2_vec.h +120 -0
- data/ext/ngtcp2/lib/ngtcp2_version.c +39 -0
- data/ext/ngtcp2/lib/ngtcp2_window_filter.c +99 -0
- data/ext/ngtcp2/lib/ngtcp2_window_filter.h +65 -0
- data/ext/ngtcp2/m4/ax_check_compile_flag.m4 +74 -0
- data/ext/ngtcp2/m4/ax_cxx_compile_stdcxx.m4 +1009 -0
- data/ext/ngtcp2/tests/CMakeLists.txt +68 -0
- data/ext/ngtcp2/tests/Makefile.am +94 -0
- data/ext/ngtcp2/tests/main.c +358 -0
- data/ext/ngtcp2/tests/ngtcp2_acktr_test.c +367 -0
- data/ext/ngtcp2/tests/ngtcp2_acktr_test.h +37 -0
- data/ext/ngtcp2/tests/ngtcp2_conn_test.c +9821 -0
- data/ext/ngtcp2/tests/ngtcp2_conn_test.h +104 -0
- data/ext/ngtcp2/tests/ngtcp2_conv_test.c +430 -0
- data/ext/ngtcp2/tests/ngtcp2_conv_test.h +46 -0
- data/ext/ngtcp2/tests/ngtcp2_crypto_test.c +667 -0
- data/ext/ngtcp2/tests/ngtcp2_crypto_test.h +35 -0
- data/ext/ngtcp2/tests/ngtcp2_gaptr_test.c +127 -0
- data/ext/ngtcp2/tests/ngtcp2_gaptr_test.h +36 -0
- data/ext/ngtcp2/tests/ngtcp2_idtr_test.c +79 -0
- data/ext/ngtcp2/tests/ngtcp2_idtr_test.h +34 -0
- data/ext/ngtcp2/tests/ngtcp2_ksl_test.c +502 -0
- data/ext/ngtcp2/tests/ngtcp2_ksl_test.h +39 -0
- data/ext/ngtcp2/tests/ngtcp2_map_test.c +206 -0
- data/ext/ngtcp2/tests/ngtcp2_map_test.h +38 -0
- data/ext/ngtcp2/tests/ngtcp2_pkt_test.c +1645 -0
- data/ext/ngtcp2/tests/ngtcp2_pkt_test.h +68 -0
- data/ext/ngtcp2/tests/ngtcp2_pmtud_test.c +153 -0
- data/ext/ngtcp2/tests/ngtcp2_pmtud_test.h +34 -0
- data/ext/ngtcp2/tests/ngtcp2_pv_test.c +129 -0
- data/ext/ngtcp2/tests/ngtcp2_pv_test.h +35 -0
- data/ext/ngtcp2/tests/ngtcp2_range_test.c +105 -0
- data/ext/ngtcp2/tests/ngtcp2_range_test.h +36 -0
- data/ext/ngtcp2/tests/ngtcp2_ringbuf_test.c +91 -0
- data/ext/ngtcp2/tests/ngtcp2_ringbuf_test.h +35 -0
- data/ext/ngtcp2/tests/ngtcp2_rob_test.c +552 -0
- data/ext/ngtcp2/tests/ngtcp2_rob_test.h +37 -0
- data/ext/ngtcp2/tests/ngtcp2_rtb_test.c +470 -0
- data/ext/ngtcp2/tests/ngtcp2_rtb_test.h +38 -0
- data/ext/ngtcp2/tests/ngtcp2_str_test.c +96 -0
- data/ext/ngtcp2/tests/ngtcp2_str_test.h +36 -0
- data/ext/ngtcp2/tests/ngtcp2_strm_test.c +575 -0
- data/ext/ngtcp2/tests/ngtcp2_strm_test.h +36 -0
- data/ext/ngtcp2/tests/ngtcp2_test_helper.c +404 -0
- data/ext/ngtcp2/tests/ngtcp2_test_helper.h +191 -0
- data/ext/ngtcp2/tests/ngtcp2_vec_test.c +426 -0
- data/ext/ngtcp2/tests/ngtcp2_vec_test.h +36 -0
- data/ext/ngtcp2/third-party/CMakeLists.txt +34 -0
- data/ext/ngtcp2/third-party/Makefile.am +31 -0
- data/ext/ngtcp2/third-party/http-parser/AUTHORS +68 -0
- data/ext/ngtcp2/third-party/http-parser/LICENSE-MIT +23 -0
- data/ext/ngtcp2/third-party/http-parser/Makefile +157 -0
- data/ext/ngtcp2/third-party/http-parser/README.md +246 -0
- data/ext/ngtcp2/third-party/http-parser/bench.c +111 -0
- data/ext/ngtcp2/third-party/http-parser/contrib/parsertrace.c +160 -0
- data/ext/ngtcp2/third-party/http-parser/contrib/url_parser.c +47 -0
- data/ext/ngtcp2/third-party/http-parser/http_parser.c +2419 -0
- data/ext/ngtcp2/third-party/http-parser/http_parser.gyp +111 -0
- data/ext/ngtcp2/third-party/http-parser/http_parser.h +431 -0
- data/ext/ngtcp2/third-party/http-parser/test.c +4411 -0
- data/lib/protocol/quic/version.rb +10 -0
- data/lib/protocol/quic.rb +9 -0
- data/license.md +21 -0
- data.tar.gz.sig +1 -0
- metadata +424 -0
- metadata.gz.sig +1 -0
@@ -0,0 +1,157 @@
|
|
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
|
+
PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
|
22
|
+
HELPER ?=
|
23
|
+
BINEXT ?=
|
24
|
+
SOLIBNAME = libhttp_parser
|
25
|
+
SOMAJOR = 2
|
26
|
+
SOMINOR = 7
|
27
|
+
SOREV = 1
|
28
|
+
ifeq (darwin,$(PLATFORM))
|
29
|
+
SOEXT ?= dylib
|
30
|
+
SONAME ?= $(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOEXT)
|
31
|
+
LIBNAME ?= $(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOREV).$(SOEXT)
|
32
|
+
else ifeq (wine,$(PLATFORM))
|
33
|
+
CC = winegcc
|
34
|
+
BINEXT = .exe.so
|
35
|
+
HELPER = wine
|
36
|
+
else
|
37
|
+
SOEXT ?= so
|
38
|
+
SONAME ?= $(SOLIBNAME).$(SOEXT).$(SOMAJOR).$(SOMINOR)
|
39
|
+
LIBNAME ?= $(SOLIBNAME).$(SOEXT).$(SOMAJOR).$(SOMINOR).$(SOREV)
|
40
|
+
endif
|
41
|
+
|
42
|
+
CC?=gcc
|
43
|
+
AR?=ar
|
44
|
+
|
45
|
+
CPPFLAGS ?=
|
46
|
+
LDFLAGS ?=
|
47
|
+
|
48
|
+
CPPFLAGS += -I.
|
49
|
+
CPPFLAGS_DEBUG = $(CPPFLAGS) -DHTTP_PARSER_STRICT=1
|
50
|
+
CPPFLAGS_DEBUG += $(CPPFLAGS_DEBUG_EXTRA)
|
51
|
+
CPPFLAGS_FAST = $(CPPFLAGS) -DHTTP_PARSER_STRICT=0
|
52
|
+
CPPFLAGS_FAST += $(CPPFLAGS_FAST_EXTRA)
|
53
|
+
CPPFLAGS_BENCH = $(CPPFLAGS_FAST)
|
54
|
+
|
55
|
+
CFLAGS += -Wall -Wextra -Werror
|
56
|
+
CFLAGS_DEBUG = $(CFLAGS) -O0 -g $(CFLAGS_DEBUG_EXTRA)
|
57
|
+
CFLAGS_FAST = $(CFLAGS) -O3 $(CFLAGS_FAST_EXTRA)
|
58
|
+
CFLAGS_BENCH = $(CFLAGS_FAST) -Wno-unused-parameter
|
59
|
+
CFLAGS_LIB = $(CFLAGS_FAST) -fPIC
|
60
|
+
|
61
|
+
LDFLAGS_LIB = $(LDFLAGS) -shared
|
62
|
+
|
63
|
+
INSTALL ?= install
|
64
|
+
PREFIX ?= $(DESTDIR)/usr/local
|
65
|
+
LIBDIR = $(PREFIX)/lib
|
66
|
+
INCLUDEDIR = $(PREFIX)/include
|
67
|
+
|
68
|
+
ifneq (darwin,$(PLATFORM))
|
69
|
+
# TODO(bnoordhuis) The native SunOS linker expects -h rather than -soname...
|
70
|
+
LDFLAGS_LIB += -Wl,-soname=$(SONAME)
|
71
|
+
endif
|
72
|
+
|
73
|
+
test: test_g test_fast
|
74
|
+
$(HELPER) ./test_g$(BINEXT)
|
75
|
+
$(HELPER) ./test_fast$(BINEXT)
|
76
|
+
|
77
|
+
test_g: http_parser_g.o test_g.o
|
78
|
+
$(CC) $(CFLAGS_DEBUG) $(LDFLAGS) http_parser_g.o test_g.o -o $@
|
79
|
+
|
80
|
+
test_g.o: test.c http_parser.h Makefile
|
81
|
+
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c test.c -o $@
|
82
|
+
|
83
|
+
http_parser_g.o: http_parser.c http_parser.h Makefile
|
84
|
+
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c http_parser.c -o $@
|
85
|
+
|
86
|
+
test_fast: http_parser.o test.o http_parser.h
|
87
|
+
$(CC) $(CFLAGS_FAST) $(LDFLAGS) http_parser.o test.o -o $@
|
88
|
+
|
89
|
+
test.o: test.c http_parser.h Makefile
|
90
|
+
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c test.c -o $@
|
91
|
+
|
92
|
+
bench: http_parser.o bench.o
|
93
|
+
$(CC) $(CFLAGS_BENCH) $(LDFLAGS) http_parser.o bench.o -o $@
|
94
|
+
|
95
|
+
bench.o: bench.c http_parser.h Makefile
|
96
|
+
$(CC) $(CPPFLAGS_BENCH) $(CFLAGS_BENCH) -c bench.c -o $@
|
97
|
+
|
98
|
+
http_parser.o: http_parser.c http_parser.h Makefile
|
99
|
+
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c http_parser.c
|
100
|
+
|
101
|
+
test-run-timed: test_fast
|
102
|
+
while(true) do time $(HELPER) ./test_fast$(BINEXT) > /dev/null; done
|
103
|
+
|
104
|
+
test-valgrind: test_g
|
105
|
+
valgrind ./test_g
|
106
|
+
|
107
|
+
libhttp_parser.o: http_parser.c http_parser.h Makefile
|
108
|
+
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_LIB) -c http_parser.c -o libhttp_parser.o
|
109
|
+
|
110
|
+
library: libhttp_parser.o
|
111
|
+
$(CC) $(LDFLAGS_LIB) -o $(LIBNAME) $<
|
112
|
+
|
113
|
+
package: http_parser.o
|
114
|
+
$(AR) rcs libhttp_parser.a http_parser.o
|
115
|
+
|
116
|
+
url_parser: http_parser.o contrib/url_parser.c
|
117
|
+
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o $@
|
118
|
+
|
119
|
+
url_parser_g: http_parser_g.o contrib/url_parser.c
|
120
|
+
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o $@
|
121
|
+
|
122
|
+
parsertrace: http_parser.o contrib/parsertrace.c
|
123
|
+
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o parsertrace$(BINEXT)
|
124
|
+
|
125
|
+
parsertrace_g: http_parser_g.o contrib/parsertrace.c
|
126
|
+
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o parsertrace_g$(BINEXT)
|
127
|
+
|
128
|
+
tags: http_parser.c http_parser.h test.c
|
129
|
+
ctags $^
|
130
|
+
|
131
|
+
install: library
|
132
|
+
$(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h
|
133
|
+
$(INSTALL) -D $(LIBNAME) $(LIBDIR)/$(LIBNAME)
|
134
|
+
ln -s $(LIBDIR)/$(LIBNAME) $(LIBDIR)/$(SONAME)
|
135
|
+
ln -s $(LIBDIR)/$(LIBNAME) $(LIBDIR)/$(SOLIBNAME).$(SOEXT)
|
136
|
+
|
137
|
+
install-strip: library
|
138
|
+
$(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h
|
139
|
+
$(INSTALL) -D -s $(LIBNAME) $(LIBDIR)/$(LIBNAME)
|
140
|
+
ln -s $(LIBDIR)/$(LIBNAME) $(LIBDIR)/$(SONAME)
|
141
|
+
ln -s $(LIBDIR)/$(LIBNAME) $(LIBDIR)/$(SOLIBNAME).$(SOEXT)
|
142
|
+
|
143
|
+
uninstall:
|
144
|
+
rm $(INCLUDEDIR)/http_parser.h
|
145
|
+
rm $(LIBDIR)/$(SONAME)
|
146
|
+
rm $(LIBDIR)/libhttp_parser.so
|
147
|
+
|
148
|
+
clean:
|
149
|
+
rm -f *.o *.a tags test test_fast test_g \
|
150
|
+
http_parser.tar libhttp_parser.so.* \
|
151
|
+
url_parser url_parser_g parsertrace parsertrace_g \
|
152
|
+
*.exe *.exe.so
|
153
|
+
|
154
|
+
contrib/url_parser.c: http_parser.h
|
155
|
+
contrib/parsertrace.c: http_parser.h
|
156
|
+
|
157
|
+
.PHONY: clean package test-run test-run-timed test-valgrind install install-strip uninstall
|
@@ -0,0 +1,246 @@
|
|
1
|
+
HTTP Parser
|
2
|
+
===========
|
3
|
+
|
4
|
+
[![Build Status](https://api.travis-ci.org/nodejs/http-parser.svg?branch=master)](https://travis-ci.org/nodejs/http-parser)
|
5
|
+
|
6
|
+
This is a parser for HTTP messages written in C. It parses both requests and
|
7
|
+
responses. The parser is designed to be used in performance HTTP
|
8
|
+
applications. It does not make any syscalls nor allocations, it does not
|
9
|
+
buffer data, it can be interrupted at anytime. Depending on your
|
10
|
+
architecture, it only requires about 40 bytes of data per message
|
11
|
+
stream (in a web server that is per connection).
|
12
|
+
|
13
|
+
Features:
|
14
|
+
|
15
|
+
* No dependencies
|
16
|
+
* Handles persistent streams (keep-alive).
|
17
|
+
* Decodes chunked encoding.
|
18
|
+
* Upgrade support
|
19
|
+
* Defends against buffer overflow attacks.
|
20
|
+
|
21
|
+
The parser extracts the following information from HTTP messages:
|
22
|
+
|
23
|
+
* Header fields and values
|
24
|
+
* Content-Length
|
25
|
+
* Request method
|
26
|
+
* Response status code
|
27
|
+
* Transfer-Encoding
|
28
|
+
* HTTP version
|
29
|
+
* Request URL
|
30
|
+
* Message body
|
31
|
+
|
32
|
+
|
33
|
+
Usage
|
34
|
+
-----
|
35
|
+
|
36
|
+
One `http_parser` object is used per TCP connection. Initialize the struct
|
37
|
+
using `http_parser_init()` and set the callbacks. That might look something
|
38
|
+
like this for a request parser:
|
39
|
+
```c
|
40
|
+
http_parser_settings settings;
|
41
|
+
settings.on_url = my_url_callback;
|
42
|
+
settings.on_header_field = my_header_field_callback;
|
43
|
+
/* ... */
|
44
|
+
|
45
|
+
http_parser *parser = malloc(sizeof(http_parser));
|
46
|
+
http_parser_init(parser, HTTP_REQUEST);
|
47
|
+
parser->data = my_socket;
|
48
|
+
```
|
49
|
+
|
50
|
+
When data is received on the socket execute the parser and check for errors.
|
51
|
+
|
52
|
+
```c
|
53
|
+
size_t len = 80*1024, nparsed;
|
54
|
+
char buf[len];
|
55
|
+
ssize_t recved;
|
56
|
+
|
57
|
+
recved = recv(fd, buf, len, 0);
|
58
|
+
|
59
|
+
if (recved < 0) {
|
60
|
+
/* Handle error. */
|
61
|
+
}
|
62
|
+
|
63
|
+
/* Start up / continue the parser.
|
64
|
+
* Note we pass recved==0 to signal that EOF has been received.
|
65
|
+
*/
|
66
|
+
nparsed = http_parser_execute(parser, &settings, buf, recved);
|
67
|
+
|
68
|
+
if (parser->upgrade) {
|
69
|
+
/* handle new protocol */
|
70
|
+
} else if (nparsed != recved) {
|
71
|
+
/* Handle error. Usually just close the connection. */
|
72
|
+
}
|
73
|
+
```
|
74
|
+
|
75
|
+
HTTP needs to know where the end of the stream is. For example, sometimes
|
76
|
+
servers send responses without Content-Length and expect the client to
|
77
|
+
consume input (for the body) until EOF. To tell http_parser about EOF, give
|
78
|
+
`0` as the fourth parameter to `http_parser_execute()`. Callbacks and errors
|
79
|
+
can still be encountered during an EOF, so one must still be prepared
|
80
|
+
to receive them.
|
81
|
+
|
82
|
+
Scalar valued message information such as `status_code`, `method`, and the
|
83
|
+
HTTP version are stored in the parser structure. This data is only
|
84
|
+
temporally stored in `http_parser` and gets reset on each new message. If
|
85
|
+
this information is needed later, copy it out of the structure during the
|
86
|
+
`headers_complete` callback.
|
87
|
+
|
88
|
+
The parser decodes the transfer-encoding for both requests and responses
|
89
|
+
transparently. That is, a chunked encoding is decoded before being sent to
|
90
|
+
the on_body callback.
|
91
|
+
|
92
|
+
|
93
|
+
The Special Problem of Upgrade
|
94
|
+
------------------------------
|
95
|
+
|
96
|
+
HTTP supports upgrading the connection to a different protocol. An
|
97
|
+
increasingly common example of this is the WebSocket protocol which sends
|
98
|
+
a request like
|
99
|
+
|
100
|
+
GET /demo HTTP/1.1
|
101
|
+
Upgrade: WebSocket
|
102
|
+
Connection: Upgrade
|
103
|
+
Host: example.com
|
104
|
+
Origin: http://example.com
|
105
|
+
WebSocket-Protocol: sample
|
106
|
+
|
107
|
+
followed by non-HTTP data.
|
108
|
+
|
109
|
+
(See [RFC6455](https://tools.ietf.org/html/rfc6455) for more information the
|
110
|
+
WebSocket protocol.)
|
111
|
+
|
112
|
+
To support this, the parser will treat this as a normal HTTP message without a
|
113
|
+
body, issuing both on_headers_complete and on_message_complete callbacks. However
|
114
|
+
http_parser_execute() will stop parsing at the end of the headers and return.
|
115
|
+
|
116
|
+
The user is expected to check if `parser->upgrade` has been set to 1 after
|
117
|
+
`http_parser_execute()` returns. Non-HTTP data begins at the buffer supplied
|
118
|
+
offset by the return value of `http_parser_execute()`.
|
119
|
+
|
120
|
+
|
121
|
+
Callbacks
|
122
|
+
---------
|
123
|
+
|
124
|
+
During the `http_parser_execute()` call, the callbacks set in
|
125
|
+
`http_parser_settings` will be executed. The parser maintains state and
|
126
|
+
never looks behind, so buffering the data is not necessary. If you need to
|
127
|
+
save certain data for later usage, you can do that from the callbacks.
|
128
|
+
|
129
|
+
There are two types of callbacks:
|
130
|
+
|
131
|
+
* notification `typedef int (*http_cb) (http_parser*);`
|
132
|
+
Callbacks: on_message_begin, on_headers_complete, on_message_complete.
|
133
|
+
* data `typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);`
|
134
|
+
Callbacks: (requests only) on_url,
|
135
|
+
(common) on_header_field, on_header_value, on_body;
|
136
|
+
|
137
|
+
Callbacks must return 0 on success. Returning a non-zero value indicates
|
138
|
+
error to the parser, making it exit immediately.
|
139
|
+
|
140
|
+
For cases where it is necessary to pass local information to/from a callback,
|
141
|
+
the `http_parser` object's `data` field can be used.
|
142
|
+
An example of such a case is when using threads to handle a socket connection,
|
143
|
+
parse a request, and then give a response over that socket. By instantiation
|
144
|
+
of a thread-local struct containing relevant data (e.g. accepted socket,
|
145
|
+
allocated memory for callbacks to write into, etc), a parser's callbacks are
|
146
|
+
able to communicate data between the scope of the thread and the scope of the
|
147
|
+
callback in a threadsafe manner. This allows http-parser to be used in
|
148
|
+
multi-threaded contexts.
|
149
|
+
|
150
|
+
Example:
|
151
|
+
```c
|
152
|
+
typedef struct {
|
153
|
+
socket_t sock;
|
154
|
+
void* buffer;
|
155
|
+
int buf_len;
|
156
|
+
} custom_data_t;
|
157
|
+
|
158
|
+
|
159
|
+
int my_url_callback(http_parser* parser, const char *at, size_t length) {
|
160
|
+
/* access to thread local custom_data_t struct.
|
161
|
+
Use this access save parsed data for later use into thread local
|
162
|
+
buffer, or communicate over socket
|
163
|
+
*/
|
164
|
+
parser->data;
|
165
|
+
...
|
166
|
+
return 0;
|
167
|
+
}
|
168
|
+
|
169
|
+
...
|
170
|
+
|
171
|
+
void http_parser_thread(socket_t sock) {
|
172
|
+
int nparsed = 0;
|
173
|
+
/* allocate memory for user data */
|
174
|
+
custom_data_t *my_data = malloc(sizeof(custom_data_t));
|
175
|
+
|
176
|
+
/* some information for use by callbacks.
|
177
|
+
* achieves thread -> callback information flow */
|
178
|
+
my_data->sock = sock;
|
179
|
+
|
180
|
+
/* instantiate a thread-local parser */
|
181
|
+
http_parser *parser = malloc(sizeof(http_parser));
|
182
|
+
http_parser_init(parser, HTTP_REQUEST); /* initialise parser */
|
183
|
+
/* this custom data reference is accessible through the reference to the
|
184
|
+
parser supplied to callback functions */
|
185
|
+
parser->data = my_data;
|
186
|
+
|
187
|
+
http_parser_settings settings; /* set up callbacks */
|
188
|
+
settings.on_url = my_url_callback;
|
189
|
+
|
190
|
+
/* execute parser */
|
191
|
+
nparsed = http_parser_execute(parser, &settings, buf, recved);
|
192
|
+
|
193
|
+
...
|
194
|
+
/* parsed information copied from callback.
|
195
|
+
can now perform action on data copied into thread-local memory from callbacks.
|
196
|
+
achieves callback -> thread information flow */
|
197
|
+
my_data->buffer;
|
198
|
+
...
|
199
|
+
}
|
200
|
+
|
201
|
+
```
|
202
|
+
|
203
|
+
In case you parse HTTP message in chunks (i.e. `read()` request line
|
204
|
+
from socket, parse, read half headers, parse, etc) your data callbacks
|
205
|
+
may be called more than once. Http-parser guarantees that data pointer is only
|
206
|
+
valid for the lifetime of callback. You can also `read()` into a heap allocated
|
207
|
+
buffer to avoid copying memory around if this fits your application.
|
208
|
+
|
209
|
+
Reading headers may be a tricky task if you read/parse headers partially.
|
210
|
+
Basically, you need to remember whether last header callback was field or value
|
211
|
+
and apply the following logic:
|
212
|
+
|
213
|
+
(on_header_field and on_header_value shortened to on_h_*)
|
214
|
+
------------------------ ------------ --------------------------------------------
|
215
|
+
| State (prev. callback) | Callback | Description/action |
|
216
|
+
------------------------ ------------ --------------------------------------------
|
217
|
+
| nothing (first call) | on_h_field | Allocate new buffer and copy callback data |
|
218
|
+
| | | into it |
|
219
|
+
------------------------ ------------ --------------------------------------------
|
220
|
+
| value | on_h_field | New header started. |
|
221
|
+
| | | Copy current name,value buffers to headers |
|
222
|
+
| | | list and allocate new buffer for new name |
|
223
|
+
------------------------ ------------ --------------------------------------------
|
224
|
+
| field | on_h_field | Previous name continues. Reallocate name |
|
225
|
+
| | | buffer and append callback data to it |
|
226
|
+
------------------------ ------------ --------------------------------------------
|
227
|
+
| field | on_h_value | Value for current header started. Allocate |
|
228
|
+
| | | new buffer and copy callback data to it |
|
229
|
+
------------------------ ------------ --------------------------------------------
|
230
|
+
| value | on_h_value | Value continues. Reallocate value buffer |
|
231
|
+
| | | and append callback data to it |
|
232
|
+
------------------------ ------------ --------------------------------------------
|
233
|
+
|
234
|
+
|
235
|
+
Parsing URLs
|
236
|
+
------------
|
237
|
+
|
238
|
+
A simplistic zero-copy URL parser is provided as `http_parser_parse_url()`.
|
239
|
+
Users of this library may wish to use it to parse URLs constructed from
|
240
|
+
consecutive `on_url` callbacks.
|
241
|
+
|
242
|
+
See examples of reading in headers:
|
243
|
+
|
244
|
+
* [partial example](http://gist.github.com/155877) in C
|
245
|
+
* [from http-parser tests](http://github.com/joyent/http-parser/blob/37a0ff8/test.c#L403) in C
|
246
|
+
* [from Node library](http://github.com/joyent/node/blob/842eaf4/src/http.js#L284) in Javascript
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/* Copyright Fedor Indutny. 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 <assert.h>
|
23
|
+
#include <stdio.h>
|
24
|
+
#include <string.h>
|
25
|
+
#include <sys/time.h>
|
26
|
+
|
27
|
+
static const char data[] =
|
28
|
+
"POST /joyent/http-parser HTTP/1.1\r\n"
|
29
|
+
"Host: github.com\r\n"
|
30
|
+
"DNT: 1\r\n"
|
31
|
+
"Accept-Encoding: gzip, deflate, sdch\r\n"
|
32
|
+
"Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4\r\n"
|
33
|
+
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) "
|
34
|
+
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
35
|
+
"Chrome/39.0.2171.65 Safari/537.36\r\n"
|
36
|
+
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,"
|
37
|
+
"image/webp,*/*;q=0.8\r\n"
|
38
|
+
"Referer: https://github.com/joyent/http-parser\r\n"
|
39
|
+
"Connection: keep-alive\r\n"
|
40
|
+
"Transfer-Encoding: chunked\r\n"
|
41
|
+
"Cache-Control: max-age=0\r\n\r\nb\r\nhello world\r\n0\r\n\r\n";
|
42
|
+
static const size_t data_len = sizeof(data) - 1;
|
43
|
+
|
44
|
+
static int on_info(http_parser* p) {
|
45
|
+
return 0;
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
static int on_data(http_parser* p, const char *at, size_t length) {
|
50
|
+
return 0;
|
51
|
+
}
|
52
|
+
|
53
|
+
static http_parser_settings settings = {
|
54
|
+
.on_message_begin = on_info,
|
55
|
+
.on_headers_complete = on_info,
|
56
|
+
.on_message_complete = on_info,
|
57
|
+
.on_header_field = on_data,
|
58
|
+
.on_header_value = on_data,
|
59
|
+
.on_url = on_data,
|
60
|
+
.on_status = on_data,
|
61
|
+
.on_body = on_data
|
62
|
+
};
|
63
|
+
|
64
|
+
int bench(int iter_count, int silent) {
|
65
|
+
struct http_parser parser;
|
66
|
+
int i;
|
67
|
+
int err;
|
68
|
+
struct timeval start;
|
69
|
+
struct timeval end;
|
70
|
+
float rps;
|
71
|
+
|
72
|
+
if (!silent) {
|
73
|
+
err = gettimeofday(&start, NULL);
|
74
|
+
assert(err == 0);
|
75
|
+
}
|
76
|
+
|
77
|
+
for (i = 0; i < iter_count; i++) {
|
78
|
+
size_t parsed;
|
79
|
+
http_parser_init(&parser, HTTP_REQUEST);
|
80
|
+
|
81
|
+
parsed = http_parser_execute(&parser, &settings, data, data_len);
|
82
|
+
assert(parsed == data_len);
|
83
|
+
}
|
84
|
+
|
85
|
+
if (!silent) {
|
86
|
+
err = gettimeofday(&end, NULL);
|
87
|
+
assert(err == 0);
|
88
|
+
|
89
|
+
fprintf(stdout, "Benchmark result:\n");
|
90
|
+
|
91
|
+
rps = (float) (end.tv_sec - start.tv_sec) +
|
92
|
+
(end.tv_usec - start.tv_usec) * 1e-6f;
|
93
|
+
fprintf(stdout, "Took %f seconds to run\n", rps);
|
94
|
+
|
95
|
+
rps = (float) iter_count / rps;
|
96
|
+
fprintf(stdout, "%f req/sec\n", rps);
|
97
|
+
fflush(stdout);
|
98
|
+
}
|
99
|
+
|
100
|
+
return 0;
|
101
|
+
}
|
102
|
+
|
103
|
+
int main(int argc, char** argv) {
|
104
|
+
if (argc == 2 && strcmp(argv[1], "infinite") == 0) {
|
105
|
+
for (;;)
|
106
|
+
bench(5000000, 1);
|
107
|
+
return 0;
|
108
|
+
} else {
|
109
|
+
return bench(5000000, 0);
|
110
|
+
}
|
111
|
+
}
|
@@ -0,0 +1,160 @@
|
|
1
|
+
/* Based on src/http/ngx_http_parse.c from NGINX copyright Igor Sysoev
|
2
|
+
*
|
3
|
+
* Additional changes are licensed under the same terms as NGINX and
|
4
|
+
* copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
* of this software and associated documentation files (the "Software"), to
|
8
|
+
* deal in the Software without restriction, including without limitation the
|
9
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
11
|
+
* furnished to do so, subject to the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
14
|
+
* all copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
22
|
+
* IN THE SOFTWARE.
|
23
|
+
*/
|
24
|
+
|
25
|
+
/* Dump what the parser finds to stdout as it happen */
|
26
|
+
|
27
|
+
#include "http_parser.h"
|
28
|
+
#include <stdio.h>
|
29
|
+
#include <stdlib.h>
|
30
|
+
#include <string.h>
|
31
|
+
|
32
|
+
int on_message_begin(http_parser* _) {
|
33
|
+
(void)_;
|
34
|
+
printf("\n***MESSAGE BEGIN***\n\n");
|
35
|
+
return 0;
|
36
|
+
}
|
37
|
+
|
38
|
+
int on_headers_complete(http_parser* _) {
|
39
|
+
(void)_;
|
40
|
+
printf("\n***HEADERS COMPLETE***\n\n");
|
41
|
+
return 0;
|
42
|
+
}
|
43
|
+
|
44
|
+
int on_message_complete(http_parser* _) {
|
45
|
+
(void)_;
|
46
|
+
printf("\n***MESSAGE COMPLETE***\n\n");
|
47
|
+
return 0;
|
48
|
+
}
|
49
|
+
|
50
|
+
int on_url(http_parser* _, const char* at, size_t length) {
|
51
|
+
(void)_;
|
52
|
+
printf("Url: %.*s\n", (int)length, at);
|
53
|
+
return 0;
|
54
|
+
}
|
55
|
+
|
56
|
+
int on_header_field(http_parser* _, const char* at, size_t length) {
|
57
|
+
(void)_;
|
58
|
+
printf("Header field: %.*s\n", (int)length, at);
|
59
|
+
return 0;
|
60
|
+
}
|
61
|
+
|
62
|
+
int on_header_value(http_parser* _, const char* at, size_t length) {
|
63
|
+
(void)_;
|
64
|
+
printf("Header value: %.*s\n", (int)length, at);
|
65
|
+
return 0;
|
66
|
+
}
|
67
|
+
|
68
|
+
int on_body(http_parser* _, const char* at, size_t length) {
|
69
|
+
(void)_;
|
70
|
+
printf("Body: %.*s\n", (int)length, at);
|
71
|
+
return 0;
|
72
|
+
}
|
73
|
+
|
74
|
+
void usage(const char* name) {
|
75
|
+
fprintf(stderr,
|
76
|
+
"Usage: %s $type $filename\n"
|
77
|
+
" type: -x, where x is one of {r,b,q}\n"
|
78
|
+
" parses file as a Response, reQuest, or Both\n",
|
79
|
+
name);
|
80
|
+
exit(EXIT_FAILURE);
|
81
|
+
}
|
82
|
+
|
83
|
+
int main(int argc, char* argv[]) {
|
84
|
+
enum http_parser_type file_type;
|
85
|
+
|
86
|
+
if (argc != 3) {
|
87
|
+
usage(argv[0]);
|
88
|
+
}
|
89
|
+
|
90
|
+
char* type = argv[1];
|
91
|
+
if (type[0] != '-') {
|
92
|
+
usage(argv[0]);
|
93
|
+
}
|
94
|
+
|
95
|
+
switch (type[1]) {
|
96
|
+
/* in the case of "-", type[1] will be NUL */
|
97
|
+
case 'r':
|
98
|
+
file_type = HTTP_RESPONSE;
|
99
|
+
break;
|
100
|
+
case 'q':
|
101
|
+
file_type = HTTP_REQUEST;
|
102
|
+
break;
|
103
|
+
case 'b':
|
104
|
+
file_type = HTTP_BOTH;
|
105
|
+
break;
|
106
|
+
default:
|
107
|
+
usage(argv[0]);
|
108
|
+
}
|
109
|
+
|
110
|
+
char* filename = argv[2];
|
111
|
+
FILE* file = fopen(filename, "r");
|
112
|
+
if (file == NULL) {
|
113
|
+
perror("fopen");
|
114
|
+
goto fail;
|
115
|
+
}
|
116
|
+
|
117
|
+
fseek(file, 0, SEEK_END);
|
118
|
+
long file_length = ftell(file);
|
119
|
+
if (file_length == -1) {
|
120
|
+
perror("ftell");
|
121
|
+
goto fail;
|
122
|
+
}
|
123
|
+
fseek(file, 0, SEEK_SET);
|
124
|
+
|
125
|
+
char* data = malloc(file_length);
|
126
|
+
if (fread(data, 1, file_length, file) != (size_t)file_length) {
|
127
|
+
fprintf(stderr, "couldn't read entire file\n");
|
128
|
+
free(data);
|
129
|
+
goto fail;
|
130
|
+
}
|
131
|
+
|
132
|
+
http_parser_settings settings;
|
133
|
+
memset(&settings, 0, sizeof(settings));
|
134
|
+
settings.on_message_begin = on_message_begin;
|
135
|
+
settings.on_url = on_url;
|
136
|
+
settings.on_header_field = on_header_field;
|
137
|
+
settings.on_header_value = on_header_value;
|
138
|
+
settings.on_headers_complete = on_headers_complete;
|
139
|
+
settings.on_body = on_body;
|
140
|
+
settings.on_message_complete = on_message_complete;
|
141
|
+
|
142
|
+
http_parser parser;
|
143
|
+
http_parser_init(&parser, file_type);
|
144
|
+
size_t nparsed = http_parser_execute(&parser, &settings, data, file_length);
|
145
|
+
free(data);
|
146
|
+
|
147
|
+
if (nparsed != (size_t)file_length) {
|
148
|
+
fprintf(stderr,
|
149
|
+
"Error: %s (%s)\n",
|
150
|
+
http_errno_description(HTTP_PARSER_ERRNO(&parser)),
|
151
|
+
http_errno_name(HTTP_PARSER_ERRNO(&parser)));
|
152
|
+
goto fail;
|
153
|
+
}
|
154
|
+
|
155
|
+
return EXIT_SUCCESS;
|
156
|
+
|
157
|
+
fail:
|
158
|
+
fclose(file);
|
159
|
+
return EXIT_FAILURE;
|
160
|
+
}
|