From 315c0a94a05e9e012ea4c2353bc0c4ea12ca2057 Mon Sep 17 00:00:00 2001 From: "Chris West (Faux)" Date: Mon, 27 May 2019 17:22:48 +0100 Subject: [PATCH 1/4] remove Cargo.lock - this is a library crate --- .gitignore | 1 + Cargo.lock | 358 ----------------------------------------------------- 2 files changed, 1 insertion(+), 358 deletions(-) delete mode 100644 Cargo.lock diff --git a/.gitignore b/.gitignore index ed092f6..045a90c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +Cargo.lock target rls diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 1cceec1..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,358 +0,0 @@ -[[package]] -name = "ascii" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "base64" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "byteorder" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cc" -version = "1.0.32" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cfg-if" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "chunked_transfer" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cookie" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding" -version = "0.2.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-korean 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-simpchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-japanese" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-korean" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-simpchinese" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-singlebyte" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-tradchinese" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding_index_tests" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "idna" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "itoa" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "lazy_static" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "libc" -version = "0.2.51" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "log" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "matches" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "percent-encoding" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "qstring" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "redox_syscall" -version = "0.1.51" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "ring" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rustls" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "ryu" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "sct" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde" -version = "1.0.89" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "serde_json" -version = "1.0.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "smallvec" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "spin" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "time" -version = "0.1.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "unicode-normalization" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "untrusted" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "ureq" -version = "0.9.1" -dependencies = [ - "ascii 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", - "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "chunked_transfer 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cookie 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "qstring 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustls 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", - "webpki-roots 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "url" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "webpki" -version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "webpki-roots" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum ascii 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a5fc969a8ce2c9c0c4b0429bb8431544f6658283c8326ba5ff8c762b75369335" -"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" -"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" -"checksum cc 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ad0daef304fa0b4238f5f7ed7178774b43b06f6a9b6509f6642bef4ff1f7b9b2" -"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" -"checksum chunked_transfer 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f98beb6554de08a14bd7b5c6014963c79d6a25a1c66b1d4ecb9e733ccba51d6c" -"checksum cookie 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1465f8134efa296b4c19db34d909637cb2bf0f7aaf21299e23e18fa29ac557cf" -"checksum encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec" -"checksum encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91" -"checksum encoding-index-korean 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81" -"checksum encoding-index-simpchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7" -"checksum encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a" -"checksum encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18" -"checksum encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" -"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" -"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" -"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" -"checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" -"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" -"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" -"checksum qstring 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "545ec057a36a93e25fb5883baed912e4984af4e2543bbf0e3463d962e0408469" -"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" -"checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" -"checksum rustls 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "38af00e78b66109e7184a0ee16940f41583161b7ec0518af258e4bcaed15db25" -"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" -"checksum sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f5adf8fbd58e1b1b52699dc8bed2630faecb6d8c7bee77d009d6bbe4af569b9" -"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560" -"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" -"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" -"checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" -"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" -"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" -"checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" -"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" -"checksum webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4f7e1cd7900a3a6b65a3e8780c51a3e6b59c0e2c55c6dc69578c288d69f7d082" -"checksum webpki-roots 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c10fa4212003ba19a564f25cd8ab572c6791f99a03cc219c13ed35ccab00de0e" -"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" From 8e446f71c489385237e94a2d3a3ecd60ffcdc004 Mon Sep 17 00:00:00 2001 From: "Chris West (Faux)" Date: Mon, 27 May 2019 17:24:22 +0100 Subject: [PATCH 2/4] upgrade cookie --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 44b6637..65f92c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ tls = ["rustls", "webpki", "webpki-roots"] ascii = "0.9" base64 = "0.10" chunked_transfer = "1" -cookie = { version = "0.11", features = ["percent-encode"] } +cookie = { version = "0.12", features = ["percent-encode"] } lazy_static = "1" qstring = "0.6" url = "1" From 73d1c89e905a8de06b8c10fe6192694e4b3edf30 Mon Sep 17 00:00:00 2001 From: "Chris West (Faux)" Date: Mon, 27 May 2019 17:25:43 +0100 Subject: [PATCH 3/4] rustfmt --- src/stream.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stream.rs b/src/stream.rs index aaf0d2a..29cd466 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -98,8 +98,8 @@ pub(crate) fn connect_http(unit: &Unit) -> Result { #[cfg(feature = "tls")] pub(crate) fn connect_https(unit: &Unit) -> Result { - use std::sync::Arc; use lazy_static::lazy_static; + use std::sync::Arc; lazy_static! { static ref TLS_CONF: Arc = { From ceb7c3ac14ceee019e24eb3fcd5302b130b5ba6c Mon Sep 17 00:00:00 2001 From: "Chris West (Faux)" Date: Mon, 27 May 2019 17:44:14 +0100 Subject: [PATCH 4/4] use pub(crate) instead of include!() --- src/agent.rs | 25 ++++++++++------------- src/lib.rs | 5 ++++- src/pool.rs | 6 ++++-- src/request.rs | 54 ++++++++++++++++++++++++++++++------------------- src/response.rs | 15 +++++++------- src/stream.rs | 5 +++-- src/test/mod.rs | 2 +- src/unit.rs | 37 +++++++++++++++++++-------------- 8 files changed, 86 insertions(+), 63 deletions(-) diff --git a/src/agent.rs b/src/agent.rs index 9eed56e..24cb6c9 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -1,14 +1,11 @@ -use crate::error::Error; -use crate::pool::ConnectionPool; -use crate::response::{self, Response}; -use cookie::{Cookie, CookieJar}; +use std::sync::Arc; use std::sync::Mutex; -use crate::header::{add_header, get_all_headers, get_header, has_header, Header}; +use cookie::{Cookie, CookieJar}; -// to get to share private fields -include!("request.rs"); -include!("unit.rs"); +use crate::header::{self, Header}; +use crate::pool::ConnectionPool; +use crate::request::Request; /// Agents keep state between requests. /// @@ -41,9 +38,9 @@ include!("unit.rs"); #[derive(Debug, Default, Clone)] pub struct Agent { /// Copied into each request of this agent. - headers: Vec
, + pub(crate) headers: Vec
, /// Reused agent state for repeated requests from this agent. - state: Arc>>, + pub(crate) state: Arc>>, } /// Container of the state @@ -52,9 +49,9 @@ pub struct Agent { #[derive(Debug)] pub(crate) struct AgentState { /// Reused connections between requests. - pool: ConnectionPool, + pub(crate) pool: ConnectionPool, /// Cookies saved between requests. - jar: CookieJar, + pub(crate) jar: CookieJar, } impl AgentState { @@ -113,7 +110,7 @@ impl Agent { /// } /// ``` pub fn set(&mut self, header: &str, value: &str) -> &mut Agent { - add_header(&mut self.headers, Header::new(header, value)); + header::add_header(&mut self.headers, Header::new(header, value)); self } @@ -255,7 +252,7 @@ impl Agent { } } -fn basic_auth(user: &str, pass: &str) -> String { +pub(crate) fn basic_auth(user: &str, pass: &str) -> String { let safe = match user.find(':') { Some(idx) => &user[..idx], None => user, diff --git a/src/lib.rs b/src/lib.rs index 3587ba5..87b7598 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,8 +97,10 @@ mod body; mod error; mod header; mod pool; +mod request; mod response; mod stream; +mod unit; #[cfg(feature = "json")] mod serde_macros; @@ -106,9 +108,10 @@ mod serde_macros; #[cfg(test)] mod test; -pub use crate::agent::{Agent, Request}; +pub use crate::agent::Agent; pub use crate::error::Error; pub use crate::header::Header; +pub use crate::request::Request; pub use crate::response::Response; // re-export diff --git a/src/pool.rs b/src/pool.rs index 335db3e..6dff887 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -1,7 +1,9 @@ -use crate::agent::Unit; -use crate::stream::Stream; use std::collections::HashMap; use std::io::{Read, Result as IoResult}; + +use crate::stream::Stream; +use crate::unit::Unit; + use url::Url; pub const DEFAULT_HOST: &str = "localhost"; diff --git a/src/request.rs b/src/request.rs index b0a4aad..6f36c63 100644 --- a/src/request.rs +++ b/src/request.rs @@ -1,7 +1,17 @@ +use std::io::Read; +use std::sync::{Arc, Mutex}; + use lazy_static::lazy_static; use qstring::QString; -use std::io::Read; -use std::sync::Arc; +use url::Url; + +use crate::agent::{self, Agent, AgentState}; +use crate::body::Payload; +use crate::error::Error; +use crate::header::{self, Header}; +use crate::pool; +use crate::unit::{self, Unit}; +use crate::Response; #[cfg(feature = "json")] use super::SerdeValue; @@ -22,19 +32,19 @@ lazy_static! { /// ``` #[derive(Clone, Default)] pub struct Request { - agent: Arc>>, + pub(crate) agent: Arc>>, // via agent - method: String, + pub(crate) method: String, path: String, // from request itself - headers: Vec
, - query: QString, - timeout_connect: u64, - timeout_read: u64, - timeout_write: u64, - redirects: u32, + pub(crate) headers: Vec
, + pub(crate) query: QString, + pub(crate) timeout_connect: u64, + pub(crate) timeout_read: u64, + pub(crate) timeout_write: u64, + pub(crate) redirects: u32, } impl ::std::fmt::Debug for Request { @@ -42,7 +52,7 @@ impl ::std::fmt::Debug for Request { let (path, query) = self .to_url() .map(|u| { - let query = combine_query(&u, &self.query, true); + let query = unit::combine_query(&u, &self.query, true); (u.path().to_string(), query) }) .unwrap_or_else(|_| ("BAD_URL".to_string(), "BAD_URL".to_string())); @@ -55,7 +65,7 @@ impl ::std::fmt::Debug for Request { } impl Request { - fn new(agent: &Agent, method: String, path: String) -> Request { + pub(crate) fn new(agent: &Agent, method: String, path: String) -> Request { Request { agent: Arc::clone(&agent.state), method, @@ -99,7 +109,7 @@ impl Request { .and_then(|url| { let reader = payload.into_read(); let unit = Unit::new(&self, &url, true, &reader); - connect(&self, unit, true, 0, reader, false) + unit::connect(&self, unit, true, 0, reader, false) }) .unwrap_or_else(|e| e.into()) } @@ -148,7 +158,8 @@ impl Request { /// ``` pub fn send_string(&mut self, data: &str) -> Response { let text = data.into(); - let charset = response::charset_from_content_type(self.header("content-type")).to_string(); + let charset = + crate::response::charset_from_content_type(self.header("content-type")).to_string(); self.do_call(Payload::Text(text, charset)) } @@ -185,7 +196,7 @@ impl Request { /// } /// ``` pub fn set(&mut self, header: &str, value: &str) -> &mut Request { - add_header(&mut self.headers, Header::new(header, value)); + header::add_header(&mut self.headers, Header::new(header, value)); self } @@ -198,7 +209,7 @@ impl Request { /// assert_eq!("foobar", req.header("x-api-Key").unwrap()); /// ``` pub fn header<'a>(&self, name: &'a str) -> Option<&str> { - get_header(&self.headers, name) + header::get_header(&self.headers, name) } /// A list of the set header names in this request. Lowercased to be uniform. @@ -226,7 +237,7 @@ impl Request { /// assert_eq!(true, req.has("x-api-Key")); /// ``` pub fn has<'a>(&self, name: &'a str) -> bool { - has_header(&self.headers, name) + header::has_header(&self.headers, name) } /// All headers corresponding values for the give name, or empty vector. @@ -242,7 +253,7 @@ impl Request { /// ]); /// ``` pub fn all<'a>(&self, name: &'a str) -> Vec<&str> { - get_all_headers(&self.headers, name) + header::get_all_headers(&self.headers, name) } /// Set a query parameter. @@ -336,7 +347,7 @@ impl Request { /// println!("{:?}", r2); /// ``` pub fn auth(&mut self, user: &str, pass: &str) -> &mut Request { - let pass = basic_auth(user, pass); + let pass = agent::basic_auth(user, pass); self.auth_kind("Basic", &pass) } @@ -440,7 +451,7 @@ impl Request { /// ``` pub fn get_host(&self) -> Result { self.to_url() - .map(|u| u.host_str().unwrap_or(DEFAULT_HOST).to_string()) + .map(|u| u.host_str().unwrap_or(pool::DEFAULT_HOST).to_string()) } /// Returns the scheme for this request. @@ -465,7 +476,8 @@ impl Request { /// assert_eq!(req.get_query().unwrap(), "?foo=bar&format=json"); /// ``` pub fn get_query(&self) -> Result { - self.to_url().map(|u| combine_query(&u, &self.query, true)) + self.to_url() + .map(|u| unit::combine_query(&u, &self.query, true)) } /// The normalized path of this request. diff --git a/src/response.rs b/src/response.rs index d854527..33dbfb9 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,11 +1,14 @@ -use crate::agent::Unit; +use std::io::{Cursor, Error as IoError, ErrorKind, Read, Result as IoResult}; +use std::str::FromStr; + +use ascii::AsciiString; +use chunked_transfer::Decoder as ChunkDecoder; + +use crate::error::Error; use crate::header::Header; use crate::pool::PoolReturnRead; use crate::stream::Stream; -use ascii::AsciiString; -use chunked_transfer::Decoder as ChunkDecoder; -use std::io::{Cursor, Error as IoError, ErrorKind, Read, Result as IoResult}; -use std::str::FromStr; +use crate::unit::Unit; #[cfg(feature = "json")] use serde_json; @@ -15,8 +18,6 @@ use encoding::label::encoding_from_whatwg_label; #[cfg(feature = "charset")] use encoding::DecoderTrap; -use crate::error::Error; - pub const DEFAULT_CONTENT_TYPE: &str = "text/plain"; pub const DEFAULT_CHARACTER_SET: &str = "utf-8"; diff --git a/src/stream.rs b/src/stream.rs index 29cd466..bbe9d04 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -1,11 +1,12 @@ -use crate::agent::Unit; -use crate::error::Error; use std::io::{Cursor, Read, Result as IoResult, Write}; use std::net::SocketAddr; use std::net::TcpStream; use std::net::ToSocketAddrs; use std::time::Duration; +use crate::error::Error; +use crate::unit::Unit; + #[allow(clippy::large_enum_variant)] pub enum Stream { Http(TcpStream), diff --git a/src/test/mod.rs b/src/test/mod.rs index b1824db..38c59eb 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -1,6 +1,6 @@ -use crate::agent::Unit; use crate::error::Error; use crate::stream::Stream; +use crate::unit::Unit; use lazy_static::lazy_static; use std::collections::HashMap; use std::io::{Cursor, Write}; diff --git a/src/unit.rs b/src/unit.rs index 89cb559..8c980d6 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -1,9 +1,16 @@ -use crate::body::{send_body, Payload, SizedReader}; -use crate::stream::{connect_http, connect_https, connect_test, Stream}; -use base64; use std::io::{Result as IoResult, Write}; +use std::sync::{Arc, Mutex}; + +use base64; +use cookie::{Cookie, CookieJar}; +use qstring::QString; use url::Url; -// + +use crate::agent::AgentState; +use crate::body::{self, Payload, SizedReader}; +use crate::header; +use crate::stream::{self, connect_https, connect_test, Stream}; +use crate::{Error, Header, Request, Response}; use crate::pool::DEFAULT_HOST; @@ -26,7 +33,7 @@ pub(crate) struct Unit { impl Unit { // - fn new(req: &Request, url: &Url, mix_queries: bool, body: &SizedReader) -> Self { + pub(crate) fn new(req: &Request, url: &Url, mix_queries: bool, body: &SizedReader) -> Self { // let is_chunked = req @@ -96,15 +103,15 @@ impl Unit { #[cfg(test)] pub fn header<'a>(&self, name: &'a str) -> Option<&str> { - get_header(&self.headers, name) + header::get_header(&self.headers, name) } #[cfg(test)] pub fn has<'a>(&self, name: &'a str) -> bool { - has_header(&self.headers, name) + header::has_header(&self.headers, name) } #[cfg(test)] pub fn all<'a>(&self, name: &'a str) -> Vec<&str> { - get_all_headers(&self.headers, name) + header::get_all_headers(&self.headers, name) } } @@ -136,7 +143,7 @@ pub(crate) fn connect( } // send the body (which can be empty now depending on redirects) - send_body(body, unit.is_chunked, &mut stream)?; + body::send_body(body, unit.is_chunked, &mut stream)?; // start reading the response to process cookies and redirects. let mut resp = Response::from_read(&mut stream); @@ -182,7 +189,7 @@ pub(crate) fn connect( // since it is not a redirect, or we're not following redirects, // give away the incoming stream to the response object - response::set_stream(&mut resp, unit.url.to_string(), Some(unit), stream); + crate::response::set_stream(&mut resp, unit.url.to_string(), Some(unit), stream); // release the response Ok(resp) @@ -219,7 +226,7 @@ fn match_cookies<'a>(jar: &'a CookieJar, domain: &str, path: &str, is_secure: bo } /// Combine the query of the url and the query options set on the request object. -fn combine_query(url: &Url, query: &QString, mix_queries: bool) -> String { +pub(crate) fn combine_query(url: &Url, query: &QString, mix_queries: bool) -> String { match (url.query(), !query.is_empty() && mix_queries) { (Some(urlq), true) => format!("?{}&{}", urlq, query), (Some(urlq), false) => format!("?{}", urlq), @@ -239,7 +246,7 @@ fn connect_socket(unit: &Unit, use_pooled: bool) -> Result<(Stream, bool), Error } } let stream = match unit.url.scheme() { - "http" => connect_http(&unit), + "http" => stream::connect_http(&unit), "https" => connect_https(&unit), "test" => connect_test(&unit), _ => Err(Error::UnknownScheme(unit.url.scheme().to_string())), @@ -264,13 +271,13 @@ fn send_prelude(unit: &Unit, stream: &mut Stream, redir: bool) -> IoResult<()> { )?; // host header if not set by user. - if !has_header(&unit.headers, "host") { + if !header::has_header(&unit.headers, "host") { write!(prelude, "Host: {}\r\n", unit.url.host().unwrap())?; } - if !has_header(&unit.headers, "user-agent") { + if !header::has_header(&unit.headers, "user-agent") { write!(prelude, "User-Agent: ureq\r\n")?; } - if !has_header(&unit.headers, "accept") { + if !header::has_header(&unit.headers, "accept") { write!(prelude, "Accept: */*\r\n")?; }