hyper-timeout-0.5.2/.cargo_vcs_info.json0000644000000001360000000000100136530ustar { "git": { "sha1": "b395dd6d5a8e655f6b2ea89e8a2673abc11ef945" }, "path_in_vcs": "" }hyper-timeout-0.5.2/.github/workflows/ci.yml000064400000000000000000000026611046102023000171630ustar 00000000000000on: push: branches: - master pull_request: {} name: Continuous integration jobs: check: name: Check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - uses: actions-rs/cargo@v1 with: command: check test: name: Test Suite runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - uses: actions-rs/cargo@v1 with: command: test fmt: name: Rustfmt runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - run: rustup component add rustfmt - uses: actions-rs/cargo@v1 with: command: fmt args: --all -- --check clippy: name: Clippy runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - run: rustup component add clippy - uses: actions-rs/cargo@v1 with: command: clippy args: -- -D warnings hyper-timeout-0.5.2/.gitignore000064400000000000000000000000221046102023000144250ustar 00000000000000target Cargo.lock hyper-timeout-0.5.2/Cargo.lock0000644000000464750000000000100116460ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "addr2line" version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] [[package]] name = "adler" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "autocfg" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line", "cc", "cfg-if 1.0.0", "libc", "miniz_oxide", "object", "rustc-demangle", ] [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "bytes" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" [[package]] name = "cc" version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ "libc", ] [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "core-foundation" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" dependencies = [ "core-foundation-sys", "libc", ] [[package]] name = "core-foundation-sys" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" [[package]] name = "fnv" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" [[package]] name = "foreign-types" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ "foreign-types-shared", ] [[package]] name = "foreign-types-shared" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "futures-channel" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcae98ca17d102fd8a3603727b9259fcf7fa4239b603d2142926189bc8999b86" dependencies = [ "futures-core", ] [[package]] name = "futures-core" version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" [[package]] name = "futures-task" version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" [[package]] name = "futures-util" version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" dependencies = [ "futures-core", "futures-task", "pin-project-lite", "pin-utils", ] [[package]] name = "getrandom" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ "cfg-if 1.0.0", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] [[package]] name = "gimli" version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "http" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" dependencies = [ "bytes", "fnv", "itoa", ] [[package]] name = "http-body" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" dependencies = [ "bytes", "http", ] [[package]] name = "http-body-util" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" dependencies = [ "bytes", "futures-util", "http", "http-body", "pin-project-lite", ] [[package]] name = "httparse" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbbff0a806a4728c99295b254c8838933b5b082d75e3cb70c8dab21fdfbcfa9a" dependencies = [ "bytes", "futures-channel", "futures-util", "http", "http-body", "httparse", "httpdate", "itoa", "pin-project-lite", "smallvec", "tokio", "want", ] [[package]] name = "hyper-timeout" version = "0.5.2" dependencies = [ "http-body-util", "hyper", "hyper-tls", "hyper-util", "pin-project-lite", "tokio", "tower-service", ] [[package]] name = "hyper-tls" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", "hyper", "hyper-util", "native-tls", "tokio", "tokio-native-tls", "tower-service", ] [[package]] name = "hyper-util" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" dependencies = [ "bytes", "futures-channel", "futures-util", "http", "http-body", "hyper", "pin-project-lite", "socket2", "tokio", "tower-service", "tracing", ] [[package]] name = "itoa" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "log" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" dependencies = [ "cfg-if 0.1.10", ] [[package]] name = "memchr" version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "miniz_oxide" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" dependencies = [ "adler", ] [[package]] name = "mio" version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys", ] [[package]] name = "native-tls" version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" dependencies = [ "lazy_static", "libc", "log", "openssl", "openssl-probe", "openssl-sys", "schannel", "security-framework", "security-framework-sys", "tempfile", ] [[package]] name = "object" version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" dependencies = [ "memchr", ] [[package]] name = "openssl" version = "0.10.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "038d43985d1ddca7a9900630d8cd031b56e4794eecc2e9ea39dd17aa04399a70" dependencies = [ "bitflags", "cfg-if 1.0.0", "foreign-types", "lazy_static", "libc", "openssl-sys", ] [[package]] name = "openssl-probe" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-sys" version = "0.9.60" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6" dependencies = [ "autocfg", "cc", "libc", "pkg-config", "vcpkg", ] [[package]] name = "pin-project-lite" version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "ppv-lite86" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "proc-macro2" version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] [[package]] name = "rand" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ "getrandom", "libc", "rand_chacha", "rand_core", "rand_hc", ] [[package]] name = "rand_chacha" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", "rand_core", ] [[package]] name = "rand_core" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ "getrandom", ] [[package]] name = "rand_hc" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ "rand_core", ] [[package]] name = "redox_syscall" version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "remove_dir_all" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ "winapi", ] [[package]] name = "rustc-demangle" version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "schannel" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" dependencies = [ "lazy_static", "winapi", ] [[package]] name = "security-framework" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69" dependencies = [ "bitflags", "core-foundation", "core-foundation-sys", "libc", "security-framework-sys", ] [[package]] name = "security-framework-sys" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b" dependencies = [ "core-foundation-sys", "libc", ] [[package]] name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", "windows-sys", ] [[package]] name = "syn" version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "tempfile" version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ "cfg-if 0.1.10", "libc", "rand", "redox_syscall", "remove_dir_all", "winapi", ] [[package]] name = "tokio" version = "1.35.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ "backtrace", "bytes", "libc", "mio", "pin-project-lite", "socket2", "tokio-macros", "windows-sys", ] [[package]] name = "tokio-macros" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "tokio-native-tls" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" dependencies = [ "native-tls", "tokio", ] [[package]] name = "tower-service" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" [[package]] name = "tracing" version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" dependencies = [ "cfg-if 1.0.0", "pin-project-lite", "tracing-core", ] [[package]] name = "tracing-core" version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" dependencies = [ "lazy_static", ] [[package]] name = "try-lock" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "vcpkg" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" [[package]] name = "want" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ "log", "try-lock", ] [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" hyper-timeout-0.5.2/Cargo.toml0000644000000034450000000000100116570ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "hyper-timeout" version = "0.5.2" authors = ["Herman J. Radtke III "] build = false autobins = false autoexamples = false autotests = false autobenches = false description = "A connect, read and write timeout aware connector to be used with hyper Client." homepage = "https://github.com/hjr3/hyper-timeout" documentation = "https://github.com/hjr3/hyper-timeout" readme = "README.md" license = "MIT OR Apache-2.0" repository = "https://github.com/hjr3/hyper-timeout" [lib] name = "hyper_timeout" path = "src/lib.rs" [[example]] name = "client" path = "examples/client.rs" [[test]] name = "client_upload" path = "tests/client_upload.rs" [dependencies.hyper] version = "1.1" [dependencies.hyper-util] version = "0.1.10" features = [ "client-legacy", "http1", ] [dependencies.pin-project-lite] version = "0.2" [dependencies.tokio] version = "1.35" [dependencies.tower-service] version = "0.3" [dev-dependencies.http-body-util] version = "0.1" [dev-dependencies.hyper] version = "1.1" features = ["http1"] [dev-dependencies.hyper-tls] version = "0.6" [dev-dependencies.hyper-util] version = "0.1.10" features = [ "client-legacy", "http1", "server", "server-graceful", ] [dev-dependencies.tokio] version = "1.35" features = [ "io-std", "io-util", "macros", ] hyper-timeout-0.5.2/Cargo.toml.orig000064400000000000000000000015731046102023000153400ustar 00000000000000[package] name = "hyper-timeout" version = "0.5.2" authors = ["Herman J. Radtke III "] edition = "2018" description = "A connect, read and write timeout aware connector to be used with hyper Client." license = "MIT OR Apache-2.0" documentation = "https://github.com/hjr3/hyper-timeout" homepage = "https://github.com/hjr3/hyper-timeout" repository = "https://github.com/hjr3/hyper-timeout" readme = "README.md" [dependencies] hyper = "1.1" hyper-util = { version = "0.1.10", features = ["client-legacy", "http1"] } pin-project-lite = "0.2" tokio = "1.35" tower-service = "0.3" [dev-dependencies] tokio = { version = "1.35", features = ["io-std", "io-util", "macros"] } hyper = { version = "1.1", features = ["http1"] } hyper-tls = "0.6" http-body-util = "0.1" hyper-util = { version = "0.1.10", features = ["client-legacy", "http1", "server", "server-graceful"] } hyper-timeout-0.5.2/LICENSE-APACHE000064400000000000000000000251371046102023000143770ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. hyper-timeout-0.5.2/LICENSE-MIT000064400000000000000000000021101046102023000140710ustar 00000000000000The MIT License (MIT) Copyright (c) 2016 The weldr Project Developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. hyper-timeout-0.5.2/README.md000064400000000000000000000044641046102023000137320ustar 00000000000000[![crates.io](https://img.shields.io/crates/v/hyper-timeout.svg)](https://crates.io/crates/hyper-timeout) # hyper-timeout A connect, read and write timeout aware connector to be used with hyper `Client`. ## Problem At the time this crate was created, hyper did not support timeouts. There is a way to do general timeouts, but no easy way to get connect, read and write specific timeouts. ## Solution There is a `TimeoutConnector` that implements the `hyper::Connect` trait. This connector wraps around `HttpConnector` or `HttpsConnector` values and provides timeouts. > [!IMPORTANT] > The timeouts are on the underlying stream and _not_ the request. - The read timeout will start when the underlying stream is first polled for read. - The write timeout will start when the underlying stream is first polled for write. Tokio often interleaves poll_read and poll_write calls to handle this bi-directional communication efficiently. Due to this behavior, both the read and write timeouts start at the same time. This means your read timeout can expire while the client is still writing the request to the server. If you are writing large bodies, consider using `set_reset_reader_on_write` to avoid this behavior. ## Usage Hyper version compatibility: - The `master` branch will track on going development for hyper. - The `0.5` release supports hyper 1.0. - The `0.4` release supports hyper 0.14. - The `0.3` release supports hyper 0.13. - The `0.2` release supports hyper 0.12. - The `0.1` release supports hyper 0.11. - **Note:** In hyper 0.11, a read or write timeout will return a _broken pipe_ error because of the way `tokio_proto::ClientProto` works Assuming you are using hyper 1.0, add this to your `Cargo.toml`: ```toml [dependencies] hyper-timeout = "0.5" ``` See the [client example](./examples/client.rs) for a working example. ## License Licensed under either of * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. hyper-timeout-0.5.2/examples/client.rs000064400000000000000000000030731046102023000161100ustar 00000000000000use std::env; use std::time::Duration; use http_body_util::{BodyExt, Empty}; use hyper::body::Bytes; use hyper_util::{client::legacy::Client, rt::TokioExecutor}; use tokio::io::{self, AsyncWriteExt}; use hyper_tls::HttpsConnector; use hyper_timeout::TimeoutConnector; #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), Box> { let url = match env::args().nth(1) { Some(url) => url, None => { println!("Usage: client "); println!("Example: client https://example.com"); return Ok(()); } }; let url = url.parse::().unwrap(); // This example uses `HttpsConnector`, but you can also use hyper `HttpConnector` //let h = hyper_util::client::legacy::connect::HttpConnector::new(); let h = HttpsConnector::new(); let mut connector = TimeoutConnector::new(h); connector.set_connect_timeout(Some(Duration::from_secs(5))); connector.set_read_timeout(Some(Duration::from_secs(5))); connector.set_write_timeout(Some(Duration::from_secs(5))); let client = Client::builder(TokioExecutor::new()).build::<_, Empty>(connector); let mut res = client.get(url).await?; println!("Status: {}", res.status()); println!("Headers:\n{:#?}", res.headers()); while let Some(frame) = res.body_mut().frame().await { let bytes = frame? .into_data() .map_err(|_| io::Error::new(io::ErrorKind::Other, "Error when consuming frame"))?; io::stdout().write_all(&bytes).await?; } Ok(()) } hyper-timeout-0.5.2/src/lib.rs000064400000000000000000000146251046102023000143560ustar 00000000000000use std::future::Future; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; use hyper::rt::{Read, Write}; use tokio::time::timeout; use hyper::Uri; use hyper_util::client::legacy::connect::{Connected, Connection}; use tower_service::Service; mod stream; use stream::TimeoutStream; type BoxError = Box; /// A connector that enforces a connection timeout #[derive(Debug, Clone)] pub struct TimeoutConnector { /// A connector implementing the `Connect` trait connector: T, /// Amount of time to wait connecting connect_timeout: Option, /// Amount of time to wait reading response read_timeout: Option, /// Amount of time to wait writing request write_timeout: Option, /// If true, resets the reader timeout whenever a write occures reset_reader_on_write: bool, } impl TimeoutConnector where T: Service + Send, T::Response: Read + Write + Send + Unpin, T::Future: Send + 'static, T::Error: Into, { /// Construct a new TimeoutConnector with a given connector implementing the `Connect` trait pub fn new(connector: T) -> Self { TimeoutConnector { connector, connect_timeout: None, read_timeout: None, write_timeout: None, reset_reader_on_write: false, } } } impl Service for TimeoutConnector where T: Service + Send, T::Response: Read + Write + Connection + Send + Unpin, T::Future: Send + 'static, T::Error: Into, { type Response = Pin>>; type Error = BoxError; #[allow(clippy::type_complexity)] type Future = Pin> + Send>>; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { self.connector.poll_ready(cx).map_err(Into::into) } fn call(&mut self, dst: Uri) -> Self::Future { let connect_timeout = self.connect_timeout; let read_timeout = self.read_timeout; let write_timeout = self.write_timeout; let reset_reader_on_write = self.reset_reader_on_write; let connecting = self.connector.call(dst); let fut = async move { let mut stream = match connect_timeout { None => { let io = connecting.await.map_err(Into::into)?; TimeoutStream::new(io) } Some(connect_timeout) => { let timeout = timeout(connect_timeout, connecting); let connecting = timeout .await .map_err(|e| io::Error::new(io::ErrorKind::TimedOut, e))?; let io = connecting.map_err(Into::into)?; TimeoutStream::new(io) } }; stream.set_read_timeout(read_timeout); stream.set_write_timeout(write_timeout); stream.set_reset_reader_on_write(reset_reader_on_write); Ok(Box::pin(stream)) }; Box::pin(fut) } } impl TimeoutConnector { /// Set the timeout for connecting to a URL. /// /// Default is no timeout. #[inline] pub fn set_connect_timeout(&mut self, val: Option) { self.connect_timeout = val; } /// Set the timeout for the response. /// /// Default is no timeout. #[inline] pub fn set_read_timeout(&mut self, val: Option) { self.read_timeout = val; } /// Set the timeout for the request. /// /// Default is no timeout. #[inline] pub fn set_write_timeout(&mut self, val: Option) { self.write_timeout = val; } /// Reset on the reader timeout on write /// /// This will reset the reader timeout when a write is done through the /// the TimeoutReader. This is useful when you don't want to trigger /// a reader timeout while writes are still be accepted. pub fn set_reset_reader_on_write(&mut self, reset: bool) { self.reset_reader_on_write = reset; } } impl Connection for TimeoutConnector where T: Read + Write + Connection + Service + Send + Unpin, T::Response: Read + Write + Send + Unpin, T::Future: Send + 'static, T::Error: Into, { fn connected(&self) -> Connected { self.connector.connected() } } #[cfg(test)] mod tests { use std::time::Duration; use std::{error::Error, io}; use http_body_util::Empty; use hyper::body::Bytes; use hyper_util::{ client::legacy::{connect::HttpConnector, Client}, rt::TokioExecutor, }; use super::TimeoutConnector; #[tokio::test] async fn test_timeout_connector() { // 10.255.255.1 is a not a routable IP address let url = "http://10.255.255.1".parse().unwrap(); let http = HttpConnector::new(); let mut connector = TimeoutConnector::new(http); connector.set_connect_timeout(Some(Duration::from_millis(1))); let client = Client::builder(TokioExecutor::new()).build::<_, Empty>(connector); let res = client.get(url).await; match res { Ok(_) => panic!("Expected a timeout"), Err(e) => { if let Some(io_e) = e.source().unwrap().downcast_ref::() { assert_eq!(io_e.kind(), io::ErrorKind::TimedOut); } else { panic!("Expected timeout error"); } } } } #[tokio::test] async fn test_read_timeout() { let url = "http://example.com".parse().unwrap(); let http = HttpConnector::new(); let mut connector = TimeoutConnector::new(http); // A 1 ms read timeout should be so short that we trigger a timeout error connector.set_read_timeout(Some(Duration::from_millis(1))); let client = Client::builder(TokioExecutor::new()).build::<_, Empty>(connector); let res = client.get(url).await; if let Err(client_e) = res { if let Some(hyper_e) = client_e.source() { if let Some(io_e) = hyper_e.source().unwrap().downcast_ref::() { return assert_eq!(io_e.kind(), io::ErrorKind::TimedOut); } } } panic!("Expected timeout error"); } } hyper-timeout-0.5.2/src/stream.rs000064400000000000000000000534271046102023000151060ustar 00000000000000//! Wrappers for applying timeouts to IO operations. //! //! This used to depend on [tokio-io-timeout]. After Hyper 1.0 introduced hyper-specific IO traits, this was rewritten to use hyper IO traits instead of tokio IO traits. //! //! These timeouts are analogous to the read and write timeouts on traditional blocking sockets. A timeout countdown is //! initiated when a read/write operation returns [`Poll::Pending`]. If a read/write does not return successfully before //! the countdown expires, an [`io::Error`] with a kind of [`TimedOut`](io::ErrorKind::TimedOut) is returned. #![warn(missing_docs)] use hyper::rt::{Read, ReadBuf, ReadBufCursor, Write}; use hyper_util::client::legacy::connect::{Connected, Connection}; use pin_project_lite::pin_project; use std::future::Future; use std::io; use std::pin::Pin; use std::task::{ready, Context, Poll}; use std::time::Duration; use tokio::time::{sleep_until, Instant, Sleep}; pin_project! { #[derive(Debug)] struct TimeoutState { timeout: Option, #[pin] cur: Sleep, active: bool, } } impl TimeoutState { #[inline] fn new() -> TimeoutState { TimeoutState { timeout: None, cur: sleep_until(Instant::now()), active: false, } } #[inline] fn timeout(&self) -> Option { self.timeout } #[inline] fn set_timeout(&mut self, timeout: Option) { // since this takes &mut self, we can't yet be active self.timeout = timeout; } #[inline] fn set_timeout_pinned(mut self: Pin<&mut Self>, timeout: Option) { *self.as_mut().project().timeout = timeout; self.reset(); } #[inline] fn reset(self: Pin<&mut Self>) { let this = self.project(); if *this.active { *this.active = false; this.cur.reset(Instant::now()); } } #[inline] fn restart(self: Pin<&mut Self>) { let this = self.project(); if *this.active { let timeout = match this.timeout { Some(timeout) => *timeout, None => return, }; this.cur.reset(Instant::now() + timeout); } } #[inline] fn poll_check(self: Pin<&mut Self>, cx: &mut Context) -> io::Result<()> { let mut this = self.project(); let timeout = match this.timeout { Some(timeout) => *timeout, None => return Ok(()), }; if !*this.active { this.cur.as_mut().reset(Instant::now() + timeout); *this.active = true; } match this.cur.poll(cx) { Poll::Ready(()) => Err(io::Error::from(io::ErrorKind::TimedOut)), Poll::Pending => Ok(()), } } } pin_project! { /// An `hyper::rt::Read`er which applies a timeout to read operations. #[derive(Debug)] pub struct TimeoutReader { #[pin] reader: R, #[pin] state: TimeoutState, reset_on_write: bool, } } impl TimeoutReader where R: Read, { /// Returns a new `TimeoutReader` wrapping the specified reader. /// /// There is initially no timeout. pub fn new(reader: R) -> TimeoutReader { TimeoutReader { reader, state: TimeoutState::new(), reset_on_write: false, } } /// Returns the current read timeout. pub fn timeout(&self) -> Option { self.state.timeout() } /// Sets the read timeout. /// /// This can only be used before the reader is pinned; use [`set_timeout_pinned`](Self::set_timeout_pinned) /// otherwise. pub fn set_timeout(&mut self, timeout: Option) { self.state.set_timeout(timeout); } /// Sets the read timeout. /// /// This will reset any pending timeout. Use [`set_timeout`](Self::set_timeout) instead if the reader is not yet /// pinned. pub fn set_timeout_pinned(self: Pin<&mut Self>, timeout: Option) { self.project().state.set_timeout_pinned(timeout); } /// Returns a shared reference to the inner reader. pub fn get_ref(&self) -> &R { &self.reader } /// Returns a mutable reference to the inner reader. pub fn get_mut(&mut self) -> &mut R { &mut self.reader } /// Returns a pinned mutable reference to the inner reader. pub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut R> { self.project().reader } /// Consumes the `TimeoutReader`, returning the inner reader. pub fn into_inner(self) -> R { self.reader } } impl TimeoutReader where R: Read + Write, { /// Reset on the reader timeout on write /// /// This will reset the reader timeout when a write is done through the /// the TimeoutReader. This is useful when you don't want to trigger /// a reader timeout while writes are still be accepted. pub fn set_reset_on_write(&mut self, reset: bool) { self.reset_on_write = reset } } impl Read for TimeoutReader where R: Read, { fn poll_read( self: Pin<&mut Self>, cx: &mut Context, buf: ReadBufCursor, ) -> Poll> { let this = self.project(); let r = this.reader.poll_read(cx, buf); match r { Poll::Pending => this.state.poll_check(cx)?, _ => this.state.reset(), } r } } impl Write for TimeoutReader where R: Write, { fn poll_write( self: Pin<&mut Self>, cx: &mut Context, buf: &[u8], ) -> Poll> { let this = self.project(); let r = this.reader.poll_write(cx, buf); if *this.reset_on_write && r.is_ready() { this.state.restart(); } r } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { let this = self.project(); let r = this.reader.poll_flush(cx); if *this.reset_on_write && r.is_ready() { this.state.restart(); } r } fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { let this = self.project(); let r = this.reader.poll_shutdown(cx); if *this.reset_on_write && r.is_ready() { this.state.restart(); } r } fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context, bufs: &[io::IoSlice], ) -> Poll> { let this = self.project(); let r = this.reader.poll_write_vectored(cx, bufs); if *this.reset_on_write && r.is_ready() { this.state.restart(); } r } fn is_write_vectored(&self) -> bool { self.reader.is_write_vectored() } } pin_project! { /// An `hyper::rt::Write`er which applies a timeout to write operations. #[derive(Debug)] pub struct TimeoutWriter { #[pin] writer: W, #[pin] state: TimeoutState, } } impl TimeoutWriter where W: Write, { /// Returns a new `TimeoutReader` wrapping the specified reader. /// /// There is initially no timeout. pub fn new(writer: W) -> TimeoutWriter { TimeoutWriter { writer, state: TimeoutState::new(), } } /// Returns the current write timeout. pub fn timeout(&self) -> Option { self.state.timeout() } /// Sets the write timeout. /// /// This can only be used before the writer is pinned; use [`set_timeout_pinned`](Self::set_timeout_pinned) /// otherwise. pub fn set_timeout(&mut self, timeout: Option) { self.state.set_timeout(timeout); } /// Sets the write timeout. /// /// This will reset any pending timeout. Use [`set_timeout`](Self::set_timeout) instead if the reader is not yet /// pinned. pub fn set_timeout_pinned(self: Pin<&mut Self>, timeout: Option) { self.project().state.set_timeout_pinned(timeout); } /// Returns a shared reference to the inner writer. pub fn get_ref(&self) -> &W { &self.writer } /// Returns a mutable reference to the inner writer. pub fn get_mut(&mut self) -> &mut W { &mut self.writer } /// Returns a pinned mutable reference to the inner writer. pub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut W> { self.project().writer } /// Consumes the `TimeoutWriter`, returning the inner writer. pub fn into_inner(self) -> W { self.writer } } impl Write for TimeoutWriter where W: Write, { fn poll_write( self: Pin<&mut Self>, cx: &mut Context, buf: &[u8], ) -> Poll> { let this = self.project(); let r = this.writer.poll_write(cx, buf); match r { Poll::Pending => this.state.poll_check(cx)?, _ => this.state.reset(), } r } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { let this = self.project(); let r = this.writer.poll_flush(cx); match r { Poll::Pending => this.state.poll_check(cx)?, _ => this.state.reset(), } r } fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { let this = self.project(); let r = this.writer.poll_shutdown(cx); match r { Poll::Pending => this.state.poll_check(cx)?, _ => this.state.reset(), } r } fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context, bufs: &[io::IoSlice], ) -> Poll> { let this = self.project(); let r = this.writer.poll_write_vectored(cx, bufs); match r { Poll::Pending => this.state.poll_check(cx)?, _ => this.state.reset(), } r } fn is_write_vectored(&self) -> bool { self.writer.is_write_vectored() } } impl Read for TimeoutWriter where W: Read, { fn poll_read( self: Pin<&mut Self>, cx: &mut Context, buf: ReadBufCursor, ) -> Poll> { self.project().writer.poll_read(cx, buf) } } pin_project! { /// A stream which applies read and write timeouts to an inner stream. #[derive(Debug)] pub struct TimeoutStream { #[pin] stream: TimeoutReader> } } impl TimeoutStream where S: Read + Write, { /// Returns a new `TimeoutStream` wrapping the specified stream. /// /// There is initially no read or write timeout. pub fn new(stream: S) -> TimeoutStream { let writer = TimeoutWriter::new(stream); let stream = TimeoutReader::new(writer); TimeoutStream { stream } } /// Returns the current read timeout. pub fn read_timeout(&self) -> Option { self.stream.timeout() } /// Sets the read timeout. /// /// This can only be used before the stream is pinned; use /// [`set_read_timeout_pinned`](Self::set_read_timeout_pinned) otherwise. pub fn set_read_timeout(&mut self, timeout: Option) { self.stream.set_timeout(timeout) } /// Sets the read timeout. /// /// This will reset any pending read timeout. Use [`set_read_timeout`](Self::set_read_timeout) instead if the stream /// has not yet been pinned. pub fn set_read_timeout_pinned(self: Pin<&mut Self>, timeout: Option) { self.project().stream.set_timeout_pinned(timeout) } /// Returns the current write timeout. pub fn write_timeout(&self) -> Option { self.stream.get_ref().timeout() } /// Sets the write timeout. /// /// This can only be used before the stream is pinned; use /// [`set_write_timeout_pinned`](Self::set_write_timeout_pinned) otherwise. pub fn set_write_timeout(&mut self, timeout: Option) { self.stream.get_mut().set_timeout(timeout) } /// Sets the write timeout. /// /// This will reset any pending write timeout. Use [`set_write_timeout`](Self::set_write_timeout) instead if the /// stream has not yet been pinned. pub fn set_write_timeout_pinned(self: Pin<&mut Self>, timeout: Option) { self.project() .stream .get_pin_mut() .set_timeout_pinned(timeout) } /// Reset on the reader timeout on write /// /// This will reset the reader timeout when a write is done through the /// the TimeoutReader. This is useful when you don't want to trigger /// a reader timeout while writes are still be accepted. pub fn set_reset_reader_on_write(&mut self, reset: bool) { self.stream.set_reset_on_write(reset); } /// Returns a shared reference to the inner stream. pub fn get_ref(&self) -> &S { self.stream.get_ref().get_ref() } /// Returns a mutable reference to the inner stream. pub fn get_mut(&mut self) -> &mut S { self.stream.get_mut().get_mut() } /// Returns a pinned mutable reference to the inner stream. pub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut S> { self.project().stream.get_pin_mut().get_pin_mut() } /// Consumes the stream, returning the inner stream. pub fn into_inner(self) -> S { self.stream.into_inner().into_inner() } } impl Read for TimeoutStream where S: Read + Write, { fn poll_read( self: Pin<&mut Self>, cx: &mut Context, buf: ReadBufCursor, ) -> Poll> { self.project().stream.poll_read(cx, buf) } } impl Write for TimeoutStream where S: Read + Write, { fn poll_write( self: Pin<&mut Self>, cx: &mut Context, buf: &[u8], ) -> Poll> { self.project().stream.poll_write(cx, buf) } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { self.project().stream.poll_flush(cx) } fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { self.project().stream.poll_shutdown(cx) } fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context, bufs: &[io::IoSlice], ) -> Poll> { self.project().stream.poll_write_vectored(cx, bufs) } fn is_write_vectored(&self) -> bool { self.stream.is_write_vectored() } } impl Connection for TimeoutStream where S: Read + Write + Connection + Unpin, { fn connected(&self) -> Connected { self.get_ref().connected() } } impl Connection for Pin>> where S: Read + Write + Connection + Unpin, { fn connected(&self) -> Connected { self.get_ref().connected() } } pin_project! { /// A future which can be used to easily read available number of bytes to fill /// a buffer. Based on the internal [tokio::io::util::read::Read] struct ReadFut<'a, R: ?Sized> { reader: &'a mut R, buf: &'a mut [u8], } } /// Tries to read some bytes directly into the given `buf` in asynchronous /// manner, returning a future type. /// /// The returned future will resolve to both the I/O stream and the buffer /// as well as the number of bytes read once the read operation is completed. #[cfg(test)] fn read<'a, R>(reader: &'a mut R, buf: &'a mut [u8]) -> ReadFut<'a, R> where R: Read + Unpin + ?Sized, { ReadFut { reader, buf } } impl Future for ReadFut<'_, R> where R: Read + Unpin + ?Sized, { type Output = io::Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let me = self.project(); let mut buf = ReadBuf::new(me.buf); ready!(Pin::new(me.reader).poll_read(cx, buf.unfilled()))?; Poll::Ready(Ok(buf.filled().len())) } } #[cfg(test)] trait ReadExt: Read { /// Pulls some bytes from this source into the specified buffer, /// returning how many bytes were read. fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFut<'a, Self> where Self: Unpin, { read(self, buf) } } pin_project! { /// A future to write some of the buffer to an `AsyncWrite`.- struct WriteFut<'a, W: ?Sized> { writer: &'a mut W, buf: &'a [u8], } } /// Tries to write some bytes from the given `buf` to the writer in an /// asynchronous manner, returning a future. #[cfg(test)] fn write<'a, W>(writer: &'a mut W, buf: &'a [u8]) -> WriteFut<'a, W> where W: Write + Unpin + ?Sized, { WriteFut { writer, buf } } impl Future for WriteFut<'_, W> where W: Write + Unpin + ?Sized, { type Output = io::Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let me = self.project(); Pin::new(&mut *me.writer).poll_write(cx, me.buf) } } #[cfg(test)] trait WriteExt: Write { /// Writes a buffer into this writer, returning how many bytes were /// written. fn write<'a>(&'a mut self, src: &'a [u8]) -> WriteFut<'a, Self> where Self: Unpin, { write(self, src) } } #[cfg(test)] impl ReadExt for Pin<&mut TimeoutReader> where R: Read, { fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFut<'a, Self> { read(self, buf) } } #[cfg(test)] impl WriteExt for Pin<&mut TimeoutWriter> where W: Write, { fn write<'a>(&'a mut self, src: &'a [u8]) -> WriteFut<'a, Self> { write(self, src) } } #[cfg(test)] impl ReadExt for Pin<&mut TimeoutStream> where S: Read + Write, { fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFut<'a, Self> { read(self, buf) } } #[cfg(test)] impl WriteExt for Pin<&mut TimeoutStream> where S: Read + Write, { fn write<'a>(&'a mut self, src: &'a [u8]) -> WriteFut<'a, Self> { write(self, src) } } #[cfg(test)] mod test { use super::*; use hyper_util::rt::TokioIo; use std::io::Write; use std::net::TcpListener; use std::thread; use tokio::net::TcpStream; use tokio::pin; pin_project! { struct DelayStream { #[pin] sleep: Sleep, } } impl DelayStream { fn new(until: Instant) -> Self { DelayStream { sleep: sleep_until(until), } } } impl Read for DelayStream { fn poll_read( self: Pin<&mut Self>, cx: &mut Context, _buf: ReadBufCursor, ) -> Poll> { match self.project().sleep.poll(cx) { Poll::Ready(()) => Poll::Ready(Ok(())), Poll::Pending => Poll::Pending, } } } impl hyper::rt::Write for DelayStream { fn poll_write( self: Pin<&mut Self>, cx: &mut Context, buf: &[u8], ) -> Poll> { match self.project().sleep.poll(cx) { Poll::Ready(()) => Poll::Ready(Ok(buf.len())), Poll::Pending => Poll::Pending, } } fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context) -> Poll> { Poll::Ready(Ok(())) } fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context) -> Poll> { Poll::Ready(Ok(())) } } #[tokio::test] async fn read_timeout() { let reader = DelayStream::new(Instant::now() + Duration::from_millis(500)); let mut reader = TimeoutReader::new(reader); reader.set_timeout(Some(Duration::from_millis(100))); pin!(reader); let r = reader.read(&mut [0, 1, 2]).await; assert_eq!(r.err().unwrap().kind(), io::ErrorKind::TimedOut); } #[tokio::test] async fn read_ok() { let reader = DelayStream::new(Instant::now() + Duration::from_millis(100)); let mut reader = TimeoutReader::new(reader); reader.set_timeout(Some(Duration::from_millis(500))); pin!(reader); reader.read(&mut [0]).await.unwrap(); } #[tokio::test] async fn write_timeout() { let writer = DelayStream::new(Instant::now() + Duration::from_millis(500)); let mut writer = TimeoutWriter::new(writer); writer.set_timeout(Some(Duration::from_millis(100))); pin!(writer); let r = writer.write(&[0]).await; assert_eq!(r.err().unwrap().kind(), io::ErrorKind::TimedOut); } #[tokio::test] async fn write_ok() { let writer = DelayStream::new(Instant::now() + Duration::from_millis(100)); let mut writer = TimeoutWriter::new(writer); writer.set_timeout(Some(Duration::from_millis(500))); pin!(writer); writer.write(&[0]).await.unwrap(); } #[tokio::test] async fn tcp_read() { let listener = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = listener.local_addr().unwrap(); thread::spawn(move || { let mut socket = listener.accept().unwrap().0; thread::sleep(Duration::from_millis(10)); socket.write_all(b"f").unwrap(); thread::sleep(Duration::from_millis(500)); let _ = socket.write_all(b"f"); // this may hit an eof }); let s = TcpStream::connect(&addr).await.unwrap(); let s = TokioIo::new(s); let mut s = TimeoutStream::new(s); s.set_read_timeout(Some(Duration::from_millis(100))); pin!(s); s.read(&mut [0]).await.unwrap(); let r = s.read(&mut [0]).await; match r { Ok(_) => panic!("unexpected success"), Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (), Err(e) => panic!("{:?}", e), } } } hyper-timeout-0.5.2/tests/client_upload.rs000064400000000000000000000070311046102023000167760ustar 00000000000000use http_body_util::{combinators::BoxBody, BodyExt, Full}; use hyper::body::Bytes; use hyper::server::conn::http1; use hyper::service::service_fn; use hyper::{Request, Response}; use hyper_util::{client::legacy::Client, rt::TokioIo}; use std::{net::SocketAddr, time::Duration}; use tokio::io; use tokio::net::TcpListener; use tokio::sync::oneshot; use tokio::task; use hyper_timeout::TimeoutConnector; async fn spawn_test_server(listener: TcpListener, shutdown_rx: oneshot::Receiver<()>) { let http = http1::Builder::new(); let graceful = hyper_util::server::graceful::GracefulShutdown::new(); let mut signal = std::pin::pin!(shutdown_rx); loop { tokio::select! { Ok((stream, _addr)) = listener.accept() => { let io = TokioIo::new(stream); let conn = http.serve_connection(io, service_fn(handle_request)); // watch this connection let fut = graceful.watch(conn); tokio::spawn(async move { if let Err(e) = fut.await { eprintln!("Error serving connection: {:?}", e); } }); }, _ = &mut signal => { eprintln!("graceful shutdown signal received"); break; } } } tokio::select! { _ = graceful.shutdown() => { eprintln!("all connections gracefully closed"); }, _ = tokio::time::sleep(std::time::Duration::from_millis(100)) => { eprintln!("timed out wait for all connections to close"); } } } async fn handle_request( req: Request, ) -> Result>, hyper::Error> { let body = req.collect().await.expect("Failed to read body").to_bytes(); assert!(!body.is_empty(), "empty body"); Ok(Response::new(full("finished"))) } fn full>(chunk: T) -> BoxBody { Full::new(chunk.into()) .map_err(|never| match never {}) .boxed() } #[tokio::test] async fn test_upload_timeout() { let addr = SocketAddr::from(([127, 0, 0, 1], 0)); let listener = TcpListener::bind(addr) .await .expect("Failed to bind listener"); let (shutdown_tx, shutdown_rx) = oneshot::channel(); let server_addr = listener.local_addr().unwrap(); let server_handle = task::spawn(spawn_test_server(listener, shutdown_rx)); let h = hyper_util::client::legacy::connect::HttpConnector::new(); let mut connector = TimeoutConnector::new(h); connector.set_read_timeout(Some(Duration::from_millis(5))); // comment this out and the test will fail connector.set_reset_reader_on_write(true); let client = Client::builder(hyper_util::rt::TokioExecutor::new()).build(connector); let body = vec![0; 10 * 1024 * 1024]; // 10MB let req = Request::post(format!("http://{}/", server_addr)) .body(full(body)) .expect("request builder"); let mut res = client.request(req).await.expect("request failed"); let mut resp_body = Vec::new(); while let Some(frame) = res.body_mut().frame().await { let bytes = frame .expect("frame error") .into_data() .map_err(|_| io::Error::new(io::ErrorKind::Other, "Error when consuming frame")) .expect("data error"); resp_body.extend_from_slice(&bytes); } assert_eq!(res.status(), 200); assert_eq!(resp_body, b"finished"); let _ = shutdown_tx.send(()); let _ = server_handle.await; }