diff --git a/.gitignore b/.gitignore index 5927861..d2a3924 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /pkg/ /tmp/ /target/ +/btls-extension-order-validation/ *.bundle *.so Gemfile.lock diff --git a/Cargo.lock b/Cargo.lock index 60036d0..c00c22f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "aho-corasick" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" dependencies = [ "memchr", ] @@ -32,12 +32,6 @@ dependencies = [ "alloc-no-stdlib", ] -[[package]] -name = "allocator-api2" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" - [[package]] name = "arc-swap" version = "1.9.2" @@ -49,9 +43,9 @@ dependencies = [ [[package]] name = "async-compression" -version = "0.4.42" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79b3f8a79cccc2898f31920fc69f304859b3bd567490f75ebf51ae1c792a9ac" +checksum = "3976abdc8fe7d1133d43d304afd42abdf5bc3e1319d263d223bde07b5efc4be8" dependencies = [ "compression-codecs", "compression-core", @@ -83,6 +77,23 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "bindgen" +version = "0.73.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "787ef8ef523575546b106a58213d6e6b06198a05c2f757258c68a74273670cfa" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex 2.0.1", + "syn 2.0.119", +] + [[package]] name = "bitflags" version = "2.13.1" @@ -113,8 +124,7 @@ dependencies = [ [[package]] name = "btls" version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c5e60b8c8d282c86360cab651ded04ab0335a7b5390c8d34145cbeab8cacf5f" +source = "git+https://github.com/0x676e67/btls?rev=5ec1c113a03626a5877b34dd6d2ea8d440897a91#5ec1c113a03626a5877b34dd6d2ea8d440897a91" dependencies = [ "bitflags", "btls-sys", @@ -126,15 +136,20 @@ dependencies = [ [[package]] name = "btls-sys" version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b1b8638a2e1c38a5ae4efa90ae57e643baec35a30d03fc5b399b893adc4954b" +source = "git+https://github.com/0x676e67/btls?rev=5ec1c113a03626a5877b34dd6d2ea8d440897a91#5ec1c113a03626a5877b34dd6d2ea8d440897a91" dependencies = [ - "bindgen", + "bindgen 0.73.2", "cmake", "fs_extra", "fslock", ] +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + [[package]] name = "bytes" version = "1.12.1" @@ -143,9 +158,9 @@ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" [[package]] name = "cc" -version = "1.4.0" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5add81bb678e6cb321aff7fa0dc7689ad82b112dbc032cea19f91d6b8e3582b9" +checksum = "509591b7bcd67f4ef775afad7662703b4935daaa6ec0e5605cfb1090b32a2b6d" dependencies = [ "find-msvc-tools", "jobserver", @@ -168,11 +183,37 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures", + "rand_core", +] + +[[package]] +name = "chromium-roots" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229b200495e6cf4d4b599a1884c30f5af57898604e6c0bd94a217295c0d1df69" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "clang-sys" -version = "1.8.1" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a" dependencies = [ "glob", "libc", @@ -218,6 +259,15 @@ dependencies = [ "version_check", ] +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.5.0" @@ -234,14 +284,52 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" [[package]] -name = "displaydoc" -version = "0.2.6" +name = "derive-deftly" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "724949bdda5310709ca2f97bf69c2b01e3362f44fef1fb47913445db4c1debb5" +dependencies = [ + "derive-deftly-macros", +] + +[[package]] +name = "derive-deftly-macros" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ac70aa55017e108007fbaf5aa0f54b021c98f92ff8af59d42eda9da96e3dd4f" +checksum = "17933e749f2502cfcd1c27519292fbbea22e8fc64ce680e863f855e8cd8cce23" dependencies = [ + "indexmap", + "itertools", + "proc-macro-crate", "proc-macro2", "quote", + "strum", "syn 2.0.119", + "unicode-ident", + "void", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "educe" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e451fac8dd8dece16234604bf1efce6e90fddd8ab6ad4d66eec0eca5160959dd" +dependencies = [ + "enum-ordinalize", + "proc-macro2", + "quote", + "syn 3.0.3", ] [[package]] @@ -259,6 +347,26 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "enum-ordinalize" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89dd01549b09589510cf0647475075d12071456586d70f5c75c98ae2a5537677" +dependencies = [ + "enum-ordinalize-derive", +] + +[[package]] +name = "enum-ordinalize-derive" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a65863d15a4ce2888bd2f0f543cc963d3879c3a022c8ee43f6141d479a3ac815" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + [[package]] name = "equivalent" version = "1.0.2" @@ -275,11 +383,17 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + [[package]] name = "find-msvc-tools" -version = "0.1.9" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" +checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890" [[package]] name = "flate2" @@ -366,9 +480,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.33" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "262590f4fe6afeb0bc83be1daa64e52657fe185690a958af7f3ad0e92085c5ae" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" dependencies = [ "futures-core", ] @@ -379,11 +493,17 @@ version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + [[package]] name = "futures-sink" -version = "0.3.33" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e34418ac499d6305c2fb5ad0ed2f6ac998c5f8ca209b4510f7f94242c647e307" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" [[package]] name = "futures-task" @@ -398,7 +518,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" dependencies = [ "futures-core", + "futures-io", "futures-task", + "memchr", "pin-project-lite", "slab", ] @@ -410,8 +532,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" dependencies = [ "cfg-if", + "js-sys", "libc", "r-efi", + "rand_core", + "wasm-bindgen", ] [[package]] @@ -426,11 +551,15 @@ version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" dependencies = [ - "allocator-api2", - "equivalent", "foldhash", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "http" version = "1.5.0" @@ -467,8 +596,7 @@ dependencies = [ [[package]] name = "http2" version = "0.5.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d3114be2f413b2e491e686b93a28cda30c355cffc8d091a57f8be4b1342896" +source = "git+https://github.com/0x676e67/http2?rev=ce505e52ce9c25fb055412cb39b1caaa7a1f70a8#ce505e52ce9c25fb055412cb39b1caaa7a1f70a8" dependencies = [ "atomic-waker", "bytes", @@ -483,6 +611,40 @@ dependencies = [ "tokio-util", ] +[[package]] +name = "http3" +version = "0.2.0" +source = "git+https://github.com/0x676e67/http3?rev=5bd394f3dfb8bc63591627a229c34c02caadc3af#5bd394f3dfb8bc63591627a229c34c02caadc3af" +dependencies = [ + "bytes", + "fastrand", + "futures-util", + "http", + "pin-project-lite", + "smallvec", + "tokio", +] + +[[package]] +name = "http3-datagram" +version = "0.2.0" +source = "git+https://github.com/0x676e67/http3?rev=5bd394f3dfb8bc63591627a229c34c02caadc3af#5bd394f3dfb8bc63591627a229c34c02caadc3af" +dependencies = [ + "bytes", + "http3", +] + +[[package]] +name = "http3-quic" +version = "0.2.0" +source = "git+https://github.com/0x676e67/http3?rev=5bd394f3dfb8bc63591627a229c34c02caadc3af#5bd394f3dfb8bc63591627a229c34c02caadc3af" +dependencies = [ + "bytes", + "futures-util", + "http3", + "quic", +] + [[package]] name = "httparse" version = "1.10.1" @@ -491,9 +653,9 @@ checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" [[package]] name = "icu_collections" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" +checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" dependencies = [ "displaydoc", "potential_utf", @@ -505,9 +667,9 @@ dependencies = [ [[package]] name = "icu_locale_core" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" dependencies = [ "displaydoc", "litemap", @@ -518,9 +680,9 @@ dependencies = [ [[package]] name = "icu_normalizer" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" +checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" dependencies = [ "icu_collections", "icu_normalizer_data", @@ -532,16 +694,17 @@ dependencies = [ [[package]] name = "icu_normalizer_data" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" +checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" [[package]] name = "icu_properties" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" +checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" dependencies = [ + "displaydoc", "icu_collections", "icu_locale_core", "icu_properties_data", @@ -552,15 +715,15 @@ dependencies = [ [[package]] name = "icu_properties_data" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" +checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" [[package]] name = "icu_provider" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +checksum = "92a7ed671a6aad807a8651a2e1782a6598fda9ce5185dd8158549e95a91c6428" dependencies = [ "displaydoc", "icu_locale_core", @@ -606,9 +769,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.12.0" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" +checksum = "6a756c3fac73139e83f14c2d742155dd2b78d3ee56597b419a0579b7bdd6dd78" [[package]] name = "itertools" @@ -635,6 +798,17 @@ dependencies = [ "libc", ] +[[package]] +name = "js-sys" +version = "0.3.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -659,9 +833,9 @@ dependencies = [ [[package]] name = "litemap" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" [[package]] name = "lock_api" @@ -674,13 +848,19 @@ dependencies = [ [[package]] name = "lru" -version = "0.18.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6180140927ee907000b0aa540091f6ea512ead4447c92b8fc35bc72788a5a6" +checksum = "4a9f71e3591c7ec44d3e563e87bf14ddc2bada8519dca046e5b0e560cd004e2d" dependencies = [ "hashbrown", ] +[[package]] +name = "lru-slab" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4050469837a6ff301cd14c1f8f24f88549e6d548f24f64e2148eb0f72cebc51f" + [[package]] name = "magnus" version = "0.9.2" @@ -744,6 +924,30 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "netty" +version = "0.2.5" +source = "git+https://github.com/0x676e67/netty?rev=0e1e53c0d9e500b253361cf6997559c44d7717b5#0e1e53c0d9e500b253361cf6997559c44d7717b5" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "http-body-util", + "http2", + "http3", + "http3-datagram", + "httparse", + "pin-project-lite", + "smallvec", + "tokio", + "tokio-socks", + "tokio-util", + "tower-service", + "want", +] + [[package]] name = "nom" version = "7.1.3" @@ -760,6 +964,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + [[package]] name = "openssl-macros" version = "0.1.1" @@ -808,15 +1018,15 @@ checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pkg-config" -version = "0.3.33" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" [[package]] name = "potential_utf" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" dependencies = [ "zerovec", ] @@ -827,6 +1037,15 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +[[package]] +name = "proc-macro-crate" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" +dependencies = [ + "toml_edit", +] + [[package]] name = "proc-macro2" version = "1.0.107" @@ -836,6 +1055,62 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quic" +version = "0.12.2" +source = "git+https://github.com/0x676e67/quic?rev=b3d74044e874c5e785f462e3032faaf021cb6958#b3d74044e874c5e785f462e3032faaf021cb6958" +dependencies = [ + "bytes", + "cfg_aliases", + "futures-io", + "libc", + "pin-project-lite", + "quic-proto", + "quinn-udp", + "rustc-hash", + "socket2", + "thiserror 2.0.21", + "tokio", + "tracing", + "web-time", + "windows-sys", +] + +[[package]] +name = "quic-proto" +version = "0.12.2" +source = "git+https://github.com/0x676e67/quic?rev=b3d74044e874c5e785f462e3032faaf021cb6958#b3d74044e874c5e785f462e3032faaf021cb6958" +dependencies = [ + "btls", + "bytes", + "getrandom", + "lru", + "lru-slab", + "rand", + "rand_pcg", + "rustc-hash", + "rustls-pki-types", + "slab", + "thiserror 2.0.21", + "tinyvec", + "tracing", + "web-time", + "zeroize", +] + +[[package]] +name = "quinn-udp" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47091c86514c2e11452cb228dee77037334b99d92a23e4c69aa5982261f39247" +dependencies = [ + "cfg_aliases", + "libc", + "socket2", + "tracing", + "windows-sys", +] + [[package]] name = "quote" version = "1.0.47" @@ -851,6 +1126,32 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "rand" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" +dependencies = [ + "chacha20", + "getrandom", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core", +] + [[package]] name = "rb-sys" version = "0.9.130" @@ -866,7 +1167,7 @@ version = "0.9.130" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05be6f9c86fe5482808162826f6c047d093b3670582296c770de1d94f8066694" dependencies = [ - "bindgen", + "bindgen 0.72.1", "lazy_static", "proc-macro2", "quote", @@ -904,9 +1205,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.16" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fcfdb36bda0c880c5931cdc7a2bcdc8ba4556847b9d912bca70bc94708711ad" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" dependencies = [ "aho-corasick", "memchr", @@ -930,6 +1231,10 @@ name = "rustls-pki-types" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "web-time", + "zeroize", +] [[package]] name = "rustversion" @@ -1089,6 +1394,27 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" +[[package]] +name = "strum" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "syn" version = "2.0.119" @@ -1137,7 +1463,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" +dependencies = [ + "thiserror-impl 2.0.21", ] [[package]] @@ -1151,11 +1486,22 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "thiserror-impl" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + [[package]] name = "time" -version = "0.3.54" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e1d5e639ff6bab73cb6885cc7e7b1de96c3f32c68ec55f3952614bec1092244" +checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134" dependencies = [ "deranged", "num-conv", @@ -1183,14 +1529,20 @@ dependencies = [ [[package]] name = "tinystr" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" dependencies = [ "displaydoc", "zerovec", ] +[[package]] +name = "tinyvec" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" + [[package]] name = "tokio" version = "1.53.2" @@ -1211,22 +1563,22 @@ dependencies = [ [[package]] name = "tokio-btls" version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e1fd638ec35427faf3b8f412e0fdd6fae76591d79dba40f38fa667d22bc44dd" +source = "git+https://github.com/0x676e67/btls?rev=5ec1c113a03626a5877b34dd6d2ea8d440897a91#5ec1c113a03626a5877b34dd6d2ea8d440897a91" dependencies = [ "btls", + "btls-sys", "tokio", ] [[package]] name = "tokio-macros" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6328af13490e73a9b4694030fafd93f8c8c6a9dede33e821c3fc63eddf8042ba" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.119", + "syn 3.0.3", ] [[package]] @@ -1237,8 +1589,7 @@ checksum = "a7e2948f60dbe26b35f2c7fb74ac2854c1fddded0fe9d7548fcc674a246f7615" dependencies = [ "either", "futures-util", - "thiserror", - "tokio", + "thiserror 1.0.69", ] [[package]] @@ -1255,6 +1606,36 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml_datetime" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_edit" +version = "0.25.19+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd43688c4858d7264ae1cf9a9f874a67c3feb74a883b1cd7bebd6a4ea8307218" +dependencies = [ + "indexmap", + "toml_datetime", + "toml_parser", + "winnow", +] + +[[package]] +name = "toml_parser" +version = "1.1.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c" +dependencies = [ + "winnow", +] + [[package]] name = "tower" version = "0.5.3" @@ -1272,9 +1653,9 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.6.11" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +checksum = "08a05a66a4fdd61cbbe0a1d755ffe0ca6aba159dd4820936a0ff8a8278245b9c" dependencies = [ "async-compression", "bitflags", @@ -1283,6 +1664,7 @@ dependencies = [ "http", "http-body", "http-body-util", + "percent-encoding", "pin-project-lite", "tokio", "tokio-util", @@ -1302,6 +1684,25 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + [[package]] name = "try-lock" version = "0.2.5" @@ -1358,6 +1759,12 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + [[package]] name = "want" version = "0.3.1" @@ -1374,12 +1781,57 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] -name = "webpki-root-certs" -version = "1.0.9" +name = "wasm-bindgen" +version = "0.2.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b96554aa2acc8ccdb7e1c9a58a7a68dd5d13bccc69cd124cb09406db612a1c9b" +checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c" dependencies = [ - "rustls-pki-types", + "cfg-if", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.3", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", ] [[package]] @@ -1420,28 +1872,41 @@ dependencies = [ ] [[package]] -name = "wreq" -version = "6.0.0-rc.29" +name = "winnow" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f0eba5f5814a94e5f1a99156f187133464e525b66bdbc69a9627d46530af2e1" +checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef" +dependencies = [ + "memchr", +] + +[[package]] +name = "wreq" +version = "0.16.1" +source = "git+https://github.com/0x676e67/wreq?rev=18d500474139c6740c841d3263f82a7eb1ac4883#18d500474139c6740c841d3263f82a7eb1ac4883" dependencies = [ "btls", "btls-sys", "bytes", + "chromium-roots", "cookie", + "derive-deftly", + "educe", "encoding_rs", "futures-util", "http", "http-body", "http-body-util", "http2", - "httparse", + "http3-quic", "ipnet", "libc", "lru", "mime", + "netty", "percent-encoding", "pin-project-lite", + "quic", "serde", "serde_html_form", "serde_json", @@ -1449,50 +1914,15 @@ dependencies = [ "sync_wrapper", "tokio", "tokio-btls", - "tokio-socks", "tokio-util", "tower", "tower-http", "url", - "webpki-root-certs", - "wreq-proto", - "wreq-rt", -] - -[[package]] -name = "wreq-proto" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a43942f024bb303f1042c9aa3c87fa1d9149f507c65db6e5220a11ccdb207387" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http", - "http-body", - "http2", - "httparse", - "pin-project-lite", - "smallvec", - "tokio", - "tokio-util", - "want", -] - -[[package]] -name = "wreq-rt" -version = "0.2.2-rc.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e9bce67a3fa3dd3f1503f066d86661c9caf399a763d3bd184da7afaf886c8b" -dependencies = [ - "pin-project-lite", - "tokio", - "wreq-proto", ] [[package]] name = "wreq-ruby" -version = "1.2.4" +version = "1.3.5" dependencies = [ "arc-swap", "bytes", @@ -1517,10 +1947,9 @@ dependencies = [ [[package]] name = "wreq-util" version = "3.0.0-rc.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d8d73c75be86fbde675988dbe5cb15f02567025c13f6ffab910361ad1ba6c89" dependencies = [ "brotli", + "chromium-roots", "flate2", "typed-builder", "wreq", @@ -1529,9 +1958,9 @@ dependencies = [ [[package]] name = "writeable" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" [[package]] name = "yoke" @@ -1577,11 +2006,17 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zeroize" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" + [[package]] name = "zerotrie" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" dependencies = [ "displaydoc", "yoke", @@ -1590,9 +2025,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.6" +version = "0.11.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +checksum = "94b5c6b5976d66c1d703c4fd17d3f5e43c8cedaacf604961b171adc7130896d8" dependencies = [ "yoke", "zerofrom", @@ -1601,13 +2036,13 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.11.3" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +checksum = "47402523226a02bfe5230160dc3ccc089aa6f6f19e7fcbb4e6f824bbb1b4aa62" dependencies = [ "proc-macro2", "quote", - "syn 2.0.119", + "syn 3.0.3", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 56cf489..f1599b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,8 @@ authors = ["SearchApi "] homepage = "https://github.com/SearchApi/wreq-ruby" repository = "https://github.com/SearchApi/wreq-ruby" edition = "2024" -rust-version = "1.97" -version = "1.2.4" +version = "1.3.5" +rust-version = "1.98" [lib] crate-type = ["cdylib"] @@ -17,7 +17,12 @@ name = "wreq_ruby" magnus = { version = "0.9.0", features = ["bytes"] } rb-sys = { version = "0.9.128", default-features = false } tokio = { version = "1.53.1", features = ["full"] } -wreq = { version = "6.0.0-rc", features = [ +# Keep the existing trust store independent of wreq's default feature selection. +wreq = { version = "0.16.1", default-features = false, features = [ + "tokio-rt", + "http2", + "http3", + "chromium-roots", "query", "form", "json", @@ -62,3 +67,17 @@ incremental = false lto = "fat" opt-level = 3 strip = true + +[patch.crates-io] +# Keep transport patches aligned with wreq's demo/brave-galileo-ac7w3r branch. +http2 = { git = "https://github.com/0x676e67/http2", rev = "ce505e52ce9c25fb055412cb39b1caaa7a1f70a8" } +http3 = { git = "https://github.com/0x676e67/http3", rev = "5bd394f3dfb8bc63591627a229c34c02caadc3af" } +http3-datagram = { git = "https://github.com/0x676e67/http3", rev = "5bd394f3dfb8bc63591627a229c34c02caadc3af" } +http3-quic = { git = "https://github.com/0x676e67/http3", rev = "5bd394f3dfb8bc63591627a229c34c02caadc3af" } +quic = { git = "https://github.com/0x676e67/quic", rev = "b3d74044e874c5e785f462e3032faaf021cb6958" } +netty = { git = "https://github.com/0x676e67/netty", rev = "0e1e53c0d9e500b253361cf6997559c44d7717b5" } +btls = { git = "https://github.com/0x676e67/btls", rev = "5ec1c113a03626a5877b34dd6d2ea8d440897a91" } +btls-sys = { git = "https://github.com/0x676e67/btls", rev = "5ec1c113a03626a5877b34dd6d2ea8d440897a91" } +tokio-btls = { git = "https://github.com/0x676e67/btls", rev = "5ec1c113a03626a5877b34dd6d2ea8d440897a91" } +wreq = { git = "https://github.com/0x676e67/wreq", rev = "18d500474139c6740c841d3263f82a7eb1ac4883" } +wreq-util = { path = "crates/wreq-util" } diff --git a/README.md b/README.md index 422d8fb..67fd3b8 100644 --- a/README.md +++ b/README.md @@ -91,9 +91,9 @@ Most browser device models share identical TLS and HTTP/2 configurations, differ | **Browser** | **Versions** | | ----------- | ------------ | - | **Chrome** | `Chrome100`, `Chrome101`, `Chrome104`, `Chrome105`, `Chrome106`, `Chrome107`, `Chrome108`, `Chrome109`, `Chrome110`, `Chrome114`, `Chrome116`, `Chrome117`, `Chrome118`, `Chrome119`, `Chrome120`, `Chrome123`, `Chrome124`, `Chrome126`, `Chrome127`, `Chrome128`, `Chrome129`, `Chrome130`, `Chrome131`, `Chrome132`, `Chrome133`, `Chrome134`, `Chrome135`, `Chrome136`, `Chrome137`, `Chrome138`, `Chrome139`, `Chrome140`, `Chrome141`, `Chrome142`, `Chrome143`, `Chrome144`, `Chrome145`, `Chrome146`, `Chrome147`, `Chrome148`, `Chrome149` | + | **Chrome** | `Chrome100`, `Chrome101`, `Chrome104`, `Chrome105`, `Chrome106`, `Chrome107`, `Chrome108`, `Chrome109`, `Chrome110`, `Chrome114`, `Chrome116`, `Chrome117`, `Chrome118`, `Chrome119`, `Chrome120`, `Chrome123`, `Chrome124`, `Chrome126`, `Chrome127`, `Chrome128`, `Chrome129`, `Chrome130`, `Chrome131`, `Chrome132`, `Chrome133`, `Chrome134`, `Chrome135`, `Chrome136`, `Chrome137`, `Chrome138`, `Chrome139`, `Chrome140`, `Chrome141`, `Chrome142`, `Chrome143`, `Chrome144`, `Chrome145`, `Chrome146`, `Chrome147`, `Chrome148`, `Chrome149`, `Chrome150`, `Chrome151`, `Chrome152`, `Chrome153`, `Chrome154`, `Chrome155`, `Chrome156`, `Chrome157`, `Chrome158` | | **Edge** | `Edge101`, `Edge122`, `Edge127`, `Edge131`, `Edge134`, `Edge135`, `Edge136`, `Edge137`, `Edge138`, `Edge139`, `Edge140`, `Edge141`, `Edge142`, `Edge143`, `Edge144`, `Edge145`, `Edge146`, `Edge147`, `Edge148` | - | **Firefox** | `Firefox109`, `Firefox117`, `Firefox128`, `Firefox133`, `Firefox135`, `FirefoxPrivate135`, `FirefoxAndroid135`, `Firefox136`, `FirefoxPrivate136`, `Firefox139`, `Firefox142`, `Firefox143`, `Firefox144`, `Firefox145`, `Firefox146`, `Firefox147`, `Firefox148`, `Firefox149`, `Firefox150`, `Firefox151` | + | **Firefox** | `Firefox109`, `Firefox117`, `Firefox128`, `Firefox133`, `Firefox135`, `FirefoxPrivate135`, `FirefoxAndroid135`, `Firefox136`, `FirefoxPrivate136`, `Firefox139`, `Firefox142`, `Firefox143`, `Firefox144`, `Firefox145`, `Firefox146`, `Firefox147`, `Firefox148`, `Firefox149`, `Firefox150`, `Firefox151`, `Firefox152` | | **Safari** | `Safari15_3`, `Safari15_5`, `Safari15_6_1`, `Safari16`, `Safari16_5`, `Safari17_0`, `Safari17_2_1`, `Safari17_4_1`, `Safari17_5`, `Safari17_6`, `Safari18`, `Safari18_2`, `Safari18_3`, `Safari18_3_1`, `Safari18_5`, `Safari26`, `Safari26_1`, `Safari26_2`, `SafariIos16_5`, `SafariIos17_2`, `SafariIos17_4_1`, `SafariIos18_1_1`, `SafariIos26`, `SafariIos26_2`, `SafariIPad18`, `SafariIPad26`, `SafariIpad26_2` | | **OkHttp** | `Opera116`, `Opera117`, `Opera118`, `Opera119`, `Opera120`, `Opera121`, `Opera122`, `Opera123`, `Opera124`, `Opera125`, `Opera126`, `Opera127`, `Opera128`, `Opera129`, `Opera130` | | **Opera** | `Opera116`, `Opera117`, `Opera118`, `Opera119` | diff --git a/crates/README.md b/crates/README.md new file mode 100644 index 0000000..3181970 --- /dev/null +++ b/crates/README.md @@ -0,0 +1,5 @@ +# Local Rust dependencies + +- [`wreq-util`](wreq-util/) is a local copy of [0x676e67/wreq-util](https://github.com/0x676e67/wreq-util). The root [`Cargo.toml`](../Cargo.toml) resolves it from `crates/wreq-util` through `[patch.crates-io]`. + +When building or testing `wreq-util` on its own, use the Git dependency patches from the root manifest of the same branch. Cargo does not inherit those patches from the parent package. diff --git a/crates/wreq-util/.github/FUNDING.yml b/crates/wreq-util/.github/FUNDING.yml new file mode 100644 index 0000000..768ac2c --- /dev/null +++ b/crates/wreq-util/.github/FUNDING.yml @@ -0,0 +1,15 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +polar: # Replace with a single Polar username +buy_me_a_coffee: # Replace with a single Buy Me a Coffee username +thanks_dev: # Replace with a single thanks.dev username +custom: ['https://github.com/0x676e67/0x676e67/blob/main/SPONSOR.md'] diff --git a/crates/wreq-util/.github/ISSUE_TEMPLATE/bug_report.md b/crates/wreq-util/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/crates/wreq-util/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/crates/wreq-util/.github/ISSUE_TEMPLATE/custom.md b/crates/wreq-util/.github/ISSUE_TEMPLATE/custom.md new file mode 100644 index 0000000..48d5f81 --- /dev/null +++ b/crates/wreq-util/.github/ISSUE_TEMPLATE/custom.md @@ -0,0 +1,10 @@ +--- +name: Custom issue template +about: Describe this issue template's purpose here. +title: '' +labels: '' +assignees: '' + +--- + + diff --git a/crates/wreq-util/.github/ISSUE_TEMPLATE/feature_request.md b/crates/wreq-util/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/crates/wreq-util/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/crates/wreq-util/.github/dependabot.yml b/crates/wreq-util/.github/dependabot.yml new file mode 100644 index 0000000..9ffca92 --- /dev/null +++ b/crates/wreq-util/.github/dependabot.yml @@ -0,0 +1,22 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "github-actions" + # Workflow files stored in the + # default location of `.github/workflows` + directory: "/" + schedule: + interval: "weekly" + - package-ecosystem: "cargo" + directory: "/" + schedule: + interval: "weekly" + # todo: if only this worked, see https://github.com/dependabot/dependabot-core/issues/4009 + # only tell us if there's a new 'breaking' change we could upgrade to + # versioning-strategy: increase-if-necessary + # disable regular version updates, security updates are unaffected + open-pull-requests-limit: 0 diff --git a/crates/wreq-util/.github/workflows/ci.yml b/crates/wreq-util/.github/workflows/ci.yml new file mode 100644 index 0000000..55422c8 --- /dev/null +++ b/crates/wreq-util/.github/workflows/ci.yml @@ -0,0 +1,82 @@ +name: CI + +on: + push: + tags: ["v*"] + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + +permissions: + contents: write + packages: write + +jobs: + style: + name: Style + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Style check + run: cargo fmt --all -- --check + - name: Clippy check + run: cargo clippy --all-targets --all-features + + docs: + name: Docs + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Build docs + run: cargo doc --document-private-items --all-features + + tests: + name: Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - uses: taiki-e/install-action@v2 + with: + tool: cargo-nextest + - name: Tests + run: | + set -euxo pipefail + cargo nextest run --workspace + + linux: + name: Linux + needs: [style, tests, docs] + runs-on: ubuntu-latest + environment: Linux + if: startsWith(github.ref, 'refs/tags/') + steps: + - uses: actions/checkout@v7 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - uses: katyo/publish-crates@v2 + with: + registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} + ignore-unpublished-changes: true + - name: Upload binaries to GitHub Release + uses: softprops/action-gh-release@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }} + generate_release_notes: true diff --git a/crates/wreq-util/.github/workflows/release-plz.yml b/crates/wreq-util/.github/workflows/release-plz.yml new file mode 100644 index 0000000..fe58090 --- /dev/null +++ b/crates/wreq-util/.github/workflows/release-plz.yml @@ -0,0 +1,52 @@ +name: Release-plz + +on: + push: + branches: + - main + +jobs: + release-plz-release: + name: Release-plz release + runs-on: ubuntu-latest + if: ${{ github.repository_owner == '0x676e67' }} + permissions: + contents: write + id-token: write + steps: + - &checkout + name: Checkout repository + uses: actions/checkout@v7 + with: + fetch-depth: 0 + persist-credentials: true + token: ${{ secrets.RELEASE_PLZ_TOKEN }} + - &install-rust + name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + - name: Run release-plz + uses: release-plz/action@v0.5 + with: + command: release + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} + + release-plz-pr: + name: Release-plz PR + runs-on: ubuntu-latest + if: ${{ github.repository_owner == '0x676e67' }} + permissions: + pull-requests: write + contents: write + concurrency: + group: release-plz-${{ github.ref }} + cancel-in-progress: false + steps: + - *checkout + - *install-rust + - name: Run release-plz + uses: release-plz/action@v0.5 + with: + command: release-pr + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} diff --git a/crates/wreq-util/.gitignore b/crates/wreq-util/.gitignore new file mode 100644 index 0000000..6a82881 --- /dev/null +++ b/crates/wreq-util/.gitignore @@ -0,0 +1,24 @@ +# Generated by Cargo +# will have compiled files and executables +debug +target +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# Generated by cargo mutants +# Contains mutation testing data +**/mutants.out*/ + +# RustRover +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ +.vscode +.zed diff --git a/crates/wreq-util/CHANGELOG.md b/crates/wreq-util/CHANGELOG.md new file mode 100644 index 0000000..f91f599 --- /dev/null +++ b/crates/wreq-util/CHANGELOG.md @@ -0,0 +1,90 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +- *(emulate)* Add Chrome 151 profile. +- *(emulate)* Add Chrome 152 profile. +- *(emulate)* Add Chrome 153 profile. +- *(emulate)* Add Chrome 154 profile. +- *(emulate)* Add Chrome 155 profile, including the JPEG XL navigation Accept header. +- *(emulate)* Add Chrome 156 profile. +- *(emulate)* Add Firefox 152 profile. + +### Fixed + +- Match Trust Anchor ID ordering by Chrome version: randomized per native configuration for 152/153, and sorted by raw ID bytes for 154. + +- *(emulate)* Fix Firefox 150 and 151 cipher suite lists. + +## [3.0.0-rc.14](https://github.com/0x676e67/wreq-util/compare/v3.0.0-rc.13...v3.0.0-rc.14) - 2026-07-04 + +### Fixed + +- *(emulate)* Fix chrome accept header `q` value ([#101](https://github.com/0x676e67/wreq-util/pull/101)) + +### Other + +- *(deps)* bump actions/checkout from 6 to 7 ([#100](https://github.com/0x676e67/wreq-util/pull/100)) + +## [3.0.0-rc.13](https://github.com/0x676e67/wreq-util/compare/v3.0.0-rc.12...v3.0.0-rc.13) - 2026-06-19 + +### Added + +- add Emulation::weighted_random for traffic-weighted profile selection ([#97](https://github.com/0x676e67/wreq-util/pull/97)) + +### Other + +- Add Chrome 149 to emulation profiles ([#99](https://github.com/0x676e67/wreq-util/pull/99)) + +## [3.0.0-rc.12](https://github.com/0x676e67/wreq-util/compare/v3.0.0-rc.11...v3.0.0-rc.12) - 2026-06-03 + +### Added + +- *(emulate)* Add Firefox 150-151 ([#93](https://github.com/0x676e67/wreq-util/pull/93)) +- *(emulate)* Add Chrome/Edge 148,Opera 131,Safari 26-2/4 ([#92](https://github.com/0x676e67/wreq-util/pull/92)) +- *(emulate)* export enum variants ([#87](https://github.com/0x676e67/wreq-util/pull/87)) +- *(emulation)* add Chrome and Edge 146-147 ([#86](https://github.com/0x676e67/wreq-util/pull/86)) +- *(emulation)* add Opera 120-130 and Firefox 148-149 support ([#82](https://github.com/0x676e67/wreq-util/pull/82)) + +### Fixed + +- *(emulate)* fix HTTP2 configuration for OkHttp ([#94](https://github.com/0x676e67/wreq-util/pull/94)) +- fix build +- fix chrome grease value and brand order ([#91](https://github.com/0x676e67/wreq-util/pull/91)) +- fix + +### Other + +- Update Cargo.toml +- Update Cargo.toml +- Update README.md +- fix docs build ([#95](https://github.com/0x676e67/wreq-util/pull/95)) +- Update wreq and wreq-util versions in README +- release-plz.yml +- *(deps)* bump softprops/action-gh-release from 2 to 3 ([#89](https://github.com/0x676e67/wreq-util/pull/89)) +- Add Discord chat badge to README +- Add rustfmt configuration settings +- Update issue submission instructions in README +- Update Cargo.toml +- Update copyright year and owner in LICENSE file +- Revise contributing section and add FAQ +- Update Apache-2.0 +- export +- Update Cargo.toml +- update deps +- update +- *(macros)* fmt code ([#85](https://github.com/0x676e67/wreq-util/pull/85)) +- *(macros)* fmt code +- Fix variable naming in emulate.rs +- *(emulation)* refine abstraction for emulation settings ([#84](https://github.com/0x676e67/wreq-util/pull/84)) +- fmt +- Change 'Overview' header to 'Features' +- *(mod)* use `emulate` when applying `emulation` ([#83](https://github.com/0x676e67/wreq-util/pull/83)) +- Update `Contributing` section in `README.md` ([#81](https://github.com/0x676e67/wreq-util/pull/81)) diff --git a/crates/wreq-util/Cargo.toml b/crates/wreq-util/Cargo.toml new file mode 100644 index 0000000..b2436c6 --- /dev/null +++ b/crates/wreq-util/Cargo.toml @@ -0,0 +1,104 @@ +[package] +name = "wreq-util" +description = "Common utilities for wreq" +repository = "https://github.com/0x676e67/wreq-util" +documentation = "https://docs.rs/wreq-util" +keywords = ["http", "client", "emulation", "ja3", "ja4"] +authors = ["0x676e67 "] +version = "3.0.0-rc.14" +readme = "README.md" +license = "Apache-2.0" +edition = "2024" +rust-version = "1.98" + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] +targets = ["x86_64-unknown-linux-gnu"] + +[features] +default = ["emulation", "tokio-rt"] + +tokio-rt = ["wreq/tokio-rt"] +compio-rt = ["wreq/compio-rt"] + +emulation = [ + "wreq/http2", + "dep:typed-builder", + "dep:brotli", + "dep:flate2", + "dep:zstd", + "dep:chromium-roots", + "wreq/chromium-roots", +] +emulation-serde = ["dep:serde"] +emulation-compression = [] + +tower-delay = ["dep:tower", "dep:pin-project-lite", "tokio/time"] + +[dependencies] +wreq = { version = "0.16.1", default-features = false } + +# Optional deps... + +serde = { version = "1.0.228", features = ["derive"], optional = true } +tokio = { version = "1.52.1", default-features = false, optional = true } +tower = { version = "0.5.2", default-features = false, optional = true } +typed-builder = { version = "0.23.2", optional = true } +pin-project-lite = { version = "0.2.17", optional = true } +chromium-roots = { version = "0.1.1", optional = true } + +## Compression algorithms +brotli = { version = "8.0.2", optional = true } +flate2 = { version = "1.1.9", optional = true } +zstd = { version = "0.13.3", optional = true } + +[dev-dependencies] +wreq = "0.16.1" +serde_json = "1.0.151" +tokio = { version = "1.48.0", features = ["full"] } +hyper = { version = "1.10.1", default-features = false, features = [ + "http1", + "http2", + "server", +] } +hyper-util = { version = "0.1.20", features = [ + "http1", + "http2", + "server-auto", + "tokio", +] } +http = "1" + +[lib] +doctest = false + +[[test]] +name = "client" +path = "tests/client.rs" + +[[test]] +name = "emulate_chrome" +path = "tests/emulate_chrome.rs" + +[[test]] +name = "emulate_okhttp" +path = "tests/emulate_okhttp.rs" + +[[test]] +name = "emulate_firefox" +path = "tests/emulate_firefox.rs" + +[[test]] +name = "emulate_safari" +path = "tests/emulate_safari.rs" + +[[example]] +name = "emulate" +path = "examples/emulate.rs" +required-features = ["emulation"] + +[[example]] +name = "tower_delay" +path = "examples/tower_delay.rs" +required-features = ["tower-delay"] diff --git a/crates/wreq-util/LICENSE b/crates/wreq-util/LICENSE new file mode 100644 index 0000000..b94601a --- /dev/null +++ b/crates/wreq-util/LICENSE @@ -0,0 +1,201 @@ + 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 2026 0x676e67 + + 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. diff --git a/crates/wreq-util/README.md b/crates/wreq-util/README.md new file mode 100644 index 0000000..6afb1db --- /dev/null +++ b/crates/wreq-util/README.md @@ -0,0 +1,64 @@ +# wreq-util + +A collection of utilities to do common things with [wreq](https://github.com/0x676e67/wreq). + +[![Crates.io](https://img.shields.io/crates/v/wreq-util.svg?logo=rust)](https://crates.io/crates/wreq-util) +[![GitHub License](https://img.shields.io/github/license/0x676e67/wreq-util)](https://github.com/0x676e67/wreq-util/blob/main/LICENSE) +[![Discord chat][discord-badge]][discord-url] + +[discord-badge]: https://img.shields.io/discord/1486741856397164788.svg?logo=discord +[discord-url]: https://discord.gg/rfbvyFkgq3 + +See the [crate documentation](https://docs.rs/wreq-util/latest/wreq_util) for more details. + +## Features + +**wreq-util** offers a set of [tower](https://github.com/tower-rs/tower) middleware and utilities designed specifically for the [wreq](https://github.com/0x676e67/wreq) HTTP client: + +- **Emulation** various mainstream browsers (Chrome, Firefox, Safari, Opera, OkHttp) and their versions. +- **Delay/JitterDelay**: Add fixed or jittered delays to HTTP [request](https://docs.rs/http/latest/http/request/index.html) with customizable strategies and predicates. + +## Example + +This vendored copy uses the development wreq revision pinned in the [root Cargo.toml](../../Cargo.toml). Building it independently requires the same Git patches. + +The following example uses the [Tokio](https://tokio.rs) runtime with optional features enabled by adding this to your `Cargo.toml`: + +```toml +[dependencies] +tokio = { version = "1", features = ["full"] } +wreq = "0.16.1" +wreq-util = "3.0.0-rc" +``` + +And then the code: + +```rust +use wreq::Client; +use wreq_util::Emulation; + +#[tokio::main] +async fn main() -> wreq::Result<()> { + // Build a client + let client = Client::builder_tokio() + .emulation(Emulation::Chrome147) + .build()?; + + // Use the API you're already familiar with + let resp = client.get("https://pingly.us.kg/api/all").send().await?; + println!("{}", resp.text().await?); + Ok(()) +} +``` + +## License + +Licensed under either of Apache License, Version 2.0 ([LICENSE](./LICENSE) or http://www.apache.org/licenses/LICENSE-2.0). + +## 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) license, shall be licensed as above, without any additional terms or conditions. + +## FAQ + +**For all issues and feedback, please head over to the [wreq](https://github.com/0x676e67/wreq) repository.** diff --git a/crates/wreq-util/examples/emulate.rs b/crates/wreq-util/examples/emulate.rs new file mode 100644 index 0000000..7ff9094 --- /dev/null +++ b/crates/wreq-util/examples/emulate.rs @@ -0,0 +1,43 @@ +use wreq_util::{Emulation, Platform, Profile}; + +#[tokio::main] +async fn main() -> Result<(), wreq::Error> { + let client = wreq::Client::builder_tokio().build()?; + // Example 1: Basic emulation - Safari26 + let text = client + .get("https://pingly.us.kg/api/all") + .emulation(Emulation::Safari26) + .send() + .await? + .text() + .await?; + println!("{}\n", text); + + // Example 2: Advanced emulation with options - OkHttp5 + let text = client + .get("https://pingly.us.kg/api/all") + .emulation( + Emulation::builder() + .profile(Profile::OkHttp5) + .platform(Platform::Windows) + .http2(false) + .build(), + ) + .send() + .await? + .text() + .await?; + println!("{}\n", text); + + // Example 3: Random device emulation + let text = client + .get("https://pingly.us.kg/api/all") + .emulation(Emulation::random()) + .send() + .await? + .text() + .await?; + println!("{}", text); + + Ok(()) +} diff --git a/crates/wreq-util/examples/tower_delay.rs b/crates/wreq-util/examples/tower_delay.rs new file mode 100644 index 0000000..4fe67fd --- /dev/null +++ b/crates/wreq-util/examples/tower_delay.rs @@ -0,0 +1,191 @@ +use std::time::{Duration, Instant}; +use wreq::Client; +use wreq_util::tower::delay::{DelayLayer, JitterDelayLayer}; + +#[tokio::main] +async fn main() -> Result<(), wreq::Error> { + // Build a client with a 1 second delay between requests + let client = Client::builder_tokio() + .layer(DelayLayer::new(Duration::from_secs(1))) + .tls_cert_verification(false) + .build()?; + + let url = "https://httpbin.io/get"; + println!("Sending 3 requests to {} using DelayLayer(1s)", url); + + let mut prev_start = Instant::now(); + + for i in 1..=3 { + let start = Instant::now(); + let delta = start.duration_since(prev_start); + println!("Request #{}, start (+{:.3}s)", i, delta.as_secs_f64()); + + let _ = client.get(url).send().await?; + + println!( + "Request #{}, completed in {:.3}s", + i, + start.elapsed().as_secs_f64() + ); + + prev_start = start; + } + + // Example 1: Basic jittered delay for all requests + basic_jitter_delay().await?; + + println!("\n{}\n", "=".repeat(60)); + + // Example 2: Conditional jittered delay using `when` + conditional_jitter_delay().await?; + + println!("\n{}\n", "=".repeat(60)); + + // Example 3: Conditional fixed delay using `when` + conditional_fixed_delay().await?; + + Ok(()) +} + +/// Demonstrates basic jittered delay aplied to all requests. +async fn basic_jitter_delay() -> Result<(), wreq::Error> { + println!("=== Basic Jittered Delay ===\n"); + + // Build a client with jittered delay: base 1s ± 50% (range: 0.5s to 1.5s) + let client = Client::builder_tokio() + .layer(JitterDelayLayer::new(Duration::from_secs(1), 0.5)) + .tls_cert_verification(false) + .build()?; + + let url = "https://httpbin.io/get"; + println!( + "Sending 3 requests to {} using JitterDelayLayer(1s ± 50%)", + url + ); + println!("Expected delay range: [0.5s, 1.5s]\n"); + + let mut prev_start = Instant::now(); + + for i in 1..=3 { + let start = Instant::now(); + let delta = start.duration_since(prev_start); + + if i > 1 { + println!( + "Request #{}: delay since last = {:.3}s", + i, + delta.as_secs_f64() + ); + } else { + println!("Request #{}: starting...", i); + } + + let _ = client.get(url).send().await?; + + println!( + "Request #{}: completed in {:.3}s\n", + i, + start.elapsed().as_secs_f64() + ); + + prev_start = start; + } + + println!("Notice how the delays vary randomly within the [0.5s, 1.5s] range."); + + Ok(()) +} + +/// Demonstrates conditional jittered delay using `when` predicate. +async fn conditional_jitter_delay() -> Result<(), wreq::Error> { + println!("=== Conditional Jittered Delay (using `JitterDelayLayer::when`) ===\n"); + + let client = Client::builder_tokio() + .layer(JitterDelayLayer::new(Duration::from_millis(800), 0.3).when( + |req: &http::Request<_>| { + // Only apply delay to POST requests + req.method() == http::Method::POST + }, + )) + .tls_cert_verification(false) + .build()?; + + const BASE_URL: &str = "https://httpbin.io"; + + println!("POST requests will have jittered delay (800ms ± 30%)"); + println!("GET requests will pass through immediately\n"); + + // Send alternating GET and POST requests + for i in 1..=4 { + let start = Instant::now(); + + if i % 2 == 1 { + // GET request - no delay expected + let url = format!("{BASE_URL}/get"); + println!("Request #{}: GET {}", i, url); + let _ = client.get(&url).send().await?; + } else { + // POST request - delay expected + let url = format!("{BASE_URL}/post"); + println!("Request #{}: POST {}", i, url); + let _ = client.post(&url).send().await?; + } + + println!( + "Request #{}: completed in {:.3}s ({})\n", + i, + start.elapsed().as_secs_f64(), + if i % 2 == 1 { "no delay" } else { "with delay" } + ); + } + + println!("Notice: GET requests complete quickly, POST requests have ~800ms delay."); + + Ok(()) +} + +/// Demonstrates conditional fixed delay using `when` predicate. +async fn conditional_fixed_delay() -> Result<(), wreq::Error> { + println!("=== Conditional Fixed Delay (using `DelayLayer::when`) ===\n"); + + // Build a client that only delays requests to specific paths + let client = Client::builder_tokio() + .layer( + DelayLayer::new(Duration::from_secs(1)).when(|req: &http::Request<_>| { + // Only apply delay to /delay/* endpoints + req.uri().path().starts_with("/delay") + }), + ) + .tls_cert_verification(false) + .build()?; + + const BASE_URL: &str = "https://httpbin.io"; + + println!("Requests to /delay/* will have 1s fixed delay"); + println!("Other requests will pass through immediately\n"); + + // Test with different endpoints + let endpoints = ["/get", "/delay/0"]; + + for (i, endpoint) in endpoints.iter().enumerate() { + let url = format!("{BASE_URL}{endpoint}"); + let start = Instant::now(); + + println!("Request #{}: GET {}", i + 1, url); + let _ = client.get(&url).send().await?; + + let elapsed = start.elapsed().as_secs_f64(); + let has_delay = endpoint.starts_with("/delay"); + + println!( + "Request #{}: completed in {:.3}s ({})\n", + i + 1, + elapsed, + if has_delay { "with delay" } else { "no delay" } + ); + } + + println!("Notice: /get completes quickly, /delay/* has additional 1s delay."); + + Ok(()) +} diff --git a/crates/wreq-util/release-plz.toml b/crates/wreq-util/release-plz.toml new file mode 100644 index 0000000..395b352 --- /dev/null +++ b/crates/wreq-util/release-plz.toml @@ -0,0 +1,2 @@ +[workspace] +publish_features = ["tokio-rt"] \ No newline at end of file diff --git a/crates/wreq-util/rustfmt.toml b/crates/wreq-util/rustfmt.toml new file mode 100644 index 0000000..ae184a9 --- /dev/null +++ b/crates/wreq-util/rustfmt.toml @@ -0,0 +1,5 @@ +group_imports = "StdExternalCrate" +imports_granularity = "Crate" +reorder_imports = true +wrap_comments = true +comment_width = 100 diff --git a/crates/wreq-util/src/emulate.rs b/crates/wreq-util/src/emulate.rs new file mode 100644 index 0000000..f248c03 --- /dev/null +++ b/crates/wreq-util/src/emulate.rs @@ -0,0 +1,383 @@ +#[macro_use] +mod macros; +pub mod compress; +pub mod profile; + +use profile::{chrome::*, firefox::*, okhttp::*, opera::*, safari::*}; +#[cfg(feature = "emulation-serde")] +use serde::{Deserialize, Serialize}; +use typed_builder::TypedBuilder; + +define_enum!( + /// Selects which client profile the request should look like. + /// + /// This controls the built-in TLS, HTTP/2, and header presets used for the + /// request. Variants cover browser-style profiles as well as other clients, + /// such as OkHttp. + dispatch, + Profile, Chrome100, + Emulation, + + // Chrome versions + Chrome100 => ("chrome_100", v100::emulation), + Chrome101 => ("chrome_101", v101::emulation), + Chrome104 => ("chrome_104", v104::emulation), + Chrome105 => ("chrome_105", v105::emulation), + Chrome106 => ("chrome_106", v106::emulation), + Chrome107 => ("chrome_107", v107::emulation), + Chrome108 => ("chrome_108", v108::emulation), + Chrome109 => ("chrome_109", v109::emulation), + Chrome110 => ("chrome_110", v110::emulation), + Chrome114 => ("chrome_114", v114::emulation), + Chrome116 => ("chrome_116", v116::emulation), + Chrome117 => ("chrome_117", v117::emulation), + Chrome118 => ("chrome_118", v118::emulation), + Chrome119 => ("chrome_119", v119::emulation), + Chrome120 => ("chrome_120", v120::emulation), + Chrome123 => ("chrome_123", v123::emulation), + Chrome124 => ("chrome_124", v124::emulation), + Chrome126 => ("chrome_126", v126::emulation), + Chrome127 => ("chrome_127", v127::emulation), + Chrome128 => ("chrome_128", v128::emulation), + Chrome129 => ("chrome_129", v129::emulation), + Chrome130 => ("chrome_130", v130::emulation), + Chrome131 => ("chrome_131", v131::emulation), + Chrome132 => ("chrome_132", v132::emulation), + Chrome133 => ("chrome_133", v133::emulation), + Chrome134 => ("chrome_134", v134::emulation), + Chrome135 => ("chrome_135", v135::emulation), + Chrome136 => ("chrome_136", v136::emulation), + Chrome137 => ("chrome_137", v137::emulation), + Chrome138 => ("chrome_138", v138::emulation), + Chrome139 => ("chrome_139", v139::emulation), + Chrome140 => ("chrome_140", v140::emulation), + Chrome141 => ("chrome_141", v141::emulation), + Chrome142 => ("chrome_142", v142::emulation), + Chrome143 => ("chrome_143", v143::emulation), + Chrome144 => ("chrome_144", v144::emulation), + Chrome145 => ("chrome_145", v145::emulation), + Chrome146 => ("chrome_146", v146::emulation), + Chrome147 => ("chrome_147", v147::emulation), + Chrome148 => ("chrome_148", v148::emulation), + Chrome149 => ("chrome_149", v149::emulation), + Chrome150 => ("chrome_150", v150::emulation), + Chrome151 => ("chrome_151", v151::emulation), + Chrome152 => ("chrome_152", v152::emulation), + Chrome153 => ("chrome_153", v153::emulation), + Chrome154 => ("chrome_154", v154::emulation), + Chrome155 => ("chrome_155", v155::emulation), + Chrome156 => ("chrome_156", v156::emulation), + Chrome157 => ("chrome_157", v157::emulation), + Chrome158 => ("chrome_158", v158::emulation), + + // Edge versions + Edge101 => ("edge_101", edge101::emulation), + Edge122 => ("edge_122", edge122::emulation), + Edge127 => ("edge_127", edge127::emulation), + Edge131 => ("edge_131", edge131::emulation), + Edge134 => ("edge_134", edge134::emulation), + Edge135 => ("edge_135", edge135::emulation), + Edge136 => ("edge_136", edge136::emulation), + Edge137 => ("edge_137", edge137::emulation), + Edge138 => ("edge_138", edge138::emulation), + Edge139 => ("edge_139", edge139::emulation), + Edge140 => ("edge_140", edge140::emulation), + Edge141 => ("edge_141", edge141::emulation), + Edge142 => ("edge_142", edge142::emulation), + Edge143 => ("edge_143", edge143::emulation), + Edge144 => ("edge_144", edge144::emulation), + Edge145 => ("edge_145", edge145::emulation), + Edge146 => ("edge_146", edge146::emulation), + Edge147 => ("edge_147", edge147::emulation), + Edge148 => ("edge_148", edge148::emulation), + + // Opera versions + Opera116 => ("opera_116", opera116::emulation), + Opera117 => ("opera_117", opera117::emulation), + Opera118 => ("opera_118", opera118::emulation), + Opera119 => ("opera_119", opera119::emulation), + Opera120 => ("opera_120", opera120::emulation), + Opera121 => ("opera_121", opera121::emulation), + Opera122 => ("opera_122", opera122::emulation), + Opera123 => ("opera_123", opera123::emulation), + Opera124 => ("opera_124", opera124::emulation), + Opera125 => ("opera_125", opera125::emulation), + Opera126 => ("opera_126", opera126::emulation), + Opera127 => ("opera_127", opera127::emulation), + Opera128 => ("opera_128", opera128::emulation), + Opera129 => ("opera_129", opera129::emulation), + Opera130 => ("opera_130", opera130::emulation), + Opera131 => ("opera_131", opera131::emulation), + + // Firefox versions + Firefox109 => ("firefox_109", ff109::emulation), + Firefox117 => ("firefox_117", ff117::emulation), + Firefox128 => ("firefox_128", ff128::emulation), + Firefox133 => ("firefox_133", ff133::emulation), + Firefox135 => ("firefox_135", ff135::emulation), + FirefoxPrivate135 => ("firefox_private_135", ff_private_135::emulation), + FirefoxAndroid135 => ("firefox_android_135", ff_android_135::emulation), + Firefox136 => ("firefox_136", ff136::emulation), + FirefoxPrivate136 => ("firefox_private_136", ff_private_136::emulation), + Firefox139 => ("firefox_139", ff139::emulation), + Firefox142 => ("firefox_142", ff142::emulation), + Firefox143 => ("firefox_143", ff143::emulation), + Firefox144 => ("firefox_144", ff144::emulation), + Firefox145 => ("firefox_145", ff145::emulation), + Firefox146 => ("firefox_146", ff146::emulation), + Firefox147 => ("firefox_147", ff147::emulation), + Firefox148 => ("firefox_148", ff148::emulation), + Firefox149 => ("firefox_149", ff149::emulation), + Firefox150 => ("firefox_150", ff150::emulation), + Firefox151 => ("firefox_151", ff151::emulation), + Firefox152 => ("firefox_152", ff152::emulation), + + // Safari versions + SafariIos17_2 => ("safari_ios_17.2", safari_ios_17_2::emulation), + SafariIos17_4_1 => ("safari_ios_17.4.1", safari_ios_17_4_1::emulation), + SafariIos16_5 => ("safari_ios_16.5", safari_ios_16_5::emulation), + Safari15_3 => ("safari_15.3", safari15_3::emulation), + Safari15_5 => ("safari_15.5", safari15_5::emulation), + Safari15_6_1 => ("safari_15.6.1", safari15_6_1::emulation), + Safari16 => ("safari_16", safari16::emulation), + Safari16_5 => ("safari_16.5", safari16_5::emulation), + Safari17_0 => ("safari_17.0", safari17_0::emulation), + Safari17_2_1 => ("safari_17.2.1", safari17_2_1::emulation), + Safari17_4_1 => ("safari_17.4.1", safari17_4_1::emulation), + Safari17_5 => ("safari_17.5", safari17_5::emulation), + Safari17_6 => ("safari_17.6", safari17_6::emulation), + Safari18 => ("safari_18", safari18::emulation), + SafariIPad18 => ("safari_ipad_18", safari_ipad_18::emulation), + Safari18_2 => ("safari_18.2", safari18_2::emulation), + SafariIos18_1_1 => ("safari_ios_18.1.1", safari_ios_18_1_1::emulation), + Safari18_3 => ("safari_18.3", safari18_3::emulation), + Safari18_3_1 => ("safari_18.3.1", safari18_3_1::emulation), + Safari18_5 => ("safari_18.5", safari18_5::emulation), + Safari26 => ("safari_26", safari26::emulation), + Safari26_1 => ("safari_26.1", safari26_1::emulation), + Safari26_2 => ("safari_26.2", safari26_2::emulation), + Safari26_3 => ("safari_26.3", safari26_3::emulation), + Safari26_4 => ("safari_26.4", safari26_4::emulation), + SafariIPad26 => ("safari_ipad_26", safari_ipad_26::emulation), + SafariIpad26_2 => ("safari_ipad_26.2", safari_ipad_26_2::emulation), + SafariIos26 => ("safari_ios_26", safari_ios_26::emulation), + SafariIos26_2 => ("safari_ios_26.2", safari_ios_26_2::emulation), + + // OkHttp versions + OkHttp3_9 => ("okhttp_3.9", okhttp3_9::emulation), + OkHttp3_11 => ("okhttp_3.11", okhttp3_11::emulation), + OkHttp3_13 => ("okhttp_3.13", okhttp3_13::emulation), + OkHttp3_14 => ("okhttp_3.14", okhttp3_14::emulation), + OkHttp4_9 => ("okhttp_4.9", okhttp4_9::emulation), + OkHttp4_10 => ("okhttp_4.10", okhttp4_10::emulation), + OkHttp4_12 => ("okhttp_4.12", okhttp4_12::emulation), + OkHttp5 => ("okhttp_5", okhttp5::emulation) + +); + +impl wreq::IntoEmulation for Profile { + #[inline] + fn into_emulation(self) -> wreq::Emulation { + Emulation::builder().profile(self).build().into_emulation() + } +} + +define_enum!( + /// Selects which platform the client should look like. + /// + /// This mainly affects platform-specific headers and user-agent details. + /// In most cases you can keep the default unless you need to match a + /// specific Windows, macOS, Linux, Android, or iOS profile. + plain, + Platform, MacOS, + Windows => "windows", + MacOS => "macos", + Linux => "linux", + Android => "android", + IOS => "ios" +); + +impl Platform { + #[inline] + const fn platform(&self) -> &'static str { + match self { + Platform::MacOS => "\"macOS\"", + Platform::Linux => "\"Linux\"", + Platform::Windows => "\"Windows\"", + Platform::Android => "\"Android\"", + Platform::IOS => "\"iOS\"", + } + } + + #[inline] + const fn is_mobile(&self) -> bool { + matches!(self, Platform::Android | Platform::IOS) + } +} + +/// Represents the configuration options for emulating a client profile and platform. +/// +/// The `Emulation` struct allows you to configure various aspects of profile and platform +/// emulation, including the profile, platform, and whether to enable certain features +/// like HTTP/2 or headers. +/// +/// Conversion through [`wreq::IntoEmulation`] creates a native configuration, +/// including a randomized Trust Anchor ID order for Chrome 152/153 profiles. +/// Client-level emulation retains that order for subsequent connections. +/// Chrome 154–156 sort the IDs by their raw bytes instead. +#[derive(Default, Clone, TypedBuilder)] +pub struct Emulation { + /// Whether to change the profile (browser/okhttp) information. + #[builder(default)] + profile: Profile, + + /// Whether to change the platform (Windows/macOS/Linux/Android/iOS) information. + #[builder(default)] + platform: Platform, + + /// Whether to enable HTTP/2. + #[builder(default = true)] + http2: bool, + + /// Whether to include default headers. + #[builder(default = true)] + headers: bool, +} + +impl Emulation { + /// Returns a random variant of the `Profile` enum. + /// + /// # Examples + /// + /// ``` + /// use wreq_util::Emulation; + /// + /// let random_emulation = Emulation::random(); + /// println!("{:?}", random_emulation); + /// ``` + pub fn random() -> Emulation { + let rand = crate::rand::fast_random(); + Emulation::builder() + .profile(Profile::VARIANTS[(rand as usize) % Profile::VARIANTS.len()]) + .platform(Platform::VARIANTS[((rand >> 32) as usize) % Platform::VARIANTS.len()]) + .build() + } + + /// Returns a market-share weighted random `Emulation`. + /// + /// Unlike [`Emulation::random`], selection is biased toward popular browser + /// families and their most recent versions, and each profile is only paired + /// with platforms it ships on. + /// + /// Browser family and version weights are derived from StatCounter Global + /// Stats data retrieved in June 2026: + /// + /// Browser market share: + /// + /// + /// Browser version market share: + /// + /// + /// StatCounter requests attribution for use of its data. See: + /// + /// + /// # Examples + /// + /// ``` + /// use wreq_util::Emulation; + /// + /// let random_emulation = Emulation::weighted_random(); + /// println!("{:?}", random_emulation); + /// ``` + pub fn weighted_random() -> Emulation { + use Platform::*; + use Profile::*; + + struct Class { + weight: u32, + platforms: &'static [Platform], + profiles: &'static [Profile], + } + + // Weights based on StatCounter June 2026 data. + // + // Each weight is the family's share percentage multiplied by 100 and + // rounded to an integer (e.g. Chrome 71.41% -> 7141, Edge 5.02% -> 502, + // Firefox 2.35% -> 235, Opera 1.73% -> 173). Only relative magnitudes + // matter, so the common x100 scale is arbitrary but keeps two decimals + // of precision without floats. + // + // Safari's 14.77% is split by platform using the browser-version data: + // iPhone 11.96% + iPad 0.44% = 12.40% mobile (-> 1240), leaving the + // remaining 2.37% for desktop/macOS (-> 237). + const CLASSES: &[Class] = &[ + Class { + weight: 7141, + platforms: &[Windows, MacOS, Linux, Android], + profiles: &[ + Chrome149, Chrome148, Chrome147, Chrome146, Chrome145, Chrome144, Chrome143, + ], + }, + Class { + weight: 1240, + platforms: &[IOS], + profiles: &[ + SafariIos26_2, + SafariIos26, + SafariIpad26_2, + SafariIPad26, + SafariIos18_1_1, + SafariIPad18, + ], + }, + Class { + weight: 502, + platforms: &[Windows, MacOS], + profiles: &[Edge148, Edge147, Edge146, Edge145, Edge144, Edge143], + }, + Class { + weight: 237, + platforms: &[MacOS], + profiles: &[ + Safari26_4, Safari26_3, Safari26_2, Safari26_1, Safari26, Safari18_5, + ], + }, + Class { + weight: 235, + platforms: &[Windows, MacOS, Linux], + profiles: &[ + Firefox151, Firefox150, Firefox149, Firefox148, Firefox147, Firefox146, + ], + }, + Class { + weight: 173, + platforms: &[Windows, MacOS, Linux, Android], + profiles: &[Opera131, Opera130, Opera129, Opera128, Opera127, Opera126], + }, + ]; + + let (r1, r2) = (crate::rand::fast_random(), crate::rand::fast_random()); + let total: u32 = CLASSES.iter().map(|c| c.weight).sum(); + let mut t = (r1 % total as u64) as u32; + let class = CLASSES + .iter() + .find(|c| { + t = t.checked_sub(c.weight).unwrap_or(u32::MAX); + t == u32::MAX + }) + .unwrap_or(&CLASSES[0]); + let n = class.profiles.len(); + let idx = ((r1 >> 32) as usize % n).min((r2 >> 32) as usize % n); + Emulation::builder() + .profile(class.profiles[idx]) + .platform(class.platforms[(r2 as usize) % class.platforms.len()]) + .build() + } +} + +impl wreq::IntoEmulation for Emulation { + #[inline] + fn into_emulation(self) -> wreq::Emulation { + self.profile.match_emulation(self) + } +} diff --git a/crates/wreq-util/src/emulate/compress.rs b/crates/wreq-util/src/emulate/compress.rs new file mode 100644 index 0000000..c3373c3 --- /dev/null +++ b/crates/wreq-util/src/emulate/compress.rs @@ -0,0 +1,85 @@ +//! Compression algorithms for TLS 1.3 certificate compression. + +use brotli::{CompressorWriter as BrotliEncoder, Decompressor as BrotliDecoder}; +use flate2::{Compression, read::ZlibDecoder, write::ZlibEncoder}; +use std::io::{self, Write}; +use wreq::tls::compress::{CertificateCompressionAlgorithm, CertificateCompressor, Codec}; +use zstd::stream::{Decoder as ZstdDecoder, Encoder as ZstdEncoder}; + +#[derive(Debug)] +pub struct BrotliCompressor; + +#[derive(Debug)] +pub struct ZlibCompressor; + +#[derive(Debug)] +pub struct ZstdCompressor; + +impl CertificateCompressor for BrotliCompressor { + fn compress(&self) -> Codec { + Codec::Pointer(|input, output| { + let mut writer = BrotliEncoder::new(output, input.len(), 11, 32); + writer.write_all(input)?; + writer.flush()?; + Ok(()) + }) + } + + fn decompress(&self) -> Codec { + Codec::Pointer(|input, output| { + let mut reader = BrotliDecoder::new(input, 4096); + io::copy(&mut reader, output)?; + Ok(()) + }) + } + + fn algorithm(&self) -> CertificateCompressionAlgorithm { + CertificateCompressionAlgorithm::BROTLI + } +} + +impl CertificateCompressor for ZlibCompressor { + fn compress(&self) -> Codec { + Codec::Pointer(|input, output| { + let mut encoder = ZlibEncoder::new(output, Compression::default()); + encoder.write_all(input)?; + encoder.finish()?; + Ok(()) + }) + } + + fn decompress(&self) -> Codec { + Codec::Pointer(|input, output| { + let mut reader = ZlibDecoder::new(input); + io::copy(&mut reader, output)?; + Ok(()) + }) + } + + fn algorithm(&self) -> CertificateCompressionAlgorithm { + CertificateCompressionAlgorithm::ZLIB + } +} + +impl CertificateCompressor for ZstdCompressor { + fn compress(&self) -> Codec { + Codec::Pointer(|input, output| { + let mut encoder = ZstdEncoder::new(output, 0)?; + encoder.write_all(input)?; + encoder.finish()?; + Ok(()) + }) + } + + fn decompress(&self) -> Codec { + Codec::Pointer(|input, output| { + let mut reader = ZstdDecoder::new(input)?; + io::copy(&mut reader, output)?; + Ok(()) + }) + } + + fn algorithm(&self) -> CertificateCompressionAlgorithm { + CertificateCompressionAlgorithm::ZSTD + } +} diff --git a/crates/wreq-util/src/emulate/macros.rs b/crates/wreq-util/src/emulate/macros.rs new file mode 100644 index 0000000..56f4102 --- /dev/null +++ b/crates/wreq-util/src/emulate/macros.rs @@ -0,0 +1,373 @@ +macro_rules! define_enum { + ( + $(#[$meta:meta])* + dispatch, + $name:ident, $default_variant:ident, + $const_target:ident, + $( + $variant:ident => ($rename:expr, $emulation_fn:path) + ),* $(,)? + ) => { + $(#[$meta])* + #[non_exhaustive] + #[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)] + #[cfg_attr(feature = "emulation-serde", derive(Deserialize, Serialize))] + pub enum $name { + $( + #[cfg_attr(feature = "emulation-serde", serde(rename = $rename))] + $variant, + )* + } + + impl $name { + pub const VARIANTS: &[$name] = &[ + $( + $name::$variant, + )* + ]; + + pub fn match_emulation(self, opt: $const_target) -> wreq::Emulation { + match self { + $( + $name::$variant => $emulation_fn(opt), + )* + } + } + } + + impl Default for $name { + fn default() -> Self { + $name::$default_variant + } + } + + #[allow(non_upper_case_globals)] + impl $const_target { + $( + pub const $variant: $name = $name::$variant; + )* + } + }; + + ( + $(#[$meta:meta])* + plain, + $name:ident, $default_variant:ident, + $( + $variant:ident => $rename:expr + ),* $(,)? + ) => { + $(#[$meta])* + #[non_exhaustive] + #[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)] + #[cfg_attr(feature = "emulation-serde", derive(Deserialize, Serialize))] + pub enum $name { + $( + #[cfg_attr(feature = "emulation-serde", serde(rename = $rename))] + $variant, + )* + } + + impl $name { + pub const VARIANTS: &[$name] = &[ + $( + $name::$variant, + )* + ]; + } + + impl Default for $name { + fn default() -> Self { + $name::$default_variant + } + } + }; +} + +macro_rules! header_chrome_sec_ch_ua { + ($headers:expr, $ua:expr, $platform:expr, $is_mobile:expr) => { + let mobile = if $is_mobile { "?1" } else { "?0" }; + $headers.insert("sec-ch-ua", HeaderValue::from_static($ua)); + $headers.insert("sec-ch-ua-mobile", HeaderValue::from_static(mobile)); + $headers.insert("sec-ch-ua-platform", HeaderValue::from_static($platform)); + }; +} + +macro_rules! header_chrome_sec_fetch { + ($headers:expr) => { + $headers.insert("sec-fetch-site", HeaderValue::from_static("none")); + $headers.insert("sec-fetch-mode", HeaderValue::from_static("navigate")); + $headers.insert("sec-fetch-user", HeaderValue::from_static("?1")); + $headers.insert("sec-fetch-dest", HeaderValue::from_static("document")); + }; +} + +macro_rules! header_chrome_ua { + ($headers:expr, $ua:expr) => { + $headers.insert(USER_AGENT, HeaderValue::from_static($ua)); + }; +} + +macro_rules! header_chrome_accept { + ($headers:expr) => { + $headers.insert(ACCEPT, HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7")); + }; +} + +macro_rules! header_chrome_accept_encoding { + ($headers:expr) => { + #[cfg(feature = "emulation-compression")] + $headers.insert( + ACCEPT_ENCODING, + HeaderValue::from_static("gzip, deflate, br"), + ); + $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9")); + }; + (zstd, $headers:expr) => { + #[cfg(feature = "emulation-compression")] + $headers.insert( + ACCEPT_ENCODING, + HeaderValue::from_static("gzip, deflate, br, zstd"), + ); + $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9")); + }; + (zstd_only, $headers:expr) => { + #[cfg(feature = "emulation-compression")] + $headers.insert( + ACCEPT_ENCODING, + HeaderValue::from_static("gzip, deflate, br, zstd"), + ); + }; +} + +macro_rules! header_firefox_sec_fetch { + ($headers:expr) => { + $headers.insert("sec-fetch-dest", HeaderValue::from_static("document")); + $headers.insert("sec-fetch-mode", HeaderValue::from_static("navigate")); + $headers.insert("sec-fetch-site", HeaderValue::from_static("none")); + $headers.insert("sec-fetch-user", HeaderValue::from_static("?1")); + }; +} + +macro_rules! header_firefox_accept { + ($headers:expr) => { + header_firefox_accept!(@build $headers, "en-US,en;q=0.5", "gzip, deflate, br"); + }; + (zstd, $headers:expr) => { + header_firefox_accept!(@build $headers, "en-US,en;q=0.5", "gzip, deflate, br, zstd"); + }; + // Firefox 147 changed the generated q-value from dividing 1.0 across the list to + // decrementing by 0.1 per entry, so a two-entry list became q=0.9 (Bugzilla 2000765, + // landed in 0e050ae5116d). + (zstd_q09, $headers:expr) => { + header_firefox_accept!(@build $headers, "en-US,en;q=0.9", "gzip, deflate, br, zstd"); + }; + (@build $headers:expr, $accept_language:expr, $accept_encoding:expr) => { + $headers.insert( + ACCEPT, + HeaderValue::from_static( + "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + ), + ); + $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static($accept_language)); + #[cfg(feature = "emulation-compression")] + $headers.insert(ACCEPT_ENCODING, HeaderValue::from_static($accept_encoding)); + }; +} + +macro_rules! header_firefox_ua { + ($headers:expr, $ua:expr) => { + $headers.insert(USER_AGENT, HeaderValue::from_static($ua)); + }; +} + +macro_rules! join { + ($sep:expr, $first:expr $(, $rest:expr)*) => { + concat!($first $(, $sep, $rest)*) + }; +} + +macro_rules! standard_mod_generator { + ($mod_name:ident, $tls_options:expr, $http2_options:expr, $headers:expr) => { + pub(crate) mod $mod_name { + use super::*; + + #[inline] + pub fn emulation(emulation: Emulation) -> wreq::Emulation { + build_emulation(emulation.http2, ($headers)(&emulation)) + } + + pub fn build_emulation( + http2: bool, + default_headers: Option, + ) -> wreq::Emulation { + build_standard_emulation( + $tls_options, + http2.then(|| $http2_options), + default_headers, + ) + } + } + }; + ($mod_name:ident, $build_emulation:expr, $headers:expr) => { + pub(crate) mod $mod_name { + use super::*; + + #[inline] + pub fn emulation(emulation: Emulation) -> wreq::Emulation { + $build_emulation(emulation.http2, ($headers)(&emulation)) + } + } + }; +} + +macro_rules! fixed_headers { + ($emulation:expr, $header_initializer:ident, $ua:expr) => { + $emulation.headers.then(|| $header_initializer($ua)) + }; +} + +macro_rules! platform_headers { + ( + $emulation:expr, + $header_initializer:ident, + [($default_os:ident, $default_sec_ch_ua:tt, $default_ua:tt) $(, ($other_os:ident, $other_sec_ch_ua:tt, $other_ua:tt))*] + ) => {{ + #[allow(unreachable_patterns)] + $emulation.headers.then(|| { + match $emulation.platform { + $( + Platform::$other_os => $header_initializer( + $other_sec_ch_ua, + $other_ua, + $emulation.platform, + ), + )* + _ => $header_initializer( + $default_sec_ch_ua, + $default_ua, + Platform::$default_os, + ), + } + }) + }}; +} + +macro_rules! firefox_platform_headers { + ($emulation:expr, $header_initializer:ident, [($default_os:ident, $default_ua:tt) $(, ($other_os:ident, $other_ua:tt))*]) => {{ + #[allow(unreachable_patterns)] + $emulation.headers.then(|| { + match $emulation.platform { + $( + Platform::$other_os => $header_initializer($other_ua), + )* + _ => $header_initializer($default_ua), + } + }) + }}; +} + +macro_rules! mod_generator { + ( + $mod_name:ident, + $tls_options:expr, + $http2_options:expr, + $header_initializer:ident, + [($default_os:ident, $default_sec_ch_ua:tt, $default_ua:tt) $(, ($other_os:ident, $other_sec_ch_ua:tt, $other_ua:tt))*] + ) => { + standard_mod_generator!( + $mod_name, + $tls_options, + $http2_options, + |emulation: &Emulation| { + platform_headers!( + emulation, + $header_initializer, + [($default_os, $default_sec_ch_ua, $default_ua) $(, ($other_os, $other_sec_ch_ua, $other_ua))*] + ) + } + ); + }; + ( + $mod_name:ident, + $tls_options:expr, + $http2_options:expr, + $header_initializer:ident, + [($default_os:ident, $default_ua:tt) $(, ($other_os:ident, $other_ua:tt))*] + ) => { + standard_mod_generator!( + $mod_name, + $tls_options, + $http2_options, + |emulation: &Emulation| { + firefox_platform_headers!( + emulation, + $header_initializer, + [($default_os, $default_ua) $(, ($other_os, $other_ua))*] + ) + } + ); + }; + ( + $mod_name:ident, + $tls_options:expr, + $http2_options:expr, + $header_initializer:ident, + $ua:expr + ) => { + standard_mod_generator!( + $mod_name, + $tls_options, + $http2_options, + |emulation: &Emulation| fixed_headers!(emulation, $header_initializer, $ua) + ); + }; + ( + $mod_name:ident, + $build_emulation:expr, + $header_initializer:ident, + [($default_os:ident, $default_sec_ch_ua:tt, $default_ua:tt) $(, ($other_os:ident, $other_sec_ch_ua:tt, $other_ua:tt))*] + ) => { + standard_mod_generator!( + $mod_name, + $build_emulation, + |emulation: &Emulation| { + platform_headers!( + emulation, + $header_initializer, + [($default_os, $default_sec_ch_ua, $default_ua) $(, ($other_os, $other_sec_ch_ua, $other_ua))*] + ) + } + ); + }; + ( + $mod_name:ident, + $build_emulation:expr, + $header_initializer:ident, + [($default_os:ident, $default_ua:tt) $(, ($other_os:ident, $other_ua:tt))*] + ) => { + standard_mod_generator!( + $mod_name, + $build_emulation, + |emulation: &Emulation| { + firefox_platform_headers!( + emulation, + $header_initializer, + [($default_os, $default_ua) $(, ($other_os, $other_ua))*] + ) + } + ); + }; + ( + $mod_name:ident, + $build_emulation:expr, + $header_initializer:ident, + $ua:expr + ) => { + standard_mod_generator!( + $mod_name, + $build_emulation, + |emulation: &Emulation| fixed_headers!(emulation, $header_initializer, $ua) + ); + }; +} diff --git a/crates/wreq-util/src/emulate/profile.rs b/crates/wreq-util/src/emulate/profile.rs new file mode 100644 index 0000000..b0da064 --- /dev/null +++ b/crates/wreq-util/src/emulate/profile.rs @@ -0,0 +1,45 @@ +//! Emulation for different browsers. + +pub mod chrome; +pub mod firefox; +pub mod okhttp; +pub mod opera; +pub mod safari; + +use typed_builder::TypedBuilder; +#[cfg(feature = "emulation-compression")] +use wreq::header::ACCEPT_ENCODING; +use wreq::{ + header::{ACCEPT, ACCEPT_LANGUAGE, HeaderMap, HeaderName, HeaderValue, USER_AGENT}, + http2::{ + HeadersDependency, HeadersPriority, Http2Options, Priorities, Priority, PseudoId, + PseudoOrder, SettingId, SettingsOrder, StreamDependency, StreamId, + }, + tls::{ + AlpnProtocol, AlpsProtocol, EchGrease, EchGreaseAead, ExtensionType, KeyShare, Tls13Cipher, + TlsOptions, TlsVersion, compress::CertificateCompressor, + }, +}; + +use super::{ + Emulation, Platform, + compress::{BrotliCompressor, ZlibCompressor, ZstdCompressor}, +}; + +fn build_standard_emulation( + tls_options: TlsOptions, + http2_options: Option, + default_headers: Option, +) -> wreq::Emulation { + let mut builder = wreq::Emulation::builder().config(tls_options); + + if let Some(http2_options) = http2_options { + builder = builder.config(http2_options); + } + + if let Some(headers) = default_headers { + builder = builder.headers(headers); + } + + builder.build() +} diff --git a/crates/wreq-util/src/emulate/profile/chrome.rs b/crates/wreq-util/src/emulate/profile/chrome.rs new file mode 100644 index 0000000..de31e96 --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/chrome.rs @@ -0,0 +1,2304 @@ +#[macro_use] +mod http2; +#[macro_use] +mod tls; +mod header; + +use header::*; +use tls::*; + +use super::*; + +mod_generator!( + v100, + tls_options!(1), + http2_options!(1), + header_initializer, + [ + ( + MacOS, + r#""Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36" + ), + ( + Linux, + r#""Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100""#, + "Mozilla/5.0 (X11; U; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36" + ), + ( + Android, + r#""Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100""#, + "Mozilla/5.0 (X11; U; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36" + ), + ( + Windows, + r#""Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36" + ), + ( + IOS, + r#""Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 15_8 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/100.0.4896.85 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v101, + v100::build_emulation, + header_initializer, + [ + ( + MacOS, + r#""Not A;Brand";v="99", "Chromium";v="101", "Google Chrome";v="101""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36" + ), + ( + Linux, + r#""Not A;Brand";v="99", "Chromium";v="101", "Google Chrome";v="101""#, + "Mozilla/5.0 (X11; U; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36" + ), + ( + Android, + r#""Not A;Brand";v="99", "Chromium";v="101", "Google Chrome";v="101""#, + "Mozilla/5.0 (X11; U; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36" + ), + ( + Windows, + r#""Not A;Brand";v="99", "Chromium";v="101", "Google Chrome";v="101""#, + "Mozilla/5.0 (X11; U; Windows x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36" + ), + ( + IOS, + r#""Not A;Brand";v="99", "Chromium";v="101", "Google Chrome";v="101""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/101.0.4951.58 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + edge101, + v100::build_emulation, + header_initializer, + [ + ( + MacOS, + r#""Not A;Brand";v="99", "Chromium";v="101", "Microsoft Edge";v="101""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.47" + ), + ( + Android, + r#""Not A;Brand";v="99", "Chromium";v="101", "Microsoft Edge";v="101""#, + "Mozilla/5.0 (Linux; Android 10; ONEPLUS A6003) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36 Edg/101.0.1210.31" + ), + ( + Windows, + r#""Not A;Brand";v="99", "Chromium";v="101", "Microsoft Edge";v="101""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.53" + ), + // This shouldn't exist, edge was never meant to be on linux, + // but I found some UAs in myip.ms (same for 122, 127 and 131) + ( + Linux, + r#""Not A;Brand";v="99", "Chromium";v="101", "Microsoft Edge";v="101""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.53" + ), + ( + IOS, + r#""Not A;Brand";v="99", "Chromium";v="101", "Microsoft Edge";v="101""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/101.0.4951.64 Mobile Safari/537.36 Edg/101.0.1210.53" + ) + ] +); + +mod_generator!( + v104, + v100::build_emulation, + header_initializer, + [ + ( + MacOS, + r#""Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104""#, + "Mozilla/5.0 (X11; U; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104""#, + "Mozilla/5.0 (X11; U; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104""#, + "Mozilla/5.0 (X11; U; Windows x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 16_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/104.0.5112.99 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v105, + tls_options!(2), + http2_options!(1), + header_initializer, + [ + ( + MacOS, + r#""Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105""#, + "Mozilla/5.0 (X11; U; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105""#, + "Mozilla/5.0 (X11; U; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105""#, + "Mozilla/5.0 (X11; U; Windows x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 16_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/105.0.5195.100 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v106, + tls_options!(3), + http2_options!(2), + header_initializer, + [ + ( + MacOS, + r#""Chromium";v="106", "Google Chrome";v="106", "Not;A=Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="106", "Google Chrome";v="106", "Not;A=Brand";v="99""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="106", "Google Chrome";v="106", "Not;A=Brand";v="99""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="106", "Google Chrome";v="106", "Not;A=Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="106", "Google Chrome";v="106", "Not;A=Brand";v="99""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 16_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/106.0.5249.92 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v107, + v106::build_emulation, + header_initializer, + [ + ( + MacOS, + r#""Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 15_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/107.0.5304.66 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v108, + v106::build_emulation, + header_initializer, + [ + ( + MacOS, + r#""Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 16_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/108.0.5359.112 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v109, + v106::build_emulation, + header_initializer, + [ + ( + MacOS, + r#""Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/109.0.5414.112 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v110, + v100::build_emulation, + header_initializer, + [ + ( + MacOS, + r#""Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/110.0.5481.104 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v114, + v106::build_emulation, + header_initializer, + [ + ( + MacOS, + r#""Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36" + ) + ] +); + +mod_generator!( + v116, + tls_options!(4), + http2_options!(2), + header_initializer, + [ + ( + MacOS, + r#""Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/116.0.5845.103 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v117, + tls_options!(5), + http2_options!(3), + header_initializer, + [ + ( + MacOS, + r#""Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117""#, + "Mozilla/5.0 (iPad; CPU OS 16_0 like Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" + ) + ] +); + +mod_generator!( + v120, + v117::build_emulation, + header_initializer, + [ + ( + MacOS, + r#""Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/120.0.6099.119 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + edge122, + v117::build_emulation, + header_initializer, + [ + ( + MacOS, + r#""Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0" + ), + ( + Android, + r#""Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122""#, + "Mozilla/5.0 (Linux; Android 10; Pixel 3 XL) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6268.219 Safari/537.36 Edg/122.0.2238.82" + ), + ( + Windows, + r#""Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0" + ), + // This shouldn't exist, edge was never meant to be on linux + ( + Linux, + r#""Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0" + ), + ( + IOS, + r#""Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0" + ) + ] +); + +mod_generator!( + v123, + v117::build_emulation, + header_initializer_with_zstd, + [ + ( + MacOS, + r#""Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36" + ) + ] +); + +mod_generator!( + v118, + tls_options!(4), + http2_options!(3), + header_initializer, + [ + ( + MacOS, + r#""Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/118.0.5993.92 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v119, + v118::build_emulation, + header_initializer, + [ + ( + MacOS, + r#""Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/119.0.6045.109 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v124, + tls_options!(6, CURVES_2), + http2_options!(3), + header_initializer_with_zstd, + [ + ( + MacOS, + r#""Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/124.0.6312.52 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v126, + v124::build_emulation, + header_initializer_with_zstd, + [ + ( + MacOS, + r#""Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/126.0.6478.153 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v127, + v124::build_emulation, + header_initializer_with_zstd, + [ + ( + MacOS, + r#""Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/127.0.6533.77 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + edge127, + v124::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not)A;Brand";v="99", "Microsoft Edge";v="127", "Chromium";v="127""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0" + ), + ( + Android, + r#""Not)A;Brand";v="99", "Microsoft Edge";v="127", "Chromium";v="127""#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6332.205 Safari/537.36 Edg/127.0.2322.67" + ), + ( + Windows, + r#""Not)A;Brand";v="99", "Microsoft Edge";v="127", "Chromium";v="127""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0" + ), + // This shouldn't exist, edge was never meant to be on linux + ( + Linux, + r#""Not)A;Brand";v="99", "Microsoft Edge";v="127", "Chromium";v="127""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0" + ), + ( + IOS, + r#""Not)A;Brand";v="99", "Microsoft Edge";v="127", "Chromium";v="127""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0" + ) + ] +); + +mod_generator!( + v128, + v124::build_emulation, + header_initializer, + [ + ( + MacOS, + r#""Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/128.0.6613.98 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v129, + v124::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/129.0.6668.46 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v130, + v124::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99""#, + "Mozilla/5.0 (iPad; CPU OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/130.0.6723.90 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v131, + tls_options!(6, CURVES_3), + http2_options!(3), + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24""#, + "Mozilla/5.0 (Linux: Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/131.0.6778.134 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + edge131, + v131::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0" + ), + ( + Android, + r#""Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24""#, + "Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.6778.200 Mobile Safari/537.36 EdgA/131.0.2903.87" + ), + ( + Windows, + r#""Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0" + ), + // This shouldn't exist, edge was never meant to be on linux + ( + Linux, + r#""Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0" + ), + ( + IOS, + r#""Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0" + ) + ] +); + +mod_generator!( + v132, + tls_options!(7, CURVES_3), + http2_options!(3), + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not A(Brand";v="8", "Chromium";v="132", "Google Chrome";v="132""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not A(Brand";v="8", "Chromium";v="132", "Google Chrome";v="132""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not A(Brand";v="8", "Chromium";v="132", "Google Chrome";v="132""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Not A(Brand";v="8", "Chromium";v="132", "Google Chrome";v="132""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not A(Brand";v="8", "Chromium";v="132", "Google Chrome";v="132""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/132.0.6834.78 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v133, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/133.0.6943.33 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v134, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/134.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + edge134, + v131::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="134", "Not:A-Brand";v="24", "Microsoft Edge";v="134"#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0" + ), + ( + Android, + r#""Chromium";v="134", "Not:A-Brand";v="24", "Microsoft Edge";v="134"#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0" + ), + ( + Windows, + r#""Chromium";v="134", "Not:A-Brand";v="24", "Microsoft Edge";v="134"#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0" + ), + ( + Linux, + r#""Chromium";v="134", "Not:A-Brand";v="24", "Microsoft Edge";v="134"#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0" + ), + ( + IOS, + r#""Chromium";v="134", "Not:A-Brand";v="24", "Microsoft Edge";v="134"#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/134.0.0.0" + ) + ] +); + +mod_generator!( + edge135, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="135", "Not:A-Brand";v="24", "Microsoft Edge";v="135"#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0" + ), + ( + Android, + r#""Chromium";v="135", "Not:A-Brand";v="24", "Microsoft Edge";v="135"#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0" + ), + ( + Windows, + r#""Chromium";v="135", "Not:A-Brand";v="24", "Microsoft Edge";v="135"#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0" + ), + ( + Linux, + r#""Chromium";v="135", "Not:A-Brand";v="24", "Microsoft Edge";v="135"#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0" + ), + ( + IOS, + r#""Chromium";v="135", "Not:A-Brand";v="24", "Microsoft Edge";v="135"#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/135.0.0.0" + ) + ] +); + +mod_generator!( + edge136, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="136", "Not:A-Brand";v="24", "Microsoft Edge";v="136"#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0" + ), + ( + Android, + r#""Chromium";v="136", "Not:A-Brand";v="24", "Microsoft Edge";v="136"#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0" + ), + ( + Windows, + r#""Chromium";v="136", "Not:A-Brand";v="24", "Microsoft Edge";v="136"#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0" + ), + ( + Linux, + r#""Chromium";v="136", "Not:A-Brand";v="24", "Microsoft Edge";v="136"#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0" + ), + ( + IOS, + r#""Chromium";v="136", "Not:A-Brand";v="24", "Microsoft Edge";v="136"#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/136.0.0.0" + ) + ] +); + +mod_generator!( + edge137, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="137", "Not:A-Brand";v="24", "Microsoft Edge";v="137"#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0" + ), + ( + Android, + r#""Chromium";v="137", "Not:A-Brand";v="24", "Microsoft Edge";v="137"#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0" + ), + ( + Windows, + r#""Chromium";v="137", "Not:A-Brand";v="24", "Microsoft Edge";v="137"#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0" + ), + ( + Linux, + r#""Chromium";v="137", "Not:A-Brand";v="24", "Microsoft Edge";v="137"#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0" + ), + ( + IOS, + r#""Chromium";v="137", "Not:A-Brand";v="24", "Microsoft Edge";v="137"#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/137.0.0.0" + ) + ] +); + +mod_generator!( + edge138, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="138", "Not=A?Brand";v="24", "Microsoft Edge";v="138"#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0" + ), + ( + Android, + r#""Chromium";v="138", "Not=A?Brand";v="24", "Microsoft Edge";v="138"#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0" + ), + ( + Windows, + r#""Chromium";v="138", "Not=A?Brand";v="24", "Microsoft Edge";v="138"#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0" + ), + ( + Linux, + r#""Chromium";v="138", "Not=A?Brand";v="24", "Microsoft Edge";v="138"#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0" + ), + ( + IOS, + r#""Chromium";v="138", "Not=A?Brand";v="24", "Microsoft Edge";v="138"#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/138.0.0.0" + ) + ] +); + +mod_generator!( + edge139, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="139", "Not=A?Brand";v="24", "Microsoft Edge";v="139"#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0" + ), + ( + Android, + r#""Chromium";v="139", "Not=A?Brand";v="24", "Microsoft Edge";v="139"#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0" + ), + ( + Windows, + r#""Chromium";v="139", "Not=A?Brand";v="24", "Microsoft Edge";v="139"#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0" + ), + ( + Linux, + r#""Chromium";v="139", "Not=A?Brand";v="24", "Microsoft Edge";v="139"#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0" + ), + ( + IOS, + r#""Chromium";v="139", "Not=A?Brand";v="24", "Microsoft Edge";v="139"#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/139.0.0.0" + ) + ] +); + +mod_generator!( + edge140, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0" + ), + ( + Android, + r#""Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0" + ), + ( + Windows, + r#""Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0" + ), + ( + Linux, + r#""Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0" + ), + ( + IOS, + r#""Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/140.0.0.0" + ) + ] +); + +mod_generator!( + edge141, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="141", "Not=A?Brand";v="24", "Microsoft Edge";v="141"#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0" + ), + ( + Android, + r#""Chromium";v="141", "Not=A?Brand";v="24", "Microsoft Edge";v="141"#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0" + ), + ( + Windows, + r#""Chromium";v="141", "Not=A?Brand";v="24", "Microsoft Edge";v="141"#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0" + ), + ( + Linux, + r#""Chromium";v="141", "Not=A?Brand";v="24", "Microsoft Edge";v="141"#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0" + ), + ( + IOS, + r#""Chromium";v="141", "Not=A?Brand";v="24", "Microsoft Edge";v="141"#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/141.0.0.0" + ) + ] +); + +mod_generator!( + v135, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/135.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v136, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/136.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v137, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Google Chrome";v="137", "Chromium";v="137", "Not/A)Brand";v="24""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="137", "Chromium";v="137", "Not/A)Brand";v="24""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="137", "Chromium";v="137", "Not/A)Brand";v="24""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="137", "Chromium";v="137", "Not/A)Brand";v="24""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="137", "Chromium";v="137", "Not/A)Brand";v="24""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/137.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v138, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/138.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v139, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not;A=Brand";v="99", "Google Chrome";v="139", "Chromium";v="139""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not;A=Brand";v="99", "Google Chrome";v="139", "Chromium";v="139""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not;A=Brand";v="99", "Google Chrome";v="139", "Chromium";v="139""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Not;A=Brand";v="99", "Google Chrome";v="139", "Chromium";v="139""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not;A=Brand";v="99", "Google Chrome";v="139", "Chromium";v="139""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/139.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v140, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="140", "Not=A?Brand";v="24", "Google Chrome";v="140""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="140", "Not=A?Brand";v="24", "Google Chrome";v="140""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="140", "Not=A?Brand";v="24", "Google Chrome";v="140""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="140", "Not=A?Brand";v="24", "Google Chrome";v="140""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="140", "Not=A?Brand";v="24", "Google Chrome";v="140""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/140.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v141, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="141", "Not?A_Brand";v="8", "Chromium";v="141""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/141.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v142, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/142.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + edge142, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="142", "Microsoft Edge";v="142", "Not_A Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0" + ), + ( + Android, + r#""Chromium";v="142", "Microsoft Edge";v="142", "Not_A Brand";v="99""#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Mobile Safari/537.36 Edg/142.0.0.0" + ), + ( + Windows, + r#""Chromium";v="142", "Microsoft Edge";v="142", "Not_A Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0" + ), + ( + Linux, + r#""Chromium";v="142", "Microsoft Edge";v="142", "Not_A Brand";v="99""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0" + ), + ( + IOS, + r#""Chromium";v="142", "Microsoft Edge";v="142", "Not_A Brand";v="99""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0" + ) + ] +); + +mod_generator!( + v143, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/143.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v144, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not(A:Brand";v="8", "Chromium";v="144", "Google Chrome";v="144""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not(A:Brand";v="8", "Chromium";v="144", "Google Chrome";v="144""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not(A:Brand";v="8", "Chromium";v="144", "Google Chrome";v="144""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Not(A:Brand";v="8", "Chromium";v="144", "Google Chrome";v="144""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not(A:Brand";v="8", "Chromium";v="144", "Google Chrome";v="144""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/144.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v145, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not:A-Brand";v="99", "Google Chrome";v="145", "Chromium";v="145""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not:A-Brand";v="99", "Google Chrome";v="145", "Chromium";v="145""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not:A-Brand";v="99", "Google Chrome";v="145", "Chromium";v="145""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Not:A-Brand";v="99", "Google Chrome";v="145", "Chromium";v="145""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not:A-Brand";v="99", "Google Chrome";v="145", "Chromium";v="145""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/145.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v146, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="146", "Not-A.Brand";v="24", "Google Chrome";v="146""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="146", "Not-A.Brand";v="24", "Google Chrome";v="146""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="146", "Not-A.Brand";v="24", "Google Chrome";v="146""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.7680.164 Mobile Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="146", "Not-A.Brand";v="24", "Google Chrome";v="146""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="146", "Not-A.Brand";v="24", "Google Chrome";v="146""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/146.0.7680.164 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v147, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Google Chrome";v="147", "Not.A/Brand";v="8", "Chromium";v="147""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="147", "Not.A/Brand";v="8", "Chromium";v="147""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="147", "Not.A/Brand";v="8", "Chromium";v="147""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.7712.122 Mobile Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="147", "Not.A/Brand";v="8", "Chromium";v="147""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="147", "Not.A/Brand";v="8", "Chromium";v="147""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/147.0.7712.122 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v148, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="148", "Google Chrome";v="148", "Not/A)Brand";v="99""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/148.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v149, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Google Chrome";v="149", "Chromium";v="149", "Not)A;Brand";v="24""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="149", "Chromium";v="149", "Not)A;Brand";v="24""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="149", "Chromium";v="149", "Not)A;Brand";v="24""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="149", "Chromium";v="149", "Not)A;Brand";v="24""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="149", "Chromium";v="149", "Not)A;Brand";v="24""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/149.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v150, + tls_options!(8, CURVES_3, NEW_SIGALGS_LIST), + http2_options!(3), + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not;A=Brand";v="8", "Chromium";v="150", "Google Chrome";v="150""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not;A=Brand";v="8", "Chromium";v="150", "Google Chrome";v="150""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not;A=Brand";v="8", "Chromium";v="150", "Google Chrome";v="150""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Not;A=Brand";v="8", "Chromium";v="150", "Google Chrome";v="150""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not;A=Brand";v="8", "Chromium";v="150", "Google Chrome";v="150""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/150.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v151, + v150::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not=A?Brand";v="99", "Google Chrome";v="151", "Chromium";v="151""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not=A?Brand";v="99", "Google Chrome";v="151", "Chromium";v="151""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not=A?Brand";v="99", "Google Chrome";v="151", "Chromium";v="151""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Not=A?Brand";v="99", "Google Chrome";v="151", "Chromium";v="151""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not=A?Brand";v="99", "Google Chrome";v="151", "Chromium";v="151""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/151.0.7922.43 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v152, + tls_options!(9, CURVES_3), + http2_options!(3), + header_initializer_chrome152, + [ + ( + MacOS, + r#""Chromium";v="152", "Not?A_Brand";v="24", "Google Chrome";v="152""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="152", "Not?A_Brand";v="24", "Google Chrome";v="152""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="152", "Not?A_Brand";v="24", "Google Chrome";v="152""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="152", "Not?A_Brand";v="24", "Google Chrome";v="152""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="152", "Not?A_Brand";v="24", "Google Chrome";v="152""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/152.0.0.0 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v153, + v152::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Google Chrome";v="153", "Not_A Brand";v="8", "Chromium";v="153""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="153", "Not_A Brand";v="8", "Chromium";v="153""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="153", "Not_A Brand";v="8", "Chromium";v="153""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="153", "Not_A Brand";v="8", "Chromium";v="153""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="153", "Not_A Brand";v="8", "Chromium";v="153""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/153.0.8010.24 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + v154, + tls_options!(9, CURVES_3, sorted_trust_anchors()), + http2_options!(3), + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="154", "Google Chrome";v="154", "Not A(Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="154", "Google Chrome";v="154", "Not A(Brand";v="99""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="154", "Google Chrome";v="154", "Not A(Brand";v="99""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="154", "Google Chrome";v="154", "Not A(Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="154", "Google Chrome";v="154", "Not A(Brand";v="99""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/154.0.8037.41 Mobile/15E148 Safari/604.1" + ) + ] +); + +// Chrome 155 retains Chrome 154's TLS/HTTP2 configuration. Its UA-CH permutation +// and GREASE brand are seeded by major version 155. +// https://chromium.googlesource.com/chromium/src/+/cfaadc5a132d78e1828635aa8405a499f3e14864/components/embedder_support/user_agent_utils.cc +mod_generator!( + v155, + v154::build_emulation, + header_initializer_chrome155, + [ + ( + MacOS, + r#""Google Chrome";v="155", "Chromium";v="155", "Not(A:Brand";v="24""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Google Chrome";v="155", "Chromium";v="155", "Not(A:Brand";v="24""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Google Chrome";v="155", "Chromium";v="155", "Not(A:Brand";v="24""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Google Chrome";v="155", "Chromium";v="155", "Not(A:Brand";v="24""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Google Chrome";v="155", "Chromium";v="155", "Not(A:Brand";v="24""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/155.0.8059.37 Mobile/15E148 Safari/604.1" + ) + ] +); + +// Chrome 156 retains Chrome 155's TLS/HTTP2 and Accept configuration. +// https://chromium.googlesource.com/chromium/src/+/29eb03535d5f2f4f899b95f22a92413ffde5284e/components/embedder_support/user_agent_utils.cc +mod_generator!( + v156, + v154::build_emulation, + header_initializer_chrome155, + [ + ( + MacOS, + r#""Not:A-Brand";v="8", "Chromium";v="156", "Google Chrome";v="156""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not:A-Brand";v="8", "Chromium";v="156", "Google Chrome";v="156""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not:A-Brand";v="8", "Chromium";v="156", "Google Chrome";v="156""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Not:A-Brand";v="8", "Chromium";v="156", "Google Chrome";v="156""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/156.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not:A-Brand";v="8", "Chromium";v="156", "Google Chrome";v="156""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/156.0.8078.54 Mobile/15E148 Safari/604.1" + ) + ] +); + +// Chrome 157 retains Chrome 156's TLS/HTTP2 and Accept configuration. +// Its UA-CH order and GREASE brand are seeded by major version 157. +// https://chromium.googlesource.com/chromium/src/+/653674df293788cf4932c40d914e9e15b41a2d31/components/embedder_support/user_agent_utils.cc +mod_generator!( + v157, + v154::build_emulation, + header_initializer_chrome155, + [ + ( + MacOS, + r#""Not-A.Brand";v="99", "Google Chrome";v="157", "Chromium";v="157""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Not-A.Brand";v="99", "Google Chrome";v="157", "Chromium";v="157""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Not-A.Brand";v="99", "Google Chrome";v="157", "Chromium";v="157""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Not-A.Brand";v="99", "Google Chrome";v="157", "Chromium";v="157""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Not-A.Brand";v="99", "Google Chrome";v="157", "Chromium";v="157""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/157.0.8103.37 Mobile/15E148 Safari/604.1" + ) + ] +); + +// Chrome 158 retains the Chrome 157 TLS, HTTP/2 and Accept presets. +// https://chromium.googlesource.com/chromium/src/+/b8c2be851f62f6a394ec57955d7f31335d7cb6d4/components/embedder_support/user_agent_utils.cc +mod_generator!( + v158, + v154::build_emulation, + header_initializer_chrome155, + [ + ( + MacOS, + r#""Chromium";v="158", "Not.A/Brand";v="24", "Google Chrome";v="158""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36" + ), + ( + Linux, + r#""Chromium";v="158", "Not.A/Brand";v="24", "Google Chrome";v="158""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36" + ), + ( + Android, + r#""Chromium";v="158", "Not.A/Brand";v="24", "Google Chrome";v="158""#, + "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Mobile Safari/537.36" + ), + ( + Windows, + r#""Chromium";v="158", "Not.A/Brand";v="24", "Google Chrome";v="158""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36" + ), + ( + IOS, + r#""Chromium";v="158", "Not.A/Brand";v="24", "Google Chrome";v="158""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/158.0.8127.35 Mobile/15E148 Safari/604.1" + ) + ] +); + +mod_generator!( + edge143, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="143", "Microsoft Edge";v="143", "Not_A Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0" + ), + ( + Android, + r#""Chromium";v="143", "Microsoft Edge";v="143", "Not_A Brand";v="99""#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Mobile Safari/537.36 Edg/143.0.0.0" + ), + ( + Windows, + r#""Chromium";v="143", "Microsoft Edge";v="143", "Not_A Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0" + ), + ( + Linux, + r#""Chromium";v="143", "Microsoft Edge";v="143", "Not_A Brand";v="99""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0" + ), + ( + IOS, + r#""Chromium";v="143", "Microsoft Edge";v="143", "Not_A Brand";v="99""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0" + ) + ] +); + +mod_generator!( + edge144, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not(A:Brand";v="8", "Chromium";v="144", "Microsoft Edge";v="144""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0" + ), + ( + Android, + r#""Not(A:Brand";v="8", "Chromium";v="144", "Microsoft Edge";v="144""#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Mobile Safari/537.36 Edg/144.0.0.0" + ), + ( + Windows, + r#""Not(A:Brand";v="8", "Chromium";v="144", "Microsoft Edge";v="144""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0" + ), + ( + Linux, + r#""Not(A:Brand";v="8", "Chromium";v="144", "Microsoft Edge";v="144""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0" + ), + ( + IOS, + r#""Not(A:Brand";v="8", "Chromium";v="144", "Microsoft Edge";v="144""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0" + ) + ] +); + +mod_generator!( + edge145, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="145", "Not;A=Brand";v="24", "Microsoft Edge";v="145""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0" + ), + ( + Android, + r#""Chromium";v="145", "Not;A=Brand";v="24", "Microsoft Edge";v="145""#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Mobile Safari/537.36 Edg/145.0.0.0" + ), + ( + Windows, + r#""Chromium";v="145", "Not;A=Brand";v="24", "Microsoft Edge";v="145""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0" + ), + ( + Linux, + r#""Chromium";v="145", "Not;A=Brand";v="24", "Microsoft Edge";v="145""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0" + ), + ( + IOS, + r#""Chromium";v="145", "Not;A=Brand";v="24", "Microsoft Edge";v="145""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0" + ) + ] +); + +mod_generator!( + edge146, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="146", "Not(A:Brand";v="24", "Microsoft Edge";v="146""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 Edg/146.0.3856.109" + ), + ( + Android, + r#""Chromium";v="146", "Not(A:Brand";v="24", "Microsoft Edge";v="146""#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.7680.178 Mobile Safari/537.36 EdgA/146.0.3856.97" + ), + ( + Windows, + r#""Chromium";v="146", "Not(A:Brand";v="24", "Microsoft Edge";v="146""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 Edg/146.0.3856.109" + ), + ( + Linux, + r#""Chromium";v="146", "Not(A:Brand";v="24", "Microsoft Edge";v="146""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 Edg/146.0.3856.109" + ), + ( + IOS, + r#""Chromium";v="146", "Not(A:Brand";v="24", "Microsoft Edge";v="146""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 EdgiOS/146.0.3856.102 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + edge147, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Microsoft Edge";v="147", "Not.A/Brand";v="8", "Chromium";v="147""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/147.0.3912.51" + ), + ( + Android, + r#""Microsoft Edge";v="147", "Not.A/Brand";v="8", "Chromium";v="147""#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.7727.55 Mobile Safari/537.36 EdgA/147.0.3912.51" + ), + ( + Windows, + r#""Microsoft Edge";v="147", "Not.A/Brand";v="8", "Chromium";v="147""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/147.0.3912.51" + ), + ( + Linux, + r#""Microsoft Edge";v="147", "Not.A/Brand";v="8", "Chromium";v="147""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/147.0.3912.51" + ), + ( + IOS, + r#""Microsoft Edge";v="147", "Not.A/Brand";v="8", "Chromium";v="147""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 EdgiOS/147.0.3912.51 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + edge148, + v132::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="148", "Microsoft Edge";v="148", "Not/A)Brand";v="99""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0" + ), + ( + Android, + r#""Chromium";v="148", "Microsoft Edge";v="148", "Not/A)Brand";v="99""#, + "Mozilla/5.0 (Linux; Android 10; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Mobile Safari/537.36 EdgA/148.0.0.0" + ), + ( + Windows, + r#""Chromium";v="148", "Microsoft Edge";v="148", "Not/A)Brand";v="99""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0" + ), + ( + Linux, + r#""Chromium";v="148", "Microsoft Edge";v="148", "Not/A)Brand";v="99""#, + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0" + ), + ( + IOS, + r#""Chromium";v="148", "Microsoft Edge";v="148", "Not/A)Brand";v="99""#, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 EdgiOS/148.0.0.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); diff --git a/crates/wreq-util/src/emulate/profile/chrome/header.rs b/crates/wreq-util/src/emulate/profile/chrome/header.rs new file mode 100644 index 0000000..2926948 --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/chrome/header.rs @@ -0,0 +1,116 @@ +use super::*; + +pub fn header_initializer( + sec_ch_ua: &'static str, + ua: &'static str, + emulation_os: Platform, +) -> HeaderMap { + let mut headers = HeaderMap::new(); + header_chrome_sec_ch_ua!( + headers, + sec_ch_ua, + emulation_os.platform(), + emulation_os.is_mobile() + ); + headers.insert( + HeaderName::from_static("upgrade-insecure-requests"), + HeaderValue::from_static("1"), + ); + header_chrome_ua!(headers, ua); + header_chrome_accept!(headers); + header_chrome_sec_fetch!(headers); + header_chrome_accept_encoding!(headers); + headers +} + +pub fn header_initializer_with_zstd( + sec_ch_ua: &'static str, + ua: &'static str, + emulation_os: Platform, +) -> HeaderMap { + let mut headers = HeaderMap::new(); + header_chrome_sec_ch_ua!( + headers, + sec_ch_ua, + emulation_os.platform(), + emulation_os.is_mobile() + ); + headers.insert( + HeaderName::from_static("upgrade-insecure-requests"), + HeaderValue::from_static("1"), + ); + header_chrome_ua!(headers, ua); + header_chrome_accept!(headers); + header_chrome_sec_fetch!(headers); + header_chrome_accept_encoding!(zstd, headers); + headers +} + +pub fn header_initializer_with_zstd_priority( + sec_ch_ua: &'static str, + ua: &'static str, + emulation_os: Platform, +) -> HeaderMap { + let mut headers = HeaderMap::new(); + header_chrome_sec_ch_ua!( + headers, + sec_ch_ua, + emulation_os.platform(), + emulation_os.is_mobile() + ); + headers.insert( + HeaderName::from_static("upgrade-insecure-requests"), + HeaderValue::from_static("1"), + ); + header_chrome_ua!(headers, ua); + header_chrome_accept!(headers); + header_chrome_sec_fetch!(headers); + header_chrome_accept_encoding!(zstd, headers); + headers.insert( + HeaderName::from_static("priority"), + HeaderValue::from_static("u=0, i"), + ); + headers +} + +pub fn header_initializer_chrome155( + sec_ch_ua: &'static str, + ua: &'static str, + emulation_os: Platform, +) -> HeaderMap { + let mut headers = header_initializer_with_zstd_priority(sec_ch_ua, ua, emulation_os); + // Chrome 155 enables JPEG XL in Blink; the iOS profile keeps its WebKit headers. + // https://chromium.googlesource.com/chromium/src/+/cfaadc5a132d78e1828635aa8405a499f3e14864/content/common/content_constants_internal.h + if !matches!(emulation_os, Platform::IOS) { + headers.insert(ACCEPT, HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7")); + } + headers +} + +pub fn header_initializer_chrome152( + sec_ch_ua: &'static str, + ua: &'static str, + emulation_os: Platform, +) -> HeaderMap { + let mut headers = HeaderMap::new(); + header_chrome_sec_ch_ua!( + headers, + sec_ch_ua, + emulation_os.platform(), + emulation_os.is_mobile() + ); + headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9")); + headers.insert( + HeaderName::from_static("upgrade-insecure-requests"), + HeaderValue::from_static("1"), + ); + header_chrome_ua!(headers, ua); + header_chrome_accept!(headers); + header_chrome_sec_fetch!(headers); + header_chrome_accept_encoding!(zstd_only, headers); + headers.insert( + HeaderName::from_static("priority"), + HeaderValue::from_static("u=0, i"), + ); + headers +} diff --git a/crates/wreq-util/src/emulate/profile/chrome/http2.rs b/crates/wreq-util/src/emulate/profile/chrome/http2.rs new file mode 100644 index 0000000..a47190a --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/chrome/http2.rs @@ -0,0 +1,65 @@ +macro_rules! headers_priority { + () => { + HeadersPriority::new(HeadersDependency::Root, 255, true) + }; +} + +macro_rules! pseudo_order { + () => { + PseudoOrder::builder() + .extend([ + PseudoId::Method, + PseudoId::Authority, + PseudoId::Scheme, + PseudoId::Path, + ]) + .build() + }; +} + +macro_rules! settings_order { + () => { + SettingsOrder::builder() + .extend([ + SettingId::HeaderTableSize, + SettingId::EnablePush, + SettingId::MaxConcurrentStreams, + SettingId::InitialWindowSize, + SettingId::MaxFrameSize, + SettingId::MaxHeaderListSize, + SettingId::EnableConnectProtocol, + SettingId::NoRfc7540Priorities, + ]) + .build() + }; +} + +macro_rules! http2_options { + (@base $builder:expr) => { + $builder + .initial_window_size(6291456) + .initial_connection_window_size(15728640) + .max_header_list_size(262144) + .header_table_size(65536) + .headers_priority(headers_priority!()) + .headers_pseudo_order(pseudo_order!()) + .settings_order(settings_order!()) + }; + + (1) => { + http2_options!(@base Http2Options::builder()) + .max_concurrent_streams(1000) + .build() + }; + (2) => { + http2_options!(@base Http2Options::builder()) + .max_concurrent_streams(1000) + .enable_push(false) + .build() + }; + (3) => { + http2_options!(@base Http2Options::builder()) + .enable_push(false) + .build() + }; +} diff --git a/crates/wreq-util/src/emulate/profile/chrome/tls.rs b/crates/wreq-util/src/emulate/profile/chrome/tls.rs new file mode 100644 index 0000000..ffabd41 --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/chrome/tls.rs @@ -0,0 +1,268 @@ +use super::*; + +macro_rules! tls_options { + (@build $builder:expr) => { + $builder.build().into() + }; + + (1) => { + tls_options!(@build ChromeTlsConfig::builder()) + }; + (2) => { + tls_options!(@build ChromeTlsConfig::builder().enable_ech_grease(true)) + }; + (3) => { + tls_options!(@build ChromeTlsConfig::builder().permute_extensions(true)) + }; + (4) => { + tls_options!(@build ChromeTlsConfig::builder() + .permute_extensions(true) + .enable_ech_grease(true)) + }; + (5) => { + tls_options!(@build ChromeTlsConfig::builder() + .permute_extensions(true) + .enable_ech_grease(true) + .pre_shared_key(true)) + }; + (6, $curves:expr) => { + tls_options!(@build ChromeTlsConfig::builder() + .permute_extensions(true) + .enable_ech_grease(true) + .pre_shared_key(true) + .curves($curves)) + }; + (7, $curves:expr) => { + tls_options!(@build ChromeTlsConfig::builder() + .permute_extensions(true) + .enable_ech_grease(true) + .pre_shared_key(true) + .curves($curves) + .alps_use_new_codepoint(true)) + }; + (8, $curves:expr, $sigalgs:expr) => { + tls_options!(@build ChromeTlsConfig::builder() + .permute_extensions(true) + .enable_ech_grease(true) + .pre_shared_key(true) + .curves($curves) + .sigalgs_list($sigalgs) + .alps_use_new_codepoint(true)) + }; + (9, $curves:expr) => { + tls_options!(9, $curves, shuffled_trust_anchors(crate::rand::fast_random)) + }; + (9, $curves:expr, $trust_anchors:expr) => { + tls_options!(@build ChromeTlsConfig::builder() + .permute_extensions(true) + .enable_ech_grease(true) + .pre_shared_key(true) + .curves($curves) + .sigalgs_list(NEW_SIGALGS_LIST) + .trust_anchors($trust_anchors) + .grease_sigalgs_enabled(true) + .alps_use_new_codepoint(true)) + }; +} + +pub const CURVES_1: &str = join!(":", "X25519", "P-256", "P-384"); +pub const CURVES_2: &str = join!(":", "X25519Kyber768Draft00", "X25519", "P-256", "P-384"); +pub const CURVES_3: &str = join!(":", "X25519MLKEM768", "X25519", "P-256", "P-384"); + +pub const CIPHER_LIST: &str = join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA" +); + +pub const TLS13_CIPHER_LIST: &[Tls13Cipher] = &[ + Tls13Cipher::AES_128_GCM_SHA256, + Tls13Cipher::AES_256_GCM_SHA384, + Tls13Cipher::CHACHA20_POLY1305_SHA256, +]; + +pub const SIGALGS_LIST: &str = join!( + ":", + "ecdsa_secp256r1_sha256", + "rsa_pss_rsae_sha256", + "rsa_pkcs1_sha256", + "ecdsa_secp384r1_sha384", + "rsa_pss_rsae_sha384", + "rsa_pkcs1_sha384", + "rsa_pss_rsae_sha512", + "rsa_pkcs1_sha512" +); + +pub const NEW_SIGALGS_LIST: &str = join!( + ":", + "mldsa44", + "mldsa65", + "mldsa87", + "ecdsa_secp256r1_sha256", + "rsa_pss_rsae_sha256", + "rsa_pkcs1_sha256", + "ecdsa_secp384r1_sha384", + "rsa_pss_rsae_sha384", + "rsa_pkcs1_sha384", + "rsa_pss_rsae_sha512", + "rsa_pkcs1_sha512" +); + +// Encoded IDs and wreq's Chromium root store come from the same root set. +pub(super) const CHROME_TRUST_ANCHORS: &[u8] = &chromium_roots::encoded_trust_anchor_ids(); + +// Chrome 152/153 iterate a salted flat_hash_set held by SSLClientContext, rather than +// the root store's source order. Generate an order once per native configuration; +// connections using that client configuration retain the order. +// https://chromium.googlesource.com/chromium/src/+/f7b831a4e249fbd98eae4b391c69f70300a849d1/net/ssl/ssl_config_service.cc +pub(super) fn shuffled_trust_anchors(mut random: impl FnMut() -> u64) -> Vec { + let mut ids = chromium_roots::trust_anchor_ids(); + for index in (1..ids.len()).rev() { + let bound = (index + 1) as u64; + let limit = u64::MAX - u64::MAX % bound; + let mut value = random(); + while value >= limit { + value = random(); + } + ids.swap(index, (value % bound) as usize); + } + + encode_trust_anchors(&ids) +} + +// Chrome 154 sorts the raw IDs before adding their length prefixes. +// https://chromium.googlesource.com/chromium/src/+/731082f0a26ce4b3976c3d82943092f5d13daf13/net/cert/x509_util.cc +pub(super) fn sorted_trust_anchors() -> Vec { + let mut ids = chromium_roots::trust_anchor_ids(); + ids.sort_unstable(); + encode_trust_anchors(&ids) +} + +fn encode_trust_anchors(ids: &[&[u8]]) -> Vec { + let mut encoded = Vec::with_capacity(CHROME_TRUST_ANCHORS.len()); + for id in ids { + // encoded_trust_anchor_ids() validates these same IDs at compile time: + // each length is nonzero and fits in one byte. + encoded.push(id.len() as u8); + encoded.extend_from_slice(id); + } + encoded +} + +pub const CERTIFICATE_COMPRESSORS: &[&'static dyn CertificateCompressor] = &[&BrotliCompressor]; + +#[derive(TypedBuilder)] +pub struct ChromeTlsConfig { + #[builder(default = CURVES_1)] + curves: &'static str, + + #[builder(default = SIGALGS_LIST)] + sigalgs_list: &'static str, + + #[builder(default = CIPHER_LIST)] + cipher_list: &'static str, + + #[builder(default = AlpsProtocol::HTTP2, setter(into))] + alps_protos: AlpsProtocol, + + #[builder(default = false)] + alps_use_new_codepoint: bool, + + #[builder(default = false, setter(into))] + enable_ech_grease: bool, + + #[builder(default = false, setter(into))] + permute_extensions: bool, + + #[builder(default = false, setter(into))] + pre_shared_key: bool, + + #[builder(default, setter(strip_option))] + trust_anchors: Option>, + + #[builder(default, setter(strip_option))] + grease_sigalgs_enabled: Option, +} + +impl From for TlsOptions { + fn from(val: ChromeTlsConfig) -> Self { + let builder = TlsOptions::builder() + .grease_enabled(true) + .enable_ocsp_stapling(true) + .enable_signed_cert_timestamps(true) + .curves_list(val.curves) + .sigalgs_list(val.sigalgs_list) + .cipher_list(val.cipher_list) + .tls13_cipher_list(TLS13_CIPHER_LIST) + .min_tls_version(TlsVersion::TLS_1_2) + .max_tls_version(TlsVersion::TLS_1_3) + .permute_extensions(val.permute_extensions) + .pre_shared_key(val.pre_shared_key) + .ech_grease( + val.enable_ech_grease + .then_some(EchGrease::Aead(EchGreaseAead::AES_128_GCM)), + ) + .alps_protocols([val.alps_protos]) + .alps_use_new_codepoint(val.alps_use_new_codepoint) + .certificate_compressors(CERTIFICATE_COMPRESSORS); + let builder = if let Some(trust_anchors) = val.trust_anchors { + builder.trust_anchors(trust_anchors) + } else { + builder + }; + let builder = if let Some(enabled) = val.grease_sigalgs_enabled { + builder.grease_sigalgs_enabled(enabled) + } else { + builder + }; + builder.build() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn sorted_trust_anchors_match_chromium_root_store() { + let encoded = sorted_trust_anchors(); + let mut expected = chromium_roots::trust_anchor_ids(); + expected.sort_unstable(); + assert_eq!(decode_ids(&encoded), expected); + assert_eq!(encoded.len(), CHROME_TRUST_ANCHORS.len()); + } + + #[test] + fn trust_anchor_shuffle_preserves_ids_without_pinning_the_first() { + // Choosing index zero at every step rotates the entire list left. + // Rejecting u64::MAX also covers the unbiased sampling boundary. + let mut samples = std::iter::once(u64::MAX).chain(std::iter::repeat(0)); + let encoded = shuffled_trust_anchors(|| samples.next().unwrap()); + let decoded = decode_ids(&encoded); + let mut expected = chromium_roots::trust_anchor_ids(); + expected.rotate_left(1); + assert_eq!(decoded, expected); + assert_eq!(encoded.len(), CHROME_TRUST_ANCHORS.len()); + } + + fn decode_ids(mut remaining: &[u8]) -> Vec<&[u8]> { + let mut decoded = Vec::new(); + while let Some((&length, rest)) = remaining.split_first() { + assert_ne!(length, 0); + let (id, rest) = rest.split_at(usize::from(length)); + decoded.push(id); + remaining = rest; + } + decoded + } +} diff --git a/crates/wreq-util/src/emulate/profile/firefox.rs b/crates/wreq-util/src/emulate/profile/firefox.rs new file mode 100644 index 0000000..74cf164 --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/firefox.rs @@ -0,0 +1,547 @@ +#[macro_use] +mod http2; +#[macro_use] +mod tls; +mod header; + +use header::*; +use tls::*; + +use super::*; + +mod_generator!( + ff109, + tls_options!(2, CIPHER_LIST_1, CURVES_1), + http2_options!(2), + header_initializer, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_17; rv:109.0) Gecko/20000101 Firefox/109.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/109.0 Firefox/109.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Linux i686; rv:109.0) Gecko/20100101 Firefox/109.0" + ), + ( + IOS, + "Mozilla/5.0 (iPad; CPU OS 13_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/109.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff117, + ff109::build_emulation, + header_initializer, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:117.0) Gecko/20100101 Firefox/117.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_16_1; rv:117.0) Gecko/20010101 Firefox/117.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:117.0) Gecko/117.0 Firefox/117.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Linux i686; rv:117.0) Gecko/20100101 Firefox/117.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/117.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff128, + tls_options!(3, CIPHER_LIST_2, CURVES_1, KEY_SHARES_1), + http2_options!(3), + header_initializer_with_zstd, + [ + ( + MacOs, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:128.0) Gecko/20100101 Firefox/128.0" + ), + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; rv:128.0) Gecko/20100101 Firefox/128.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:128.0) Gecko/128.0 Firefox/128.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/128.0 Mobile/15E148 Safari/605.1.15" + ), + ( + Linux, + "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0" + ) + ] +); + +mod_generator!( + ff133, + tls_options!(1, CIPHER_LIST_1, CURVES_2, KEY_SHARES_2), + http2_options!(1), + header_initializer_with_zstd, + [ + ( + MacOs, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:133.0) Gecko/20100101 Firefox/133.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:133.0) Gecko/133.0 Firefox/133.0" + ), + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; rv:133.0) Gecko/20100101 Firefox/133.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/133.4 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff135, + tls_options!(4, CIPHER_LIST_1, CURVES_2, KEY_SHARES_2), + http2_options!(1), + header_initializer_with_zstd, + [ + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0" + ), + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; rv:135.0) Gecko/20100101 Firefox/135.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:135.0) Gecko/20100101 Firefox/135.0" + ) + ] +); + +mod_generator!( + ff_private_135, + tls_options!(6, CIPHER_LIST_1, CURVES_2, KEY_SHARES_2), + http2_options!(1), + header_initializer_with_zstd, + [ + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0" + ), + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; rv:135.0) Gecko/20100101 Firefox/135.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:135.0) Gecko/20100101 Firefox/135.0" + ) + ] +); + +mod_generator!( + ff_android_135, + tls_options!(5, CIPHER_LIST_1, CURVES_1, KEY_SHARES_1), + http2_options!(4), + header_initializer_with_zstd, + [( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:135.0) Gecko/135.0 Firefox/135.0" + )] +); + +mod_generator!( + ff136, + ff135::build_emulation, + header_initializer_with_zstd, + [ + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:136.0) Gecko/20100101 Firefox/136.0" + ), + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; rv:136.0) Gecko/20100101 Firefox/136.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0" + ) + ] +); + +mod_generator!( + ff_private_136, + ff_private_135::build_emulation, + header_initializer_with_zstd, + [ + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:136.0) Gecko/20100101 Firefox/136.0" + ), + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; rv:136.0) Gecko/20100101 Firefox/136.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0" + ) + ] +); + +mod_generator!( + ff139, + ff135::build_emulation, + header_initializer_with_zstd, + [ + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:139.0) Gecko/20100101 Firefox/139.0" + ), + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; rv:136.0) Gecko/20100101 Firefox/139.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/139.0" + ) + ] +); + +mod_generator!( + ff142, + ff135::build_emulation, + header_initializer_with_zstd, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:142.0) Gecko/20100101 Firefox/142.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:142.0) Gecko/142.0 Firefox/142.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/142.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff143, + ff135::build_emulation, + header_initializer_with_zstd, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:143.0) Gecko/20100101 Firefox/143.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:143.0) Gecko/20100101 Firefox/143.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:143.0) Gecko/20100101 Firefox/143.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:143.0) Gecko/143.0 Firefox/143.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/143.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff144, + ff135::build_emulation, + header_initializer_with_zstd, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:144.0) Gecko/20100101 Firefox/144.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:144.0) Gecko/20100101 Firefox/144.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:144.0) Gecko/144.0 Firefox/144.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/144.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff145, + ff135::build_emulation, + header_initializer_with_zstd, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:145.0) Gecko/20100101 Firefox/145.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:145.0) Gecko/20100101 Firefox/145.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:145.0) Gecko/20100101 Firefox/145.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:145.0) Gecko/145.0 Firefox/145.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/145.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff146, + ff135::build_emulation, + header_initializer_with_zstd, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:146.0) Gecko/20100101 Firefox/146.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:146.0) Gecko/20100101 Firefox/146.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:146.0) Gecko/146.0 Firefox/146.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/146.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff147, + ff135::build_emulation, + header_initializer_with_zstd_q09, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:147.0) Gecko/20100101 Firefox/147.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:147.0) Gecko/147.0 Firefox/147.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/147.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff148, + ff135::build_emulation, + header_initializer_with_zstd_q09, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:148.0) Gecko/20100101 Firefox/148.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:148.0) Gecko/20100101 Firefox/148.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:148.0) Gecko/148.0 Firefox/148.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/148.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff149, + ff135::build_emulation, + header_initializer_with_zstd_q09, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:149.0) Gecko/20100101 Firefox/149.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:149.0) Gecko/20100101 Firefox/149.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:149.0) Gecko/20100101 Firefox/149.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:149.0) Gecko/149.0 Firefox/149.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/149.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff150, + tls_options!(4, CIPHER_LIST_3, CURVES_2, KEY_SHARES_2), + http2_options!(1), + header_initializer_with_zstd_q09, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:150.0) Gecko/20100101 Firefox/150.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:150.0) Gecko/20100101 Firefox/150.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:150.0) Gecko/150.0 Firefox/150.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/150.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff151, + ff150::build_emulation, + header_initializer_with_zstd_q09, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:151.0) Gecko/20100101 Firefox/151.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:151.0) Gecko/20100101 Firefox/151.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:151.0) Gecko/151.0 Firefox/151.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/151.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); + +mod_generator!( + ff152, + ff150::build_emulation, + header_initializer_with_zstd_q09, + [ + ( + Windows, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0" + ), + ( + MacOS, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:152.0) Gecko/20100101 Firefox/152.0" + ), + ( + Linux, + "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:152.0) Gecko/20100101 Firefox/152.0" + ), + ( + Android, + "Mozilla/5.0 (Android 13; Mobile; rv:152.0) Gecko/152.0 Firefox/152.0" + ), + ( + IOS, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/152.0 Mobile/15E148 Safari/605.1.15" + ) + ] +); diff --git a/crates/wreq-util/src/emulate/profile/firefox/header.rs b/crates/wreq-util/src/emulate/profile/firefox/header.rs new file mode 100644 index 0000000..2627180 --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/firefox/header.rs @@ -0,0 +1,59 @@ +use super::*; + +pub fn header_initializer(ua: &'static str) -> HeaderMap { + let mut headers = HeaderMap::new(); + header_firefox_ua!(headers, ua); + header_firefox_accept!(headers); + headers.insert( + HeaderName::from_static("upgrade-insecure-requests"), + HeaderValue::from_static("1"), + ); + header_firefox_sec_fetch!(headers); + headers.insert( + HeaderName::from_static("te"), + HeaderValue::from_static("trailers"), + ); + headers +} + +pub fn header_initializer_with_zstd(ua: &'static str) -> HeaderMap { + let mut headers = HeaderMap::new(); + header_firefox_ua!(headers, ua); + header_firefox_accept!(zstd, headers); + headers.insert( + HeaderName::from_static("upgrade-insecure-requests"), + HeaderValue::from_static("1"), + ); + header_firefox_sec_fetch!(headers); + headers.insert( + HeaderName::from_static("priority"), + HeaderValue::from_static("u=0, i"), + ); + headers.insert( + HeaderName::from_static("te"), + HeaderValue::from_static("trailers"), + ); + headers +} + +/// Firefox 147 and later. Identical to [`header_initializer_with_zstd`] apart from the +/// `Accept-Language` q-value, which Firefox changed in 147 (Bugzilla 2000765). +pub fn header_initializer_with_zstd_q09(ua: &'static str) -> HeaderMap { + let mut headers = HeaderMap::new(); + header_firefox_ua!(headers, ua); + header_firefox_accept!(zstd_q09, headers); + headers.insert( + HeaderName::from_static("upgrade-insecure-requests"), + HeaderValue::from_static("1"), + ); + header_firefox_sec_fetch!(headers); + headers.insert( + HeaderName::from_static("priority"), + HeaderValue::from_static("u=0, i"), + ); + headers.insert( + HeaderName::from_static("te"), + HeaderValue::from_static("trailers"), + ); + headers +} diff --git a/crates/wreq-util/src/emulate/profile/firefox/http2.rs b/crates/wreq-util/src/emulate/profile/firefox/http2.rs new file mode 100644 index 0000000..4c93345 --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/firefox/http2.rs @@ -0,0 +1,113 @@ +macro_rules! headers_priority { + (1) => { + HeadersPriority::new(HeadersDependency::Root, 41, false) + }; + (2) => { + HeadersPriority::new(HeadersDependency::Declared(StreamId::from(13)), 41, false) + }; +} + +macro_rules! pseudo_order { + () => { + PseudoOrder::builder() + .extend([ + PseudoId::Method, + PseudoId::Path, + PseudoId::Authority, + PseudoId::Scheme, + ]) + .build() + }; +} + +macro_rules! settings_order { + () => { + SettingsOrder::builder() + .extend([ + SettingId::HeaderTableSize, + SettingId::EnablePush, + SettingId::MaxConcurrentStreams, + SettingId::InitialWindowSize, + SettingId::MaxFrameSize, + SettingId::MaxHeaderListSize, + SettingId::EnableConnectProtocol, + SettingId::NoRfc7540Priorities, + ]) + .build() + }; +} + +macro_rules! http2_options { + (@base $builder:expr) => { + $builder + .initial_window_size(131072) + .max_frame_size(16384) + .initial_connection_window_size(12517377 + 65535) + .headers_pseudo_order(pseudo_order!()) + .settings_order(settings_order!()) + }; + + (1) => { + http2_options!(@base Http2Options::builder()) + .initial_stream_id(3) + .header_table_size(65536) + .enable_push(false) + .headers_priority(headers_priority!(1)) + .build() + }; + (2) => { + http2_options!(@base Http2Options::builder()) + .initial_stream_id(15) + .header_table_size(65536) + .headers_priority(headers_priority!(2)) + .priorities( + Priorities::builder() + .extend([ + Priority::new( + StreamId::from(3), + StreamDependency::new(StreamId::from(0), 200, false), + ), + Priority::new( + StreamId::from(5), + StreamDependency::new(StreamId::from(0), 100, false), + ), + Priority::new( + StreamId::from(7), + StreamDependency::new(StreamId::from(0), 0, false), + ), + Priority::new( + StreamId::from(9), + StreamDependency::new(StreamId::from(7), 0, false), + ), + Priority::new( + StreamId::from(11), + StreamDependency::new(StreamId::from(3), 0, false), + ), + Priority::new( + StreamId::from(13), + StreamDependency::new(StreamId::from(0), 240, false), + ), + ]) + .build(), + ) + .build() + }; + (3) => { + http2_options!(@base Http2Options::builder()) + .initial_stream_id(3) + .header_table_size(65536) + .enable_push(false) + .max_concurrent_streams(0) + .headers_priority(headers_priority!(1)) + .build() + }; + (4) => { + http2_options!(@base Http2Options::builder()) + .initial_stream_id(3) + .header_table_size(4096) + .enable_push(false) + .initial_window_size(32768) + .headers_priority(headers_priority!(1)) + .build() + }; +} diff --git a/crates/wreq-util/src/emulate/profile/firefox/tls.rs b/crates/wreq-util/src/emulate/profile/firefox/tls.rs new file mode 100644 index 0000000..fb610b3 --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/firefox/tls.rs @@ -0,0 +1,268 @@ +use super::*; + +macro_rules! tls_options { + (@build $builder:expr) => { + $builder.build().into() + }; + + (@base $builder:expr, $cipher_list:expr, $curves:expr) => { + $builder + .cipher_list($cipher_list) + .curves_list($curves) + }; + + (1, $cipher_list:expr, $curves:expr, $key_shares:expr) => { + tls_options!(@build tls_options!(@base FirefoxTlsConfig::builder(), $cipher_list, $curves) + .enable_ech_grease(true) + .pre_shared_key(true) + .psk_skip_session_tickets(true) + .key_shares($key_shares) + .certificate_compressors(CERTIFICATE_COMPRESSORS)) + }; + (2, $cipher_list:expr, $curves:expr) => { + tls_options!(@build tls_options!(@base FirefoxTlsConfig::builder(), $cipher_list, $curves)) + }; + (3, $cipher_list:expr, $curves:expr, $key_shares:expr) => { + tls_options!(@build tls_options!(@base FirefoxTlsConfig::builder(), $cipher_list, $curves) + .session_ticket(false) + .enable_ech_grease(true) + .psk_dhe_ke(false) + .key_shares($key_shares)) + }; + (4, $cipher_list:expr, $curves:expr, $key_shares:expr) => { + tls_options!(@build tls_options!(@base FirefoxTlsConfig::builder(), $cipher_list, $curves) + .enable_ech_grease(true) + .enable_signed_cert_timestamps(true) + .session_ticket(true) + .pre_shared_key(true) + .psk_skip_session_tickets(true) + .key_shares($key_shares) + .certificate_compressors(CERTIFICATE_COMPRESSORS)) + }; + (5, $cipher_list:expr, $curves:expr, $key_shares:expr) => { + tls_options!(@build tls_options!(@base FirefoxTlsConfig::builder(), $cipher_list, $curves) + .enable_ech_grease(true) + .pre_shared_key(true) + .psk_skip_session_tickets(true) + .key_shares($key_shares) + .certificate_compressors(CERTIFICATE_COMPRESSORS)) + }; + (6, $cipher_list:expr, $curves:expr, $key_shares:expr) => { + tls_options!(@build tls_options!(@base FirefoxTlsConfig::builder(), $cipher_list, $curves) + .enable_ech_grease(true) + .enable_signed_cert_timestamps(true) + .session_ticket(false) + .psk_dhe_ke(false) + .key_shares($key_shares) + .certificate_compressors(CERTIFICATE_COMPRESSORS)) + }; +} + +pub const CURVES_1: &str = join!( + ":", + "X25519", + "P-256", + "P-384", + "P-521", + "ffdhe2048", + "ffdhe3072" +); + +pub const CURVES_2: &str = join!( + ":", + "X25519MLKEM768", + "X25519", + "P-256", + "P-384", + "P-521", + "ffdhe2048", + "ffdhe3072" +); + +pub const KEY_SHARES_1: &[KeyShare] = &[KeyShare::X25519, KeyShare::P256]; + +pub const KEY_SHARES_2: &[KeyShare] = + &[KeyShare::X25519_MLKEM768, KeyShare::X25519, KeyShare::P256]; + +pub const CIPHER_LIST_1: &str = join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA" +); + +pub const CIPHER_LIST_2: &str = join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA" +); + +pub const CIPHER_LIST_3: &str = join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA" +); + +pub const SIGALGS_LIST: &str = join!( + ":", + "ecdsa_secp256r1_sha256", + "ecdsa_secp384r1_sha384", + "ecdsa_secp521r1_sha512", + "rsa_pss_rsae_sha256", + "rsa_pss_rsae_sha384", + "rsa_pss_rsae_sha512", + "rsa_pkcs1_sha256", + "rsa_pkcs1_sha384", + "rsa_pkcs1_sha512", + "ecdsa_sha1", + "rsa_pkcs1_sha1" +); + +pub const TLS13_CIPHER_LIST: &[Tls13Cipher] = &[ + Tls13Cipher::AES_128_GCM_SHA256, + Tls13Cipher::CHACHA20_POLY1305_SHA256, + Tls13Cipher::AES_256_GCM_SHA384, +]; + +pub const CERTIFICATE_COMPRESSORS: &[&'static dyn CertificateCompressor] = + &[&ZlibCompressor, &BrotliCompressor, &ZstdCompressor]; + +pub const DELEGATED_CREDENTIALS: &str = join!( + ":", + "ecdsa_secp256r1_sha256", + "ecdsa_secp384r1_sha384", + "ecdsa_secp521r1_sha512", + "ecdsa_sha1" +); + +pub const RECORD_SIZE_LIMIT: u16 = 0x4001; + +pub const EXTENSION_PERMUTATION_INDICES: &[ExtensionType] = &[ + ExtensionType::SERVER_NAME, + ExtensionType::EXTENDED_MASTER_SECRET, + ExtensionType::RENEGOTIATE, + ExtensionType::SUPPORTED_GROUPS, + ExtensionType::EC_POINT_FORMATS, + ExtensionType::SESSION_TICKET, + ExtensionType::APPLICATION_LAYER_PROTOCOL_NEGOTIATION, + ExtensionType::STATUS_REQUEST, + ExtensionType::DELEGATED_CREDENTIAL, + ExtensionType::CERTIFICATE_TIMESTAMP, + ExtensionType::KEY_SHARE, + ExtensionType::SUPPORTED_VERSIONS, + ExtensionType::SIGNATURE_ALGORITHMS, + ExtensionType::PSK_KEY_EXCHANGE_MODES, + ExtensionType::RECORD_SIZE_LIMIT, + ExtensionType::CERT_COMPRESSION, + ExtensionType::ENCRYPTED_CLIENT_HELLO, +]; + +#[derive(TypedBuilder)] +pub struct FirefoxTlsConfig { + #[builder(default = SIGALGS_LIST)] + sigalgs_list: &'static str, + + #[builder(setter(into))] + cipher_list: &'static str, + + #[builder(setter(into))] + curves_list: &'static str, + + #[builder(default, setter(into))] + key_shares: Option<&'static [KeyShare]>, + + #[builder(default = true)] + session_ticket: bool, + + #[builder(default = false, setter(into))] + enable_ech_grease: bool, + + #[builder(default = false, setter(into))] + enable_signed_cert_timestamps: bool, + + #[builder(default = false, setter(into))] + pre_shared_key: bool, + + #[builder(default = false, setter(into))] + psk_skip_session_tickets: bool, + + #[builder(default = DELEGATED_CREDENTIALS, setter(into))] + delegated_credentials: &'static str, + + #[builder(default = RECORD_SIZE_LIMIT, setter(into))] + record_size_limit: u16, + + #[builder(default = true, setter(into))] + psk_dhe_ke: bool, + + #[builder(default, setter(into))] + certificate_compressors: Option<&'static [&'static dyn CertificateCompressor]>, + + #[builder(default = EXTENSION_PERMUTATION_INDICES, setter(into))] + extension_permutation: &'static [ExtensionType], +} + +impl From for TlsOptions { + fn from(val: FirefoxTlsConfig) -> Self { + let mut builder = TlsOptions::builder() + .curves_list(val.curves_list) + .sigalgs_list(val.sigalgs_list) + .cipher_list(val.cipher_list) + .tls13_cipher_list(TLS13_CIPHER_LIST) + .session_ticket(val.session_ticket) + .delegated_credentials(val.delegated_credentials) + .record_size_limit(val.record_size_limit) + .enable_ocsp_stapling(true) + .ech_grease(val.enable_ech_grease.then_some(EchGrease::NssPre3127)) + .enable_signed_cert_timestamps(val.enable_signed_cert_timestamps) + .alpn_protocols([AlpnProtocol::HTTP2, AlpnProtocol::HTTP1]) + .min_tls_version(TlsVersion::TLS_1_2) + .max_tls_version(TlsVersion::TLS_1_3) + .pre_shared_key(val.pre_shared_key) + .psk_skip_session_ticket(val.psk_skip_session_tickets) + .psk_dhe_ke(val.psk_dhe_ke) + .extension_permutation(val.extension_permutation); + + if let Some(key_shares) = val.key_shares { + builder = builder.key_shares(key_shares) + } + + if let Some(certificate_compressors) = val.certificate_compressors { + builder = builder.certificate_compressors(certificate_compressors) + } + + builder.build() + } +} diff --git a/crates/wreq-util/src/emulate/profile/okhttp.rs b/crates/wreq-util/src/emulate/profile/okhttp.rs new file mode 100644 index 0000000..6507f7a --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/okhttp.rs @@ -0,0 +1,235 @@ +use super::*; + +const CURVES: &str = join!(":", "X25519", "P-256", "P-384"); + +const SIGALGS_LIST: &str = join!( + ":", + "ecdsa_secp256r1_sha256", + "rsa_pss_rsae_sha256", + "rsa_pkcs1_sha256", + "ecdsa_secp384r1_sha384", + "rsa_pss_rsae_sha384", + "rsa_pkcs1_sha384", + "rsa_pss_rsae_sha512", + "rsa_pkcs1_sha512", + "rsa_pkcs1_sha1" +); + +const CIPHER_LIST: &str = join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_3DES_EDE_CBC_SHA" +); + +const TLS13_CIPHER_LIST: &[Tls13Cipher] = &[ + Tls13Cipher::AES_128_GCM_SHA256, + Tls13Cipher::AES_256_GCM_SHA384, + Tls13Cipher::CHACHA20_POLY1305_SHA256, +]; + +#[derive(TypedBuilder)] +struct OkHttpTlsConfig { + #[builder(default = CURVES)] + curves: &'static str, + + #[builder(default = SIGALGS_LIST)] + sigalgs_list: &'static str, + + cipher_list: &'static str, +} + +impl From for TlsOptions { + fn from(val: OkHttpTlsConfig) -> Self { + TlsOptions::builder() + .enable_ocsp_stapling(true) + .curves_list(val.curves) + .sigalgs_list(val.sigalgs_list) + .cipher_list(val.cipher_list) + .tls13_cipher_list(TLS13_CIPHER_LIST) + .min_tls_version(TlsVersion::TLS_1_2) + .max_tls_version(TlsVersion::TLS_1_3) + .build() + } +} + +macro_rules! mod_generator { + ($mod_name:ident, $cipher:expr, $ua:expr) => { + pub(crate) mod $mod_name { + use super::*; + + pub fn emulation(emulation: Emulation) -> wreq::Emulation { + build_emulation(emulation, $cipher, $ua) + } + } + }; +} + +fn build_emulation( + emulation: Emulation, + cipher_list: &'static str, + user_agent: &'static str, +) -> wreq::Emulation { + let tls_options = OkHttpTlsConfig::builder() + .cipher_list(cipher_list) + .build() + .into(); + + let http2_options = emulation.http2.then(|| { + let settings_order = SettingsOrder::builder() + .extend([ + SettingId::HeaderTableSize, + SettingId::EnablePush, + SettingId::MaxConcurrentStreams, + SettingId::InitialWindowSize, + SettingId::MaxFrameSize, + SettingId::MaxHeaderListSize, + SettingId::EnableConnectProtocol, + SettingId::NoRfc7540Priorities, + ]) + .build(); + + Http2Options::builder() + .initial_window_size(16777216) + .initial_connection_window_size(16777216) + .headers_pseudo_order( + PseudoOrder::builder() + .extend([ + PseudoId::Method, + PseudoId::Path, + PseudoId::Authority, + PseudoId::Scheme, + ]) + .build(), + ) + .settings_order(settings_order) + .build() + }); + + let headers = emulation.headers.then(|| { + let mut headers = HeaderMap::new(); + headers.insert(ACCEPT, HeaderValue::from_static("*/*")); + headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9")); + headers.insert(USER_AGENT, HeaderValue::from_static(user_agent)); + #[cfg(feature = "emulation-compression")] + headers.insert(ACCEPT_ENCODING, HeaderValue::from_static("gzip")); + headers + }); + + build_standard_emulation(tls_options, http2_options, headers) +} + +mod_generator!( + okhttp3_9, + join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_3DES_EDE_CBC_SHA" + ), + "MaiMemo/4.4.50_639 okhttp/3.9 Android/5.0 Channel/WanDouJia Device/alps+M8+Emulator (armeabi-v7a) Screen/4.44 Resolution/480x800 DId/aa6cde19def3806806d5374c4e5fd617 RAM/0.94 ROM/4.91 Theme/Day" +); + +mod_generator!( + okhttp3_11, + join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_3DES_EDE_CBC_SHA" + ), + "NRC Audio/2.0.6 (nl.nrc.audio; build:36; Android 12; Sdk:31; Manufacturer:motorola; Model: moto g72) OkHttp/3.11.0" +); + +mod_generator!( + okhttp3_13, + join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_3DES_EDE_CBC_SHA" + ), + "GM-Android/6.112.2 (240590300; M:Google Pixel 7a; O:34; D:2b045e03986fa6dc) ObsoleteUrlFactory/1.0 OkHttp/3.13.0" +); + +mod_generator!( + okhttp3_14, + CIPHER_LIST, + "DS podcast/2.0.1 (be.standaard.audio; build:9; Android 11; Sdk:30; Manufacturer:samsung; Model: SM-A405FN) OkHttp/3.14.0" +); + +mod_generator!( + okhttp4_10, + CIPHER_LIST, + "GM-Android/6.112.2 (240590300; M:samsung SM-G781U1; O:33; D:edb34792871638d8) ObsoleteUrlFactory/1.0 OkHttp/4.10.0" +); + +mod_generator!( + okhttp4_9, + join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA" + ), + "GM-Android/6.111.1 (240460200; M:motorola moto g power (2021); O:30; D:76ba9f6628d198c8) ObsoleteUrlFactory/1.0 OkHttp/4.9" +); + +mod_generator!(okhttp4_12, CIPHER_LIST, "okhttp/4.12.0"); + +mod_generator!( + okhttp5, + CIPHER_LIST, + "NRC Audio/2.0.6 (nl.nrc.audio; build:36; Android 14; Sdk:34; Manufacturer:OnePlus; Model: CPH2609) OkHttp/5.0.0-alpha2" +); diff --git a/crates/wreq-util/src/emulate/profile/opera.rs b/crates/wreq-util/src/emulate/profile/opera.rs new file mode 100644 index 0000000..c751d39 --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/opera.rs @@ -0,0 +1,299 @@ +#[macro_use] +mod http2; +#[macro_use] +mod tls; +mod header; + +use header::*; +use tls::*; + +use super::*; + +mod_generator!( + opera116, + tls_options!(CURVES), + http2_options!(), + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Opera";v="116", "Chromium";v="131", "Not_A Brand";v="24""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 OPR/116.0.0.0" + ), + ( + Windows, + r#""Opera";v="116", "Chromium";v="131", "Not_A Brand";v="24""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 OPR/116.0.0.0" + ) + ] +); + +mod_generator!( + opera117, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not A(Brand";v="8", "Chromium";v="132", "Opera";v="117""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 OPR/117.0.0.0" + ), + ( + Windows, + r#""Not A(Brand";v="8", "Chromium";v="132", "Opera";v="117""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 OPR/117.0.0.0" + ) + ] +); + +mod_generator!( + opera118, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not(A:Brand";v="99", "Opera";v="118", "Chromium";v="133""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 OPR/118.0.0.0" + ), + ( + Windows, + r#""Not(A:Brand";v="99", "Opera";v="118", "Chromium";v="133""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 OPR/118.0.0.0" + ) + ] +); + +mod_generator!( + opera119, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="134", "Not:A-Brand";v="24", "Opera";v="119""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 OPR/119.0.0.0" + ), + ( + Windows, + r#""Chromium";v="134", "Not:A-Brand";v="24", "Opera";v="119""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 OPR/119.0.0.0" + ) + ] +); + +mod_generator!( + opera120, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="135", "Not:A-Brand";v="24", "Opera";v="120""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 OPR/120.0.0.0" + ), + ( + Windows, + r#""Chromium";v="135", "Not:A-Brand";v="24", "Opera";v="120""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 OPR/120.0.0.0" + ) + ] +); + +mod_generator!( + opera121, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Opera";v="121", "Chromium";v="137", "Not/A)Brand";v="24""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 OPR/121.0.0.0" + ), + ( + Windows, + r#""Opera";v="121", "Chromium";v="137", "Not/A)Brand";v="24""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 OPR/121.0.0.0" + ) + ] +); + +mod_generator!( + opera122, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="138", "Not=A?Brand";v="24", "Opera";v="122""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 OPR/122.0.0.0" + ), + ( + Windows, + r#""Chromium";v="138", "Not=A?Brand";v="24", "Opera";v="122""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 OPR/122.0.0.0" + ) + ] +); + +mod_generator!( + opera123, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="139", "Not=A?Brand";v="24", "Opera";v="123""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 OPR/123.0.0.0" + ), + ( + Windows, + r#""Chromium";v="139", "Not=A?Brand";v="24", "Opera";v="123""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 OPR/123.0.0.0" + ) + ] +); + +mod_generator!( + opera124, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Chromium";v="140", "Not=A?Brand";v="24", "Opera";v="124""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 OPR/124.0.0.0" + ), + ( + Windows, + r#""Chromium";v="140", "Not=A?Brand";v="24", "Opera";v="124""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 OPR/124.0.0.0" + ) + ] +); + +mod_generator!( + opera125, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Opera";v="125", "Not?A_Brand";v="8", "Chromium";v="141""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 OPR/125.0.0.0" + ), + ( + Windows, + r#""Opera";v="125", "Not?A_Brand";v="8", "Chromium";v="141""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 OPR/125.0.0.0" + ) + ] +); + +mod_generator!( + opera126, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not:A-Brand";v="99", "Opera";v="126", "Chromium";v="142""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 OPR/126.0.0.0" + ), + ( + Windows, + r#""Not:A-Brand";v="99", "Opera";v="126", "Chromium";v="142""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 OPR/126.0.0.0" + ) + ] +); + +mod_generator!( + opera127, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not:A-Brand";v="99", "Opera";v="127", "Chromium";v="143""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 OPR/127.0.0.0" + ), + ( + Windows, + r#""Not:A-Brand";v="99", "Opera";v="127", "Chromium";v="143""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 OPR/127.0.0.0" + ) + ] +); + +mod_generator!( + opera128, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not:A-Brand";v="99", "Opera";v="128", "Chromium";v="144""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 OPR/128.0.0.0" + ), + ( + Windows, + r#""Not:A-Brand";v="99", "Opera";v="128", "Chromium";v="144""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 OPR/128.0.0.0" + ) + ] +); + +mod_generator!( + opera129, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not:A-Brand";v="99", "Opera";v="129", "Chromium";v="145""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 OPR/129.0.0.0" + ), + ( + Windows, + r#""Not:A-Brand";v="99", "Opera";v="129", "Chromium";v="145""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 OPR/129.0.0.0" + ) + ] +); + +mod_generator!( + opera130, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Not:A-Brand";v="99", "Opera";v="130", "Chromium";v="146""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 OPR/130.0.0.0" + ), + ( + Windows, + r#""Not:A-Brand";v="99", "Opera";v="130", "Chromium";v="146""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 OPR/130.0.0.0" + ) + ] +); + +mod_generator!( + opera131, + opera116::build_emulation, + header_initializer_with_zstd_priority, + [ + ( + MacOS, + r#""Opera";v="131", "Not.A/Brand";v="8", "Chromium";v="147""#, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 OPR/131.0.0.0" + ), + ( + Windows, + r#""Opera";v="131", "Not.A/Brand";v="8", "Chromium";v="147""#, + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 OPR/131.0.0.0" + ) + ] +); diff --git a/crates/wreq-util/src/emulate/profile/opera/header.rs b/crates/wreq-util/src/emulate/profile/opera/header.rs new file mode 100644 index 0000000..6a7a77f --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/opera/header.rs @@ -0,0 +1,29 @@ +use super::*; + +#[inline] +pub fn header_initializer_with_zstd_priority( + sec_ch_ua: &'static str, + ua: &'static str, + emulation_os: Platform, +) -> HeaderMap { + let mut headers = HeaderMap::new(); + header_chrome_sec_ch_ua!( + headers, + sec_ch_ua, + emulation_os.platform(), + emulation_os.is_mobile() + ); + headers.insert( + HeaderName::from_static("upgrade-insecure-requests"), + HeaderValue::from_static("1"), + ); + header_chrome_ua!(headers, ua); + header_chrome_accept!(headers); + header_chrome_sec_fetch!(headers); + header_chrome_accept_encoding!(zstd, headers); + headers.insert( + HeaderName::from_static("priority"), + HeaderValue::from_static("u=0, i"), + ); + headers +} diff --git a/crates/wreq-util/src/emulate/profile/opera/http2.rs b/crates/wreq-util/src/emulate/profile/opera/http2.rs new file mode 100644 index 0000000..ddc27dd --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/opera/http2.rs @@ -0,0 +1,50 @@ +macro_rules! headers_priority { + () => { + HeadersPriority::new(HeadersDependency::Root, 255, true) + }; +} + +macro_rules! pseudo_order { + () => { + PseudoOrder::builder() + .extend([ + PseudoId::Method, + PseudoId::Authority, + PseudoId::Scheme, + PseudoId::Path, + ]) + .build() + }; +} + +macro_rules! settings_order { + () => { + SettingsOrder::builder() + .extend([ + SettingId::HeaderTableSize, + SettingId::EnablePush, + SettingId::MaxConcurrentStreams, + SettingId::InitialWindowSize, + SettingId::MaxFrameSize, + SettingId::MaxHeaderListSize, + SettingId::EnableConnectProtocol, + SettingId::NoRfc7540Priorities, + ]) + .build() + }; +} + +macro_rules! http2_options { + () => { + Http2Options::builder() + .initial_window_size(6291456) + .initial_connection_window_size(15728640) + .max_header_list_size(262144) + .header_table_size(65536) + .enable_push(false) + .headers_priority(headers_priority!()) + .headers_pseudo_order(pseudo_order!()) + .settings_order(settings_order!()) + .build() + }; +} diff --git a/crates/wreq-util/src/emulate/profile/opera/tls.rs b/crates/wreq-util/src/emulate/profile/opera/tls.rs new file mode 100644 index 0000000..b1cbf4d --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/opera/tls.rs @@ -0,0 +1,103 @@ +use super::*; + +macro_rules! tls_options { + ($curves:expr) => { + OperaTlsConfig::builder() + .curves($curves) + .permute_extensions(true) + .pre_shared_key(true) + .enable_ech_grease(true) + .build() + .into() + }; +} + +pub const CURVES: &str = join!(":", "X25519MLKEM768", "X25519", "P-256", "P-384"); + +pub const CIPHER_LIST: &str = join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA" +); + +pub const TLS13_CIPHER_LIST: &[Tls13Cipher] = &[ + Tls13Cipher::AES_128_GCM_SHA256, + Tls13Cipher::AES_256_GCM_SHA384, + Tls13Cipher::CHACHA20_POLY1305_SHA256, +]; + +pub const SIGALGS_LIST: &str = join!( + ":", + "ecdsa_secp256r1_sha256", + "rsa_pss_rsae_sha256", + "rsa_pkcs1_sha256", + "ecdsa_secp384r1_sha384", + "rsa_pss_rsae_sha384", + "rsa_pkcs1_sha384", + "rsa_pss_rsae_sha512", + "rsa_pkcs1_sha512" +); + +pub const CERTIFICATE_COMPRESSORS: &[&'static dyn CertificateCompressor] = &[&BrotliCompressor]; + +#[derive(TypedBuilder)] +pub struct OperaTlsConfig { + #[builder(default = CURVES)] + curves: &'static str, + + #[builder(default = SIGALGS_LIST)] + sigalgs_list: &'static str, + + #[builder(default = CIPHER_LIST)] + cipher_list: &'static str, + + #[builder(default = AlpsProtocol::HTTP2, setter(into))] + alps_protos: AlpsProtocol, + + #[builder(default = false)] + alps_use_new_codepoint: bool, + + #[builder(default = false, setter(into))] + enable_ech_grease: bool, + + #[builder(default = false, setter(into))] + permute_extensions: bool, + + #[builder(default = false, setter(into))] + pre_shared_key: bool, +} + +impl From for TlsOptions { + fn from(val: OperaTlsConfig) -> Self { + TlsOptions::builder() + .grease_enabled(true) + .enable_ocsp_stapling(true) + .enable_signed_cert_timestamps(true) + .curves_list(val.curves) + .sigalgs_list(val.sigalgs_list) + .cipher_list(val.cipher_list) + .tls13_cipher_list(TLS13_CIPHER_LIST) + .min_tls_version(TlsVersion::TLS_1_2) + .max_tls_version(TlsVersion::TLS_1_3) + .permute_extensions(val.permute_extensions) + .pre_shared_key(val.pre_shared_key) + .ech_grease( + val.enable_ech_grease + .then_some(EchGrease::Aead(EchGreaseAead::AES_128_GCM)), + ) + .alps_protocols([val.alps_protos]) + .alps_use_new_codepoint(val.alps_use_new_codepoint) + .certificate_compressors(CERTIFICATE_COMPRESSORS) + .build() + } +} diff --git a/crates/wreq-util/src/emulate/profile/safari.rs b/crates/wreq-util/src/emulate/profile/safari.rs new file mode 100644 index 0000000..69ac983 --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/safari.rs @@ -0,0 +1,222 @@ +#[macro_use] +mod http2; +#[macro_use] +mod tls; +mod header; + +use header::*; +use tls::*; + +use super::*; + +mod_generator!( + safari15_3, + tls_options!(1, CIPHER_LIST_1), + http2_options!(4), + header_initializer_for_15, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Safari/605.1.15" +); + +mod_generator!( + safari15_5, + safari15_3::build_emulation, + header_initializer_for_15, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Safari/605.1.15" +); + +mod_generator!( + safari15_6_1, + tls_options!(1, CIPHER_LIST_2), + http2_options!(4), + header_initializer_for_15, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15" +); + +mod_generator!( + safari16, + safari15_6_1::build_emulation, + header_initializer_for_16_17, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15" +); + +mod_generator!( + safari16_5, + safari15_6_1::build_emulation, + header_initializer_for_16_17, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15" +); + +mod_generator!( + safari17_4_1, + safari15_6_1::build_emulation, + header_initializer_for_16_17, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15" +); + +mod_generator!( + safari_ios_16_5, + tls_options!(1, CIPHER_LIST_2), + http2_options!(1), + header_initializer_for_16_17, + "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1" +); + +mod_generator!( + safari17_0, + tls_options!(1, CIPHER_LIST_2), + http2_options!(5), + header_initializer_for_16_17, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15" +); + +mod_generator!( + safari17_2_1, + safari17_0::build_emulation, + header_initializer_for_16_17, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15" +); + +mod_generator!( + safari17_5, + safari17_0::build_emulation, + header_initializer_for_16_17, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15" +); + +mod_generator!( + safari17_6, + safari17_0::build_emulation, + header_initializer_for_16_17, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15" +); + +mod_generator!( + safari_ios_17_2, + tls_options!(1, CIPHER_LIST_2), + http2_options!(2), + header_initializer_for_16_17, + "Mozilla/5.0 (iPhone; CPU iPhone OS 17_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Mobile/15E148 Safari/604.1" +); + +mod_generator!( + safari_ios_17_4_1, + safari_ios_17_2::build_emulation, + header_initializer_for_16_17, + "Mozilla/5.0 (iPad; CPU OS 17_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Mobile/15E148 Safari/604.1" +); + +mod_generator!( + safari18, + tls_options!(1, CIPHER_LIST_2), + http2_options!(3), + header_initializer_for_18, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15" +); + +mod_generator!( + safari_ipad_18, + safari18::build_emulation, + header_initializer_for_18, + "Mozilla/5.0 (iPad; CPU OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1" +); + +mod_generator!( + safari_ios_18_1_1, + safari18::build_emulation, + header_initializer_for_18, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1.1 Mobile/15E148 Safari/604.1" +); + +mod_generator!( + safari18_2, + tls_options!(2, CIPHER_LIST_2, SIGALGS_LIST_2), + http2_options!(3), + header_initializer_for_18, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Safari/605.1.15" +); + +mod_generator!( + safari18_3, + safari18_2::build_emulation, + header_initializer_for_18, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15" +); + +mod_generator!( + safari18_3_1, + safari18_2::build_emulation, + header_initializer_for_18, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3.1 Safari/605.1.15" +); + +mod_generator!( + safari18_5, + tls_options!(2, CIPHER_LIST_2, SIGALGS_LIST_2), + http2_options!(6), + header_initializer_for_18, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15" +); + +mod_generator!( + safari26, + tls_options!(3, CIPHER_LIST_3, SIGALGS_LIST_2, CURVES_2), + http2_options!(6), + header_initializer_for_18, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Safari/605.1.15" +); + +mod_generator!( + safari_ipad_26, + safari26::build_emulation, + header_initializer_for_18, + "Mozilla/5.0 (iPad; CPU OS 18_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Mobile/15E148 Safari/604.1" +); + +mod_generator!( + safari_ios_26, + safari26::build_emulation, + header_initializer_for_18, + "Mozilla/5.0 (iPhone; CPU iPhone OS 26_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Mobile/15E148 Safari/604.1" +); + +mod_generator!( + safari26_1, + safari18_5::build_emulation, + header_initializer_for_18, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15" +); + +mod_generator!( + safari_ios_26_2, + safari26::build_emulation, + header_initializer_for_18, + "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.2 Mobile/15E148 Safari/604.1" +); + +mod_generator!( + safari26_2, + safari18_5::build_emulation, + header_initializer_for_18, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.2 Safari/605.1.15" +); + +mod_generator!( + safari26_3, + safari18_5::build_emulation, + header_initializer_for_18, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Safari/605.1.15" +); + +mod_generator!( + safari26_4, + safari18_5::build_emulation, + header_initializer_for_18, + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.4 Safari/605.1.15" +); + +mod_generator!( + safari_ipad_26_2, + safari26::build_emulation, + header_initializer_for_18, + "Mozilla/5.0 (iPad; CPU OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.2 Mobile/15E148 Safari/604.1" +); diff --git a/crates/wreq-util/src/emulate/profile/safari/header.rs b/crates/wreq-util/src/emulate/profile/safari/header.rs new file mode 100644 index 0000000..aef337c --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/safari/header.rs @@ -0,0 +1,59 @@ +use super::*; + +#[inline] +pub fn header_initializer_for_15(ua: &'static str) -> HeaderMap { + let mut headers = HeaderMap::new(); + headers.insert(USER_AGENT, HeaderValue::from_static(ua)); + headers.insert( + ACCEPT, + HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), + ); + headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9")); + #[cfg(feature = "emulation-compression")] + headers.insert( + ACCEPT_ENCODING, + HeaderValue::from_static("gzip, deflate, br"), + ); + headers +} + +#[inline] +pub fn header_initializer_for_16_17(ua: &'static str) -> HeaderMap { + let mut headers = HeaderMap::new(); + headers.insert( + ACCEPT, + HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), + ); + headers.insert("sec-fetch-site", HeaderValue::from_static("none")); + #[cfg(feature = "emulation-compression")] + headers.insert( + ACCEPT_ENCODING, + HeaderValue::from_static("gzip, deflate, br"), + ); + headers.insert("sec-fetch-mode", HeaderValue::from_static("navigate")); + headers.insert(USER_AGENT, HeaderValue::from_static(ua)); + headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9")); + headers.insert("sec-fetch-dest", HeaderValue::from_static("document")); + headers +} + +#[inline] +pub fn header_initializer_for_18(ua: &'static str) -> HeaderMap { + let mut headers = HeaderMap::new(); + headers.insert("sec-fetch-dest", HeaderValue::from_static("document")); + headers.insert(USER_AGENT, HeaderValue::from_static(ua)); + headers.insert( + ACCEPT, + HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), + ); + headers.insert("sec-fetch-site", HeaderValue::from_static("none")); + headers.insert("sec-fetch-mode", HeaderValue::from_static("navigate")); + headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9")); + headers.insert("priority", HeaderValue::from_static("u=0, i")); + #[cfg(feature = "emulation-compression")] + headers.insert( + ACCEPT_ENCODING, + HeaderValue::from_static("gzip, deflate, br"), + ); + headers +} diff --git a/crates/wreq-util/src/emulate/profile/safari/http2.rs b/crates/wreq-util/src/emulate/profile/safari/http2.rs new file mode 100644 index 0000000..e900864 --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/safari/http2.rs @@ -0,0 +1,116 @@ +macro_rules! headers_pseudo_order { + (1) => { + PseudoOrder::builder() + .extend([ + PseudoId::Method, + PseudoId::Scheme, + PseudoId::Path, + PseudoId::Authority, + ]) + .build() + }; + (2) => { + PseudoOrder::builder() + .extend([ + PseudoId::Method, + PseudoId::Scheme, + PseudoId::Authority, + PseudoId::Path, + ]) + .build() + }; +} + +macro_rules! settings_order { + (1) => { + SettingsOrder::builder() + .extend([ + SettingId::HeaderTableSize, + SettingId::EnablePush, + SettingId::InitialWindowSize, + SettingId::MaxConcurrentStreams, + SettingId::MaxFrameSize, + SettingId::MaxHeaderListSize, + SettingId::EnableConnectProtocol, + SettingId::NoRfc7540Priorities, + ]) + .build() + }; + (2) => { + SettingsOrder::builder() + .extend([ + SettingId::HeaderTableSize, + SettingId::EnablePush, + SettingId::MaxConcurrentStreams, + SettingId::InitialWindowSize, + SettingId::MaxFrameSize, + SettingId::MaxHeaderListSize, + SettingId::EnableConnectProtocol, + SettingId::NoRfc7540Priorities, + ]) + .build() + }; +} + +macro_rules! http2_options { + (@base $builder:expr) => { + $builder + .max_concurrent_streams(100) + }; + + (1) => { + http2_options!(@base Http2Options::builder()) + .initial_window_size(2097152) + .initial_connection_window_size(10551295) + .headers_pseudo_order(headers_pseudo_order!(1)) + .settings_order(settings_order!(1)) + .build() + }; + (2) => { + http2_options!(@base Http2Options::builder()) + .initial_window_size(2097152) + .initial_connection_window_size(10551295) + .enable_push(false) + .headers_pseudo_order(headers_pseudo_order!(1)) + .settings_order(settings_order!(1)) + .build() + }; + (3) => { + http2_options!(@base Http2Options::builder()) + .initial_window_size(2097152) + .initial_connection_window_size(10485760) + .enable_push(false) + .enable_connect_protocol(true) + .no_rfc7540_priorities(true) + .headers_pseudo_order(headers_pseudo_order!(2)) + .settings_order(settings_order!(2)) + .build() + }; + (4) => { + http2_options!(@base Http2Options::builder()) + .initial_window_size(4194304) + .initial_connection_window_size(10551295) + .headers_pseudo_order(headers_pseudo_order!(1)) + .settings_order(settings_order!(1)) + .build() + }; + (5) => { + http2_options!(@base Http2Options::builder()) + .initial_window_size(4194304) + .initial_connection_window_size(10551295) + .enable_push(false) + .headers_pseudo_order(headers_pseudo_order!(1)) + .settings_order(settings_order!(1)) + .build() + }; + (6) => { + http2_options!(@base Http2Options::builder()) + .initial_window_size(2097152) + .initial_connection_window_size(10485760) + .enable_push(false) + .no_rfc7540_priorities(true) + .headers_pseudo_order(headers_pseudo_order!(2)) + .settings_order(settings_order!(2)) + .build() + }; +} diff --git a/crates/wreq-util/src/emulate/profile/safari/tls.rs b/crates/wreq-util/src/emulate/profile/safari/tls.rs new file mode 100644 index 0000000..a495a14 --- /dev/null +++ b/crates/wreq-util/src/emulate/profile/safari/tls.rs @@ -0,0 +1,176 @@ +use super::*; + +macro_rules! tls_options { + (1, $cipher_list:expr) => { + SafariTlsConfig::builder() + .cipher_list($cipher_list) + .build() + .into() + }; + (2, $cipher_list:expr, $sigalgs_list:expr) => { + SafariTlsConfig::builder() + .cipher_list($cipher_list) + .sigalgs_list($sigalgs_list) + .build() + .into() + }; + (3, $cipher_list:expr, $sigalgs_list:expr, $curves:expr) => { + SafariTlsConfig::builder() + .curves($curves) + .cipher_list($cipher_list) + .sigalgs_list($sigalgs_list) + .tls13_cipher_list(TLS13_CIPHER_LIST) + .min_tls_version(wreq::tls::TlsVersion::TLS_1_2) + .max_tls_version(wreq::tls::TlsVersion::TLS_1_3) + .build() + .into() + }; +} + +pub const CURVES_1: &str = join!(":", "X25519", "P-256", "P-384", "P-521"); + +pub const CURVES_2: &str = join!(":", "X25519MLKEM768", "X25519", "P-256", "P-384", "P-521"); + +pub const CIPHER_LIST_1: &str = join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_CBC_SHA256", + "TLS_RSA_WITH_AES_128_CBC_SHA256", + "TLS_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA", + "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", + "TLS_RSA_WITH_3DES_EDE_CBC_SHA" +); +pub const CIPHER_LIST_2: &str = join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA", + "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", + "TLS_RSA_WITH_3DES_EDE_CBC_SHA" +); +pub const CIPHER_LIST_3: &str = join!( + ":", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA", + "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", + "TLS_RSA_WITH_3DES_EDE_CBC_SHA" +); + +pub const TLS13_CIPHER_LIST: &[Tls13Cipher] = &[ + Tls13Cipher::AES_256_GCM_SHA384, + Tls13Cipher::CHACHA20_POLY1305_SHA256, + Tls13Cipher::AES_128_GCM_SHA256, +]; + +pub const SIGALGS_LIST_1: &str = join!( + ":", + "ecdsa_secp256r1_sha256", + "rsa_pss_rsae_sha256", + "rsa_pkcs1_sha256", + "ecdsa_secp384r1_sha384", + "ecdsa_sha1", + "rsa_pss_rsae_sha384", + "rsa_pss_rsae_sha384", + "rsa_pkcs1_sha384", + "rsa_pss_rsae_sha512", + "rsa_pkcs1_sha512", + "rsa_pkcs1_sha1" +); + +pub const SIGALGS_LIST_2: &str = join!( + ":", + "ecdsa_secp256r1_sha256", + "rsa_pss_rsae_sha256", + "rsa_pkcs1_sha256", + "ecdsa_secp384r1_sha384", + "rsa_pss_rsae_sha384", + "rsa_pss_rsae_sha384", + "rsa_pkcs1_sha384", + "rsa_pss_rsae_sha512", + "rsa_pkcs1_sha512", + "rsa_pkcs1_sha1" +); + +pub const CERTIFICATE_COMPRESSORS: &[&'static dyn CertificateCompressor] = &[&ZlibCompressor]; + +#[derive(TypedBuilder)] +pub struct SafariTlsConfig { + #[builder(default = TlsVersion::TLS_1_0)] + min_tls_version: TlsVersion, + + #[builder(default = TlsVersion::TLS_1_3)] + max_tls_version: TlsVersion, + + #[builder(default = CURVES_1)] + curves: &'static str, + + #[builder(default = SIGALGS_LIST_1)] + sigalgs_list: &'static str, + + cipher_list: &'static str, + + #[builder(default, setter(strip_option))] + tls13_cipher_list: Option<&'static [Tls13Cipher]>, +} + +impl From for TlsOptions { + fn from(val: SafariTlsConfig) -> Self { + let mut builder = TlsOptions::builder() + .session_ticket(false) + .grease_enabled(true) + .enable_ocsp_stapling(true) + .enable_signed_cert_timestamps(true) + .curves_list(val.curves) + .sigalgs_list(val.sigalgs_list) + .cipher_list(val.cipher_list) + .min_tls_version(val.min_tls_version) + .max_tls_version(val.max_tls_version) + .certificate_compressors(CERTIFICATE_COMPRESSORS); + if let Some(ciphers) = val.tls13_cipher_list { + builder = builder.tls13_cipher_list(ciphers); + } + builder.build() + } +} diff --git a/crates/wreq-util/src/lib.rs b/crates/wreq-util/src/lib.rs new file mode 100644 index 0000000..03a68e6 --- /dev/null +++ b/crates/wreq-util/src/lib.rs @@ -0,0 +1,14 @@ +#![deny(unused)] +#![deny(unsafe_code)] +#![cfg_attr(docsrs, feature(doc_cfg))] +#![cfg_attr(test, deny(warnings))] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![doc = include_str!("../README.md")] + +#[cfg(feature = "emulation")] +pub mod emulate; +mod rand; +pub mod tower; + +#[cfg(feature = "emulation")] +pub use self::emulate::{Emulation, Platform, Profile}; diff --git a/crates/wreq-util/src/rand.rs b/crates/wreq-util/src/rand.rs new file mode 100644 index 0000000..2bc5f19 --- /dev/null +++ b/crates/wreq-util/src/rand.rs @@ -0,0 +1,24 @@ +use std::{ + cell::Cell, + collections::hash_map::RandomState, + hash::{BuildHasher, Hasher}, +}; + +// from: https://github.com/seanmonstar/reqwest/blob/5d5bf355744b181d31533501133ad9fbf99e8849/src/util.rs#L28 +pub(crate) fn fast_random() -> u64 { + thread_local! { + static KEY: RandomState = RandomState::new(); + static COUNTER: Cell = const { Cell::new(0) }; + } + + KEY.with(|key| { + COUNTER.with(|ctr| { + let n = ctr.get().wrapping_add(1); + ctr.set(n); + + let mut h = key.build_hasher(); + h.write_u64(n); + h.finish() + }) + }) +} diff --git a/crates/wreq-util/src/tower.rs b/crates/wreq-util/src/tower.rs new file mode 100644 index 0000000..fe20ba2 --- /dev/null +++ b/crates/wreq-util/src/tower.rs @@ -0,0 +1,7 @@ +//! Tower middleware helpers for `wreq`. +//! +//! Modules here are feature-gated. Enable the feature to make the tower middleware +//! available and to include its docs. + +#[cfg(feature = "tower-delay")] +pub mod delay; diff --git a/crates/wreq-util/src/tower/delay.rs b/crates/wreq-util/src/tower/delay.rs new file mode 100644 index 0000000..cbcf2d5 --- /dev/null +++ b/crates/wreq-util/src/tower/delay.rs @@ -0,0 +1,98 @@ +//! Request delay middleware. +//! +//! Adds configurable delays before HTTP requests — useful for rate limiting, +//! testing under slow network conditions, or just being polite to APIs. +//! +//! # Quick Start +//! +//! Fixed 1-second delay: +//! +//! ```no_run +//! use std::time::Duration; +//! use wreq::Client; +//! use wreq_util::tower::delay::DelayLayer; +//! +//! let client = Client::builder_tokio() +//! .layer(DelayLayer::new(Duration::from_secs(1))) +//! .build()?; +//! # Ok::<(), wreq::Error>(()) +//! ``` +//! +//! Random jitter (0.8s ~ 1.2s): +//! +//! ```no_run +//! use std::time::Duration; +//! use wreq::Client; +//! use wreq_util::tower::delay::JitterDelayLayer; +//! +//! let client = Client::builder_tokio() +//! .layer(JitterDelayLayer::new(Duration::from_secs(1), 0.2)) +//! .build()?; +//! # Ok::<(), wreq::Error>(()) +//! ``` +//! +//! # Conditional Delays +//! +//! Use `.when()` to apply delays only to matching requests: +//! +//! ```ignore +//! // Only delay POST requests +//! DelayLayer::new(Duration::from_secs(1)) +//! .when(|req: &http::Request<_>| req.method() == http::Method::POST) +//! +//! // Jitter on specific paths +//! JitterDelayLayer::new(Duration::from_millis(500), 0.3) +//! .when(|req: &http::Request<_>| req.uri().path().starts_with("/api")) +//! ``` +//! +//! # Notes +//! +//! - Delays are async and won't block the runtime +//! - Not a substitute for proper rate limiters — servers can still see timing patterns +//! - Keep delays short in hot paths + +mod future; +mod layer; +mod service; + +use std::time::Duration; + +pub use self::{ + future::ResponseFuture, + layer::{DelayLayer, DelayLayerWith, JitterDelayLayer, JitterDelayLayerWith}, + service::{Delay, DelayWith, JitterDelay, JitterDelayWith}, +}; + +/// Compute a randomized duration in `[base * (1 - pct), base * (1 + pct)]`. +fn jittered_duration(base: Duration, pct: f64) -> Duration { + let jitter = base.mul_f64(pct); + let low = base.saturating_sub(jitter); + let high = base.saturating_add(jitter); + + if low >= high { + return base; + } + + // Generate pseudo-random value using multiple entropy sources + let time_entropy = { + use std::time::SystemTime; + SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .map(|d| d.as_nanos() as u64) + .unwrap_or(0) + }; + + // Use stack address as additional entropy source + let addr_entropy = (&time_entropy as *const u64 as u64).wrapping_mul(0x517cc1b727220a95); + + // Mix entropy sources with a simple but effective hash + let mixed = time_entropy + .wrapping_add(addr_entropy) + .wrapping_mul(0x9e3779b97f4a7c15); + + // Convert to fraction in [0, 1) + let frac = (mixed as f64) / (u64::MAX as f64); + + let span = (high - low).as_secs_f64(); + low + Duration::from_secs_f64(span * frac) +} diff --git a/crates/wreq-util/src/tower/delay/future.rs b/crates/wreq-util/src/tower/delay/future.rs new file mode 100644 index 0000000..944cb0b --- /dev/null +++ b/crates/wreq-util/src/tower/delay/future.rs @@ -0,0 +1,43 @@ +use std::{ + pin::Pin, + task::{Context, Poll, ready}, +}; + +use pin_project_lite::pin_project; +use tokio::time::Sleep; +use tower::BoxError; + +pin_project! { + /// Response future for [`Delay`]. + /// + /// [`Delay`]: super::Delay + #[derive(Debug)] + pub struct ResponseFuture { + #[pin] + response: S, + #[pin] + sleep: Sleep, + } +} + +impl ResponseFuture { + // Create a new [`ResponseFuture`] + #[inline] + pub(crate) fn new(response: S, sleep: Sleep) -> Self { + ResponseFuture { response, sleep } + } +} + +impl Future for ResponseFuture +where + F: Future>, + E: Into, +{ + type Output = Result; + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + let this = self.project(); + ready!(this.sleep.poll(cx)); + this.response.poll(cx).map_err(Into::into) + } +} diff --git a/crates/wreq-util/src/tower/delay/layer.rs b/crates/wreq-util/src/tower/delay/layer.rs new file mode 100644 index 0000000..73f90b3 --- /dev/null +++ b/crates/wreq-util/src/tower/delay/layer.rs @@ -0,0 +1,201 @@ +use std::time::Duration; + +use tower::Layer; + +use super::service::{Delay, DelayWith, JitterDelay, JitterDelayWith}; + +/// A Tower [`Layer`] that introduces a fixed delay before each request. +#[derive(Clone, Debug)] +pub struct DelayLayer { + delay: Duration, +} + +/// Conditional delay [`Layer`], applies delay based on a predicate. +/// +/// Created via [`DelayLayer::when`]. +#[derive(Clone, Debug)] +pub struct DelayLayerWith

{ + delay: Duration, + predicate: P, +} + +/// A Tower [`Layer`] that introduces a jittered delay before each request. +/// +/// The actual delay for each request will be randomly chosen within the range +/// `[base - base*pct, base + base*pct]`. +/// +/// # Example +/// +/// ```no_run +/// use std::time::Duration; +/// use wreq::Client; +/// use wreq_util::tower::delay::JitterDelayLayer; +/// +/// // Creates delays in range [0.8s, 1.2s] (1s ± 20%) +/// let client = Client::builder_tokio() +/// .layer(JitterDelayLayer::new(Duration::from_secs(1), 0.2)) +/// .build()?; +/// # Ok::<(), wreq::Error>(()) +/// ``` +#[derive(Clone, Debug)] +pub struct JitterDelayLayer { + base: Duration, + pct: f64, +} + +/// Conditional jitter delay [`Layer`], applies delay based on a predicate. +/// +/// Created via [`JitterDelayLayer::when`]. +#[derive(Clone, Debug)] +pub struct JitterDelayLayerWith

{ + base: Duration, + pct: f64, + predicate: P, +} + +// ===== impl DelayLayer ===== + +impl DelayLayer { + /// Create a new [`DelayLayer`] with the given delay duration. + #[inline] + pub const fn new(delay: Duration) -> Self { + DelayLayer { delay } + } + + /// Apply delay only to requests that satisfy a predicate. + /// + /// Requests that don't match the predicate will pass through without delay. + /// + /// # Example + /// + /// ```ignore + /// use std::time::Duration; + /// use http::Request; + /// use wreq_util::tower::delay::DelayLayer; + /// + /// // Only delay POST requests + /// let layer = DelayLayer::new(Duration::from_secs(1)) + /// .when(|req: &Request<_>| req.method() == http::Method::POST); + /// ``` + pub fn when(self, predicate: P) -> DelayLayerWith

+ where + P: Fn(&Req) -> bool + Clone, + { + DelayLayerWith::new(self.delay, predicate) + } +} + +impl Layer for DelayLayer { + type Service = Delay; + + #[inline] + fn layer(&self, service: S) -> Self::Service { + Delay::new(service, self.delay) + } +} + +// ===== impl DelayLayerWith ===== + +impl

DelayLayerWith

{ + /// Creates a new [`DelayLayerWith`]. + #[inline] + pub fn new(delay: Duration, predicate: P) -> Self { + Self { delay, predicate } + } +} + +impl Layer for DelayLayerWith

+where + P: Clone, +{ + type Service = DelayWith; + + #[inline] + fn layer(&self, inner: S) -> Self::Service { + DelayWith::new(inner, self.delay, self.predicate.clone()) + } +} + +// ===== impl JitterDelayLayer ===== + +impl JitterDelayLayer { + /// Create a new [`JitterDelayLayer`] with the given base delay and jitter percentage. + /// + /// # Arguments + /// * `base` - The base delay duration + /// * `pct` - The jitter percentage (0.0 to 1.0), representing ±pct deviation + /// + /// # Example + /// + /// ``` + /// use std::time::Duration; + /// use wreq_util::tower::delay::JitterDelayLayer; + /// + /// // Creates delays in range [800ms, 1200ms] + /// let layer = JitterDelayLayer::new(Duration::from_secs(1), 0.2); + /// ``` + #[inline] + pub fn new(base: Duration, pct: f64) -> Self { + Self { + base, + pct: pct.clamp(0.0, 1.0), + } + } + + /// Apply jitter delay only to requests that satisfy a predicate. + /// + /// Requests that don't match the predicate will pass through without delay. + /// + /// # Example + /// + /// ```ignore + /// use std::time::Duration; + /// use http::Request; + /// use wreq_util::tower::delay::JitterDelayLayer; + /// + /// // Only delay requests to paths starting with "/slow" + /// let layer = JitterDelayLayer::new(Duration::from_secs(1), 0.2) + /// .when(|req: &Request<_>| req.uri().path().starts_with("/slow")); + /// ``` + pub fn when(self, predicate: P) -> JitterDelayLayerWith

+ where + P: Fn(&Req) -> bool + Clone, + { + JitterDelayLayerWith::new(self.base, self.pct, predicate) + } +} + +impl Layer for JitterDelayLayer { + type Service = JitterDelay; + + #[inline] + fn layer(&self, inner: S) -> Self::Service { + JitterDelay::new(inner, self.base, self.pct) + } +} + +// ===== impl JitterDelayLayerWith ===== + +impl

JitterDelayLayerWith

{ + /// Creates a new [`JitterDelayLayerWith`]. + #[inline] + pub fn new(base: Duration, pct: f64, predicate: P) -> Self { + Self { + base, + pct: pct.clamp(0.0, 1.0), + predicate, + } + } +} + +impl Layer for JitterDelayLayerWith

+where + P: Clone, +{ + type Service = JitterDelayWith; + + #[inline] + fn layer(&self, inner: S) -> Self::Service { + JitterDelayWith::new(inner, self.base, self.pct, self.predicate.clone()) + } +} diff --git a/crates/wreq-util/src/tower/delay/service.rs b/crates/wreq-util/src/tower/delay/service.rs new file mode 100644 index 0000000..741900e --- /dev/null +++ b/crates/wreq-util/src/tower/delay/service.rs @@ -0,0 +1,190 @@ +use std::{ + task::{Context, Poll}, + time::Duration, +}; + +use tower::{BoxError, Service}; + +use super::{future::ResponseFuture, jittered_duration}; + +/// A Tower [`Service`] that introduces a fixed delay before each request. +#[derive(Debug, Clone)] +pub struct Delay { + inner: S, + delay: Duration, +} + +/// A Tower [`Service`] that conditionally applies fixed delay based on a predicate. +/// +/// Requests that match the predicate will have the delay applied; +/// other requests pass through immediately. +#[derive(Clone, Debug)] +pub struct DelayWith { + inner: Delay, + predicate: P, +} + +/// A Tower [`Service`] that applies jittered delay to requests. +/// +/// This service wraps an inner service and introduces a random delay +/// (within a configured range) before each request. +#[derive(Clone, Debug)] +pub struct JitterDelay { + inner: S, + base: Duration, + pct: f64, +} + +/// A Tower [`Service`] that conditionally applies jittered delay based on a predicate. +/// +/// Requests that match the predicate will have a jittered delay applied; +/// other requests pass through immediately. +#[derive(Clone, Debug)] +pub struct JitterDelayWith { + inner: JitterDelay, + predicate: P, +} + +// ===== impl Delay ===== + +impl Delay { + /// Create a new [`Delay`] service wrapping the given inner service + #[inline] + pub fn new(inner: S, delay: Duration) -> Self { + Delay { inner, delay } + } +} + +impl Service for Delay +where + S: Service, + S::Error: Into, +{ + type Response = S::Response; + type Error = BoxError; + type Future = ResponseFuture; + + #[inline] + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { + self.inner.poll_ready(cx).map_err(Into::into) + } + + fn call(&mut self, req: Request) -> Self::Future { + let response = self.inner.call(req); + let sleep = tokio::time::sleep(self.delay); + ResponseFuture::new(response, sleep) + } +} + +// ===== impl DelayWith ===== + +impl DelayWith { + /// Creates a new [`DelayWith`]. + #[inline] + pub fn new(inner: S, delay: Duration, predicate: P) -> Self { + Self { + inner: Delay::new(inner, delay), + predicate, + } + } +} + +impl Service for DelayWith +where + S: Service, + S::Error: Into, + P: Fn(&Req) -> bool, +{ + type Response = S::Response; + type Error = BoxError; + type Future = ResponseFuture; + + #[inline] + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { + self.inner.poll_ready(cx).map_err(Into::into) + } + + fn call(&mut self, req: Req) -> Self::Future { + if !(self.predicate)(&req) { + self.inner.delay = Duration::ZERO; + } + self.inner.call(req) + } +} + +// ===== impl JitterDelay ===== + +impl JitterDelay { + /// Creates a new [`JitterDelay`]. + #[inline] + pub fn new(inner: S, base: Duration, pct: f64) -> Self { + Self { + inner, + base, + pct: pct.clamp(0.0, 1.0), + } + } +} + +impl Service for JitterDelay +where + S: Service, + S::Error: Into, +{ + type Response = S::Response; + type Error = BoxError; + type Future = ResponseFuture; + + #[inline] + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { + self.inner.poll_ready(cx).map_err(Into::into) + } + + fn call(&mut self, req: Req) -> Self::Future { + let delay = jittered_duration(self.base, self.pct); + let sleep = tokio::time::sleep(delay); + let fut = self.inner.call(req); + ResponseFuture::new(fut, sleep) + } +} + +// ===== impl JitterDelayWith ===== + +impl JitterDelayWith { + /// Creates a new [`JitterDelayWith`]. + #[inline] + pub fn new(inner: S, base: Duration, pct: f64, predicate: P) -> Self { + Self { + inner: JitterDelay::new(inner, base, pct), + predicate, + } + } +} + +impl Service for JitterDelayWith +where + S: Service, + S::Error: Into, + P: Fn(&Req) -> bool, +{ + type Response = S::Response; + type Error = BoxError; + type Future = ResponseFuture; + + #[inline] + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { + self.inner.poll_ready(cx).map_err(Into::into) + } + + fn call(&mut self, req: Req) -> Self::Future { + let delay = if (self.predicate)(&req) { + jittered_duration(self.inner.base, self.inner.pct) + } else { + Duration::ZERO + }; + + let sleep = tokio::time::sleep(delay); + let fut = self.inner.inner.call(req); + ResponseFuture::new(fut, sleep) + } +} diff --git a/crates/wreq-util/tests/client.rs b/crates/wreq-util/tests/client.rs new file mode 100644 index 0000000..14ba500 --- /dev/null +++ b/crates/wreq-util/tests/client.rs @@ -0,0 +1,151 @@ +#![cfg(not(target_arch = "wasm32"))] +mod support; + +use std::future::Future; + +use support::server; +use tokio::{io::AsyncWriteExt, net::TcpStream}; +use wreq::Client; +use wreq_util::{Emulation, Platform, Profile}; + +const CHROMIUM_HEADER_ORDER: &[&str] = &[ + "sec-ch-ua", + "sec-ch-ua-mobile", + "sec-ch-ua-platform", + "upgrade-insecure-requests", + "user-agent", + "accept", + "sec-fetch-site", + "sec-fetch-mode", + "sec-fetch-user", + "sec-fetch-dest", + #[cfg(feature = "emulation-compression")] + "accept-encoding", + "accept-language", + "priority", +]; + +const FIREFOX_HEADER_ORDER: &[&str] = &[ + "user-agent", + "accept", + "accept-language", + #[cfg(feature = "emulation-compression")] + "accept-encoding", + "upgrade-insecure-requests", + "sec-fetch-dest", + "sec-fetch-mode", + "sec-fetch-site", + "sec-fetch-user", + "te", +]; + +fn check_header_order<'a>( + request: &'a [u8], + stream: &'a mut TcpStream, + expected: &'static [&'static str], +) -> Box + Send + 'a> { + Box::new(async move { + let request = std::str::from_utf8(request) + .expect("request should be valid UTF-8") + .to_ascii_lowercase(); + let mut previous = None; + + for name in expected { + let marker = format!("\r\n{name}:"); + let position = request + .find(&marker) + .unwrap_or_else(|| panic!("missing `{name}` header:\n{request}")); + + if let Some(previous) = previous { + assert!( + position > previous, + "`{name}` header is out of order:\n{request}" + ); + } + + previous = Some(position); + } + + assert!(request.contains("\r\nupgrade-insecure-requests: 1\r\n")); + assert!(request.contains("\r\nsec-fetch-user: ?1\r\n")); + + stream + .write_all(b"HTTP/1.1 200 OK\r\ncontent-length: 0\r\nconnection: close\r\n\r\n") + .await + .expect("response"); + }) +} + +async fn assert_emulation_headers(profile: Profile, expected: &'static [&'static str]) { + let server = server::low_level_with_response(move |request, stream| { + check_header_order(request, stream, expected) + }); + let response = Client::builder_tokio() + .emulation(profile) + .build() + .expect("client") + .get(format!("http://{}/headers", server.addr())) + .send() + .await + .expect("request"); + + assert_eq!(response.status(), wreq::StatusCode::OK); +} + +#[tokio::test] +async fn test_client_emulation_device() { + let server = server::http(move |req| async move { + let header = |name| { + req.headers() + .get(name) + .and_then(|value| value.to_str().ok()) + }; + + assert_eq!( + header("user-agent"), + Some( + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36" + ) + ); + assert_eq!( + header("sec-ch-ua"), + Some(r#""Not=A?Brand";v="99", "Google Chrome";v="151", "Chromium";v="151""#) + ); + assert_eq!(header("sec-ch-ua-mobile"), Some("?0")); + assert_eq!(header("sec-ch-ua-platform"), Some("\"Linux\"")); + http::Response::default() + }); + + let url = format!("http://{}/ua", server.addr()); + let res = Client::builder_tokio() + .emulation( + Emulation::builder() + .profile(Emulation::Chrome151) + .platform(Platform::Linux) + .http2(true) + .build(), + ) + .build() + .expect("Unable to build client") + .get(&url) + .send() + .await + .expect("request"); + + assert_eq!(res.status(), wreq::StatusCode::OK); +} + +#[tokio::test] +async fn test_chrome_default_header_order() { + assert_emulation_headers(Emulation::Chrome133, CHROMIUM_HEADER_ORDER).await; +} + +#[tokio::test] +async fn test_firefox_default_header_order() { + assert_emulation_headers(Emulation::Firefox109, FIREFOX_HEADER_ORDER).await; +} + +#[tokio::test] +async fn test_opera_default_header_order() { + assert_emulation_headers(Emulation::Opera116, CHROMIUM_HEADER_ORDER).await; +} diff --git a/crates/wreq-util/tests/emulate_chrome.rs b/crates/wreq-util/tests/emulate_chrome.rs new file mode 100644 index 0000000..f2b3f99 --- /dev/null +++ b/crates/wreq-util/tests/emulate_chrome.rs @@ -0,0 +1,347 @@ +#[macro_use] +mod support; + +use wreq_util::Emulation; + +// Enabling certain extensions(ECH) will change the length during encryption. This is because TLS will +// automatically use padding to fill the data and add a padding extension. At this time, the ja4 +// fingerprint will change. + +test_emulation!( + test_chrome100, + Emulation::Chrome100, + ["t13d1516h2_8daaf6152771_e5627efa2ab1"], + "4f04edce68a7ecbe689edce7bf5f23f3" +); + +test_emulation!( + test_chrome101, + Emulation::Chrome101, + ["t13d1516h2_8daaf6152771_e5627efa2ab1"], + "4f04edce68a7ecbe689edce7bf5f23f3" +); + +test_emulation!( + test_edge101, + Emulation::Edge101, + ["t13d1516h2_8daaf6152771_e5627efa2ab1"], + "4f04edce68a7ecbe689edce7bf5f23f3" +); + +test_emulation!( + test_chrome104, + Emulation::Chrome104, + ["t13d1516h2_8daaf6152771_e5627efa2ab1"], + "4f04edce68a7ecbe689edce7bf5f23f3" +); + +test_emulation!( + test_chrome105, + Emulation::Chrome105, + [ + "t13d1516h2_8daaf6152771_02713d6af862", + "t13d1517h2_8daaf6152771_b1ff8ab2d16f" + ], + "4f04edce68a7ecbe689edce7bf5f23f3" +); + +test_emulation!( + test_chrome106, + Emulation::Chrome106, + ["t13d1516h2_8daaf6152771_e5627efa2ab1"], + "a345a694846ad9f6c97bcc3c75adbe26" +); + +test_emulation!( + test_chrome107, + Emulation::Chrome107, + ["t13d1516h2_8daaf6152771_e5627efa2ab1"], + "a345a694846ad9f6c97bcc3c75adbe26" +); + +test_emulation!( + test_chrome108, + Emulation::Chrome108, + ["t13d1516h2_8daaf6152771_e5627efa2ab1"], + "a345a694846ad9f6c97bcc3c75adbe26" +); + +test_emulation!( + test_chrome109, + Emulation::Chrome109, + ["t13d1516h2_8daaf6152771_e5627efa2ab1"], + "a345a694846ad9f6c97bcc3c75adbe26" +); + +test_emulation!( + test_chrome110, + Emulation::Chrome110, + ["t13d1516h2_8daaf6152771_e5627efa2ab1"], + "4f04edce68a7ecbe689edce7bf5f23f3" +); + +test_emulation!( + test_chrome114, + Emulation::Chrome114, + ["t13d1516h2_8daaf6152771_e5627efa2ab1"], + "a345a694846ad9f6c97bcc3c75adbe26" +); + +test_emulation!( + test_chrome116, + Emulation::Chrome116, + [ + "t13d1516h2_8daaf6152771_02713d6af862", + "t13d1517h2_8daaf6152771_b1ff8ab2d16f" + ], + "a345a694846ad9f6c97bcc3c75adbe26" +); + +test_emulation!( + test_chrome117, + Emulation::Chrome117, + [ + "t13d1516h2_8daaf6152771_02713d6af862", + "t13d1517h2_8daaf6152771_b1ff8ab2d16f" + ], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome118, + Emulation::Chrome118, + [ + "t13d1516h2_8daaf6152771_02713d6af862", + "t13d1517h2_8daaf6152771_b1ff8ab2d16f" + ], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome119, + Emulation::Chrome119, + [ + "t13d1516h2_8daaf6152771_02713d6af862", + "t13d1517h2_8daaf6152771_b1ff8ab2d16f" + ], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome120, + Emulation::Chrome120, + [ + "t13d1516h2_8daaf6152771_02713d6af862", + "t13d1517h2_8daaf6152771_b1ff8ab2d16f" + ], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_edge122, + Emulation::Edge122, + [ + "t13d1516h2_8daaf6152771_02713d6af862", + "t13d1517h2_8daaf6152771_b1ff8ab2d16f" + ], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome123, + Emulation::Chrome123, + [ + "t13d1516h2_8daaf6152771_02713d6af862", + "t13d1517h2_8daaf6152771_b1ff8ab2d16f" + ], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome124, + Emulation::Chrome124, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome126, + Emulation::Chrome126, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome127, + Emulation::Chrome127, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_edge127, + Emulation::Edge127, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome128, + Emulation::Chrome128, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome129, + Emulation::Chrome129, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome130, + Emulation::Chrome130, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome131, + Emulation::Chrome131, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_edge131, + Emulation::Edge131, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome132, + Emulation::Chrome132, + ["t13d1516h2_8daaf6152771_d8a2da3f94cd"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome133, + Emulation::Chrome133, + ["t13d1516h2_8daaf6152771_d8a2da3f94cd"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome134, + Emulation::Chrome134, + ["t13d1516h2_8daaf6152771_d8a2da3f94cd"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_edge134, + Emulation::Edge134, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome135, + Emulation::Chrome135, + ["t13d1516h2_8daaf6152771_d8a2da3f94cd"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome136, + Emulation::Chrome136, + ["t13d1516h2_8daaf6152771_d8a2da3f94cd"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome137, + Emulation::Chrome137, + ["t13d1516h2_8daaf6152771_d8a2da3f94cd"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome151, + Emulation::Chrome151, + ["t13d1516h2_8daaf6152771_806a8c22fdea"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome152, + Emulation::Chrome152, + [ + "t13d1517h2_8daaf6152771_cb7bf5808d99", + "t13d1518h2_8daaf6152771_e2d80978ab2e" + ], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome153, + Emulation::Chrome153, + [ + "t13d1517h2_8daaf6152771_cb7bf5808d99", + "t13d1518h2_8daaf6152771_e2d80978ab2e" + ], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome154, + Emulation::Chrome154, + [ + "t13d1517h2_8daaf6152771_cb7bf5808d99", + "t13d1518h2_8daaf6152771_e2d80978ab2e" + ], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome155, + Emulation::Chrome155, + [ + "t13d1517h2_8daaf6152771_cb7bf5808d99", + "t13d1518h2_8daaf6152771_e2d80978ab2e" + ], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome156, + Emulation::Chrome156, + [ + "t13d1517h2_8daaf6152771_cb7bf5808d99", + "t13d1518h2_8daaf6152771_e2d80978ab2e" + ], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome157, + Emulation::Chrome157, + [ + "t13d1517h2_8daaf6152771_cb7bf5808d99", + "t13d1518h2_8daaf6152771_e2d80978ab2e" + ], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_chrome158, + Emulation::Chrome158, + [ + "t13d1517h2_8daaf6152771_cb7bf5808d99", + "t13d1518h2_8daaf6152771_e2d80978ab2e" + ], + "52d84b11737d980aef856699f885ca86" +); diff --git a/crates/wreq-util/tests/emulate_firefox.rs b/crates/wreq-util/tests/emulate_firefox.rs new file mode 100644 index 0000000..28a7595 --- /dev/null +++ b/crates/wreq-util/tests/emulate_firefox.rs @@ -0,0 +1,176 @@ +#[macro_use] +mod support; + +use wreq_util::Emulation; + +// Enabling certain extensions(ECH) will change the length during encryption. This is because TLS will +// automatically use padding to fill the data and add a padding extension. At this time, the ja4 +// fingerprint will change. + +test_emulation!( + test_firefox_109, + Emulation::Firefox109, + ["t13d1715h2_5b57614c22b0_3d5424432f57"], + "73d042072ceabaedacfd45e84dff1020" +); + +test_emulation!( + test_firefox_117, + Emulation::Firefox117, + ["t13d1715h2_5b57614c22b0_3d5424432f57"], + "73d042072ceabaedacfd45e84dff1020" +); + +test_emulation!( + test_firefox_128, + Emulation::Firefox128, + ["t13d1513h2_8daaf6152771_748f4c70de1c"], + "1d8a6f51fd7253d04674593073fc18b0" +); + +test_emulation!( + test_firefox_133, + Emulation::Firefox133, + ["t13d1716h2_5b57614c22b0_eeeea6562960"], + "6ea73faa8fc5aac76bded7bd238f6433" +); + +test_emulation!( + test_firefox_135, + Emulation::Firefox135, + ["t13d1717h2_5b57614c22b0_3cbfd9057e0d"], + "6ea73faa8fc5aac76bded7bd238f6433" +); + +test_emulation!( + test_firefox_private_135, + Emulation::FirefoxPrivate135, + ["t13d1715h2_5b57614c22b0_a54fffd0eb61"], + "6ea73faa8fc5aac76bded7bd238f6433" +); + +test_emulation!( + test_firefox_android_135, + Emulation::FirefoxAndroid135, + ["t13d1716h2_5b57614c22b0_eeeea6562960"], + "41a06cadb1c6385e6d08c8d0dbbea818" +); + +test_emulation!( + test_firefox_136, + Emulation::Firefox136, + ["t13d1717h2_5b57614c22b0_3cbfd9057e0d"], + "6ea73faa8fc5aac76bded7bd238f6433" +); + +test_emulation!( + test_firefox_private_136, + Emulation::FirefoxPrivate136, + ["t13d1715h2_5b57614c22b0_a54fffd0eb61"], + "6ea73faa8fc5aac76bded7bd238f6433" +); + +test_emulation!( + test_firefox_139, + Emulation::Firefox139, + ["t13d1717h2_5b57614c22b0_3cbfd9057e0d"], + "6ea73faa8fc5aac76bded7bd238f6433" +); + +test_emulation!( + test_firefox_142, + Emulation::Firefox142, + ["t13d1717h2_5b57614c22b0_3cbfd9057e0d"], + "6ea73faa8fc5aac76bded7bd238f6433" +); + +test_emulation!( + test_firefox_143, + Emulation::Firefox143, + ["t13d1717h2_5b57614c22b0_3cbfd9057e0d"], + "6ea73faa8fc5aac76bded7bd238f6433" +); + +test_emulation!( + test_firefox_150, + Emulation::Firefox150, + ["t13d1617h2_86a278354501_3cbfd9057e0d"], + "6ea73faa8fc5aac76bded7bd238f6433" +); + +test_emulation!( + test_firefox_151, + Emulation::Firefox151, + ["t13d1617h2_86a278354501_3cbfd9057e0d"], + "6ea73faa8fc5aac76bded7bd238f6433" +); + +test_emulation!( + test_firefox_152, + Emulation::Firefox152, + ["t13d1617h2_86a278354501_3cbfd9057e0d"], + "6ea73faa8fc5aac76bded7bd238f6433" +); + +/// Firefox 147 changed the generated `Accept-Language` q-value: the list used to divide 1.0 +/// across its entries, giving `q=0.5` for two, and now decrements by 0.1 per entry, giving +/// `q=0.9`. See Bugzilla 2000765, landed in mozilla-firefox 0e050ae5116d. +/// +/// Every profile is listed rather than a range, so adding one is a deliberate choice about +/// which side of 147 it falls on. +#[tokio::test] +async fn firefox_accept_language_matches_the_profile_version() { + use wreq_util::{Platform, Profile}; + + const PRE_147: &[(&str, Profile)] = &[ + ("Firefox109", Emulation::Firefox109), + ("Firefox117", Emulation::Firefox117), + ("Firefox128", Emulation::Firefox128), + ("Firefox133", Emulation::Firefox133), + ("Firefox135", Emulation::Firefox135), + ("FirefoxPrivate135", Emulation::FirefoxPrivate135), + ("FirefoxAndroid135", Emulation::FirefoxAndroid135), + ("Firefox136", Emulation::Firefox136), + ("FirefoxPrivate136", Emulation::FirefoxPrivate136), + ("Firefox139", Emulation::Firefox139), + ("Firefox142", Emulation::Firefox142), + ("Firefox143", Emulation::Firefox143), + ("Firefox144", Emulation::Firefox144), + ("Firefox145", Emulation::Firefox145), + ("Firefox146", Emulation::Firefox146), + ]; + const POST_147: &[(&str, Profile)] = &[ + ("Firefox147", Emulation::Firefox147), + ("Firefox148", Emulation::Firefox148), + ("Firefox149", Emulation::Firefox149), + ("Firefox150", Emulation::Firefox150), + ("Firefox151", Emulation::Firefox151), + ("Firefox152", Emulation::Firefox152), + ]; + + let server = support::server::http(|request| async move { + let mut response = http::Response::default(); + response.headers_mut().insert( + "accept-language", + request.headers()["accept-language"].clone(), + ); + response + }); + let client = wreq::Client::builder_tokio().no_proxy().build().unwrap(); + for (profiles, expected) in [(PRE_147, "en-US,en;q=0.5"), (POST_147, "en-US,en;q=0.9")] { + for (name, profile) in profiles { + let response = client + .get(format!("http://{}/", server.addr())) + .emulation( + Emulation::builder() + .profile(*profile) + .platform(Platform::Linux) + .build(), + ) + .send() + .await + .unwrap(); + assert_eq!(response.headers()["accept-language"], expected, "{name}"); + } + } +} diff --git a/crates/wreq-util/tests/emulate_okhttp.rs b/crates/wreq-util/tests/emulate_okhttp.rs new file mode 100644 index 0000000..052e607 --- /dev/null +++ b/crates/wreq-util/tests/emulate_okhttp.rs @@ -0,0 +1,46 @@ +#[macro_use] +mod support; + +use wreq_util::Emulation; + +test_emulation!( + test_okhttp3_13, + Emulation::OkHttp3_13, + ["t13d1613h2_46e7e9700bed_eca864cca44a"], + "605a1154008045d7e3cb3c6fb062c0ce" +); + +test_emulation!( + test_okhttp3_14, + Emulation::OkHttp3_14, + ["t13d1613h2_46e7e9700bed_eca864cca44a"], + "605a1154008045d7e3cb3c6fb062c0ce" +); + +test_emulation!( + test_okhttp4_9, + Emulation::OkHttp4_9, + ["t13d1513h2_8daaf6152771_eca864cca44a"], + "605a1154008045d7e3cb3c6fb062c0ce" +); + +test_emulation!( + test_okhttp4_10, + Emulation::OkHttp4_10, + ["t13d1613h2_46e7e9700bed_eca864cca44a"], + "605a1154008045d7e3cb3c6fb062c0ce" +); + +test_emulation!( + test_okhttp4_12, + Emulation::OkHttp4_12, + ["t13d1613h2_46e7e9700bed_eca864cca44a"], + "605a1154008045d7e3cb3c6fb062c0ce" +); + +test_emulation!( + test_okhttp5, + Emulation::OkHttp5, + ["t13d1613h2_46e7e9700bed_eca864cca44a"], + "605a1154008045d7e3cb3c6fb062c0ce" +); diff --git a/crates/wreq-util/tests/emulate_opera.rs b/crates/wreq-util/tests/emulate_opera.rs new file mode 100644 index 0000000..3d8e3c2 --- /dev/null +++ b/crates/wreq-util/tests/emulate_opera.rs @@ -0,0 +1,113 @@ +#[macro_use] +mod support; + +use wreq_util::Emulation; + +// Enabling certain extensions will change the length during encryption. This is because TLS will +// automatically use padding to fill the data and add a padding extension. At this time, the ja4 +// fingerprint will change. + +test_emulation!( + test_opera116, + Emulation::Opera116, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera117, + Emulation::Opera117, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera118, + Emulation::Opera118, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera119, + Emulation::Opera119, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera120, + Emulation::Opera120, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera121, + Emulation::Opera121, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera122, + Emulation::Opera122, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera123, + Emulation::Opera123, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera124, + Emulation::Opera124, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera125, + Emulation::Opera125, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera126, + Emulation::Opera126, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera127, + Emulation::Opera127, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera128, + Emulation::Opera128, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera129, + Emulation::Opera129, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); + +test_emulation!( + test_opera130, + Emulation::Opera130, + ["t13d1516h2_8daaf6152771_02713d6af862"], + "52d84b11737d980aef856699f885ca86" +); diff --git a/crates/wreq-util/tests/emulate_safari.rs b/crates/wreq-util/tests/emulate_safari.rs new file mode 100644 index 0000000..4e4c667 --- /dev/null +++ b/crates/wreq-util/tests/emulate_safari.rs @@ -0,0 +1,151 @@ +#[macro_use] +mod support; + +use wreq_util::Emulation; + +test_emulation!( + test_safari_15_3, + Emulation::Safari15_3, + ["t13d2614h2_2802a3db6c62_14788d8d241b"], + "dda308d35f4e5db7b52a61720ca1b122" +); + +test_emulation!( + test_safari_15_5, + Emulation::Safari15_5, + ["t13d2614h2_2802a3db6c62_14788d8d241b"], + "dda308d35f4e5db7b52a61720ca1b122" +); + +test_emulation!( + test_safari_15_6_1, + Emulation::Safari15_6_1, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "dda308d35f4e5db7b52a61720ca1b122" +); + +test_emulation!( + test_safari_16, + Emulation::Safari16, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "dda308d35f4e5db7b52a61720ca1b122" +); + +test_emulation!( + test_safari_16_5, + Emulation::Safari16_5, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "dda308d35f4e5db7b52a61720ca1b122" +); + +test_emulation!( + test_safari_ios_16_5, + Emulation::SafariIos16_5, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "d5fcbdc393757341115a861bf8d23265" +); + +test_emulation!( + test_safari_17, + Emulation::Safari17_0, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "959a7e813b79b909a1a0b00a38e8bba3" +); + +test_emulation!( + test_safari_17_2_1, + Emulation::Safari17_2_1, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "959a7e813b79b909a1a0b00a38e8bba3" +); + +test_emulation!( + test_safari_17_4_1, + Emulation::Safari17_4_1, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "dda308d35f4e5db7b52a61720ca1b122" +); + +test_emulation!( + test_safari_17_5, + Emulation::Safari17_5, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "959a7e813b79b909a1a0b00a38e8bba3" +); + +test_emulation!( + test_safari_ios_17_2, + Emulation::SafariIos17_2, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "ad8424af1cc590e09f7b0c499bf7fcdb" +); + +test_emulation!( + test_safari_ios_17_4_1, + Emulation::SafariIos17_4_1, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "ad8424af1cc590e09f7b0c499bf7fcdb" +); + +test_emulation!( + test_safari_18, + Emulation::Safari18, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "d4a2dcbfde511b5040ed5a5190a8d78b" +); + +test_emulation!( + test_safari_18_2, + Emulation::Safari18_2, + ["t13d2014h2_a09f3c656075_e42f34c56612"], + "d4a2dcbfde511b5040ed5a5190a8d78b" +); + +test_emulation!( + test_safari_18_3, + Emulation::Safari18_3, + ["t13d2014h2_a09f3c656075_e42f34c56612"], + "d4a2dcbfde511b5040ed5a5190a8d78b" +); + +test_emulation!( + test_safari_18_3_1, + Emulation::Safari18_3_1, + ["t13d2014h2_a09f3c656075_e42f34c56612"], + "d4a2dcbfde511b5040ed5a5190a8d78b" +); + +test_emulation!( + test_safari_ios_18_1_1, + Emulation::SafariIos18_1_1, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "d4a2dcbfde511b5040ed5a5190a8d78b" +); + +test_emulation!( + test_safari_ipad_18, + Emulation::SafariIPad18, + ["t13d2014h2_a09f3c656075_14788d8d241b"], + "d4a2dcbfde511b5040ed5a5190a8d78b" +); + +test_emulation!( + test_safari_18_5, + Emulation::Safari18_5, + ["t13d2014h2_a09f3c656075_e42f34c56612"], + "c52879e43202aeb92740be6e8c86ea96" +); + +test_emulation!( + test_safari_26, + Emulation::Safari26, + ["t13d2013h2_a09f3c656075_7f0f34a4126d"], + "c52879e43202aeb92740be6e8c86ea96" +); + +test_emulation!( + test_safari_26_1, + Emulation::Safari26_1, + ["t13d2014h2_a09f3c656075_e42f34c56612"], + "c52879e43202aeb92740be6e8c86ea96" +); diff --git a/crates/wreq-util/tests/support/mod.rs b/crates/wreq-util/tests/support/mod.rs new file mode 100644 index 0000000..cc59664 --- /dev/null +++ b/crates/wreq-util/tests/support/mod.rs @@ -0,0 +1,58 @@ +#![allow(dead_code)] +pub mod server; + +use std::{sync::LazyLock, time::Duration}; + +use tokio::sync::Semaphore; +use wreq::Client; + +// TODO: remove once done converting to new support server? +#[allow(unused)] +pub static DEFAULT_USER_AGENT: &str = + concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); + +pub static TEST_SEMAPHORE: LazyLock = LazyLock::new(|| Semaphore::new(1)); + +pub static CLIENT: LazyLock = LazyLock::new(|| { + Client::builder_tokio() + .connect_timeout(Duration::from_secs(60)) + .build() + .unwrap() +}); + +#[allow(unused_macros)] +macro_rules! test_emulation { + ($test_name:ident, $emulation:expr, $ja4:expr, $akamai_hash:expr) => { + #[tokio::test] + async fn $test_name() { + let _permit = crate::support::TEST_SEMAPHORE.acquire().await.unwrap(); + + let resp = crate::support::CLIENT + .get("https://tls.browserleaks.com/") + .emulation($emulation) + .send() + .await + .unwrap(); + + assert_eq!(resp.status(), wreq::StatusCode::OK); + let content = resp.text().await.unwrap(); + let fingerprint: serde_json::Value = serde_json::from_str(&content) + .unwrap_or_else(|error| panic!("invalid fingerprint JSON: {error}\n{content}")); + + let actual_ja4 = fingerprint["ja4"].as_str(); + assert!( + actual_ja4.is_some_and(|value| $ja4.contains(&value)), + "JA4 fingerprint mismatch: expected {:?}, got {actual_ja4:?}\n{content}", + $ja4 + ); + + assert_eq!( + fingerprint["akamai_hash"].as_str(), + Some($akamai_hash), + "HTTP/2 fingerprint mismatch:\n{content}" + ); + + tokio::time::sleep(std::time::Duration::from_millis(1000)).await; + } + }; +} diff --git a/crates/wreq-util/tests/support/server.rs b/crates/wreq-util/tests/support/server.rs new file mode 100644 index 0000000..8b190fd --- /dev/null +++ b/crates/wreq-util/tests/support/server.rs @@ -0,0 +1,232 @@ +#![cfg(not(target_arch = "wasm32"))] +use std::{ + convert::Infallible, future::Future, net, sync::mpsc as std_mpsc, thread, time::Duration, +}; + +use tokio::{io::AsyncReadExt, net::TcpStream, runtime, sync::oneshot}; + +pub struct Server { + addr: net::SocketAddr, + panic_rx: std_mpsc::Receiver<()>, + events_rx: std_mpsc::Receiver, + shutdown_tx: Option>, +} + +#[non_exhaustive] +pub enum Event { + ConnectionClosed, +} + +impl Server { + pub fn addr(&self) -> net::SocketAddr { + self.addr + } + + #[allow(unused)] + pub fn events(&mut self) -> Vec { + let mut events = Vec::new(); + while let Ok(event) = self.events_rx.try_recv() { + events.push(event); + } + events + } +} + +impl Drop for Server { + fn drop(&mut self) { + if let Some(tx) = self.shutdown_tx.take() { + let _ = tx.send(()); + } + + if !::std::thread::panicking() { + self.panic_rx + .recv_timeout(Duration::from_secs(3)) + .expect("test server should not panic"); + } + } +} + +pub fn http(func: F) -> Server +where + F: Fn(http::Request) -> Fut + Clone + Send + 'static, + Fut: Future> + Send + 'static, +{ + http_with_config(func, |_builder| {}) +} + +type Builder = hyper_util::server::conn::auto::Builder; + +pub fn http_with_config(func: F1, apply_config: F2) -> Server +where + F1: Fn(http::Request) -> Fut + Clone + Send + 'static, + Fut: Future> + Send + 'static, + F2: FnOnce(&mut Builder) -> Bu + Send + 'static, +{ + // Spawn new runtime in thread to prevent reactor execution context conflict + let test_name = thread::current().name().unwrap_or("").to_string(); + thread::spawn(move || { + let rt = runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("new rt"); + let listener = rt.block_on(async move { + tokio::net::TcpListener::bind(&std::net::SocketAddr::from(([127, 0, 0, 1], 0))) + .await + .unwrap() + }); + let addr = listener.local_addr().unwrap(); + + let (shutdown_tx, mut shutdown_rx) = oneshot::channel(); + let (panic_tx, panic_rx) = std_mpsc::channel(); + let (events_tx, events_rx) = std_mpsc::channel(); + let tname = format!( + "test({})-support-server", + test_name, + ); + thread::Builder::new() + .name(tname) + .spawn(move || { + rt.block_on(async move { + let mut builder = + hyper_util::server::conn::auto::Builder::new(hyper_util::rt::TokioExecutor::new()); + apply_config(&mut builder); + + loop { + tokio::select! { + _ = &mut shutdown_rx => { + break; + } + accepted = listener.accept() => { + let (io, _) = accepted.expect("accepted"); + let func = func.clone(); + let svc = hyper::service::service_fn(move |req| { + let fut = func(req); + async move { Ok::<_, Infallible>(fut.await) } + }); + let builder = builder.clone(); + let events_tx = events_tx.clone(); + tokio::spawn(async move { + let _ = builder.serve_connection_with_upgrades(hyper_util::rt::TokioIo::new(io), svc).await; + let _ = events_tx.send(Event::ConnectionClosed); + }); + } + } + } + let _ = panic_tx.send(()); + }); + }) + .expect("thread spawn"); + Server { + addr, + panic_rx, + events_rx, + shutdown_tx: Some(shutdown_tx), + } + }) + .join() + .unwrap() +} + +#[allow(unused)] +pub fn low_level_with_response(do_response: F) -> Server +where + for<'c> F: Fn(&'c [u8], &'c mut TcpStream) -> Box + Send + 'c> + + Clone + + Send + + 'static, +{ + // Spawn new runtime in thread to prevent reactor execution context conflict + let test_name = thread::current().name().unwrap_or("").to_string(); + thread::spawn(move || { + let rt = runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("new rt"); + let listener = rt.block_on(async move { + tokio::net::TcpListener::bind(&std::net::SocketAddr::from(([127, 0, 0, 1], 0))) + .await + .unwrap() + }); + let addr = listener.local_addr().unwrap(); + + let (shutdown_tx, mut shutdown_rx) = oneshot::channel(); + let (panic_tx, panic_rx) = std_mpsc::channel(); + let (events_tx, events_rx) = std_mpsc::channel(); + let tname = format!("test({})-support-server", test_name,); + thread::Builder::new() + .name(tname) + .spawn(move || { + rt.block_on(async move { + loop { + tokio::select! { + _ = &mut shutdown_rx => { + break; + } + accepted = listener.accept() => { + let (io, _) = accepted.expect("accepted"); + let do_response = do_response.clone(); + let events_tx = events_tx.clone(); + tokio::spawn(async move { + low_level_server_client(io, do_response).await; + let _ = events_tx.send(Event::ConnectionClosed); + }); + } + } + } + let _ = panic_tx.send(()); + }); + }) + .expect("thread spawn"); + Server { + addr, + panic_rx, + events_rx, + shutdown_tx: Some(shutdown_tx), + } + }) + .join() + .unwrap() +} + +#[allow(unused)] +async fn low_level_server_client(mut client_socket: TcpStream, do_response: F) +where + for<'c> F: Fn(&'c [u8], &'c mut TcpStream) -> Box + Send + 'c>, +{ + loop { + let request = low_level_read_http_request(&mut client_socket) + .await + .expect("read_http_request failed"); + if request.is_empty() { + // connection closed by client + break; + } + + Box::into_pin(do_response(&request, &mut client_socket)).await; + } +} + +#[allow(unused)] +async fn low_level_read_http_request( + client_socket: &mut TcpStream, +) -> core::result::Result, std::io::Error> { + let mut buf = Vec::new(); + + // Read until the delimiter "\r\n\r\n" is found + loop { + let mut temp_buffer = [0; 1024]; + let n = client_socket.read(&mut temp_buffer).await?; + + if n == 0 { + break; + } + + buf.extend_from_slice(&temp_buffer[..n]); + + if let Some(pos) = buf.windows(4).position(|window| window == b"\r\n\r\n") { + return Ok(buf.drain(..pos + 4).collect()); + } + } + + Ok(buf) +} diff --git a/examples/emulate_request.rb b/examples/emulate_request.rb index 52ff307..0f3c1c0 100644 --- a/examples/emulate_request.rb +++ b/examples/emulate_request.rb @@ -11,7 +11,7 @@ # Set when creating the Wreq::Client instance. # All requests from this client will use the specified emulation unless overridden. client = Wreq::Client.new(emulation: Wreq::Emulation.new( - profile: Wreq::Profile::Chrome149, + profile: Wreq::Profile::Chrome150, platform: Wreq::Platform::MacOS, http2: true, headers: true diff --git a/lib/wreq.rb b/lib/wreq.rb index 3d8de6f..23e7cc1 100644 --- a/lib/wreq.rb +++ b/lib/wreq.rb @@ -76,7 +76,7 @@ module Wreq # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the client's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -110,7 +110,7 @@ def self.request(method, url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the client's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -144,7 +144,7 @@ def self.get(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the client's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -178,7 +178,7 @@ def self.head(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the client's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -212,7 +212,7 @@ def self.post(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the client's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -246,7 +246,7 @@ def self.put(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the client's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -280,7 +280,7 @@ def self.delete(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the client's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -314,7 +314,7 @@ def self.options(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the client's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -348,7 +348,7 @@ def self.trace(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the client's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. diff --git a/lib/wreq_ruby/client.rb b/lib/wreq_ruby/client.rb index 9e62269..14e9ee6 100644 --- a/lib/wreq_ruby/client.rb +++ b/lib/wreq_ruby/client.rb @@ -5,7 +5,7 @@ module Wreq # HTTP client with extensive configuration options. # # This class wraps a native Rust implementation providing high-performance - # HTTP/1.1 and HTTP/2 client functionality with support for connection pooling, + # HTTP/1.1, HTTP/2 and HTTP/3 client functionality with support for connection pooling, # compression, redirects, proxies, and fine-grained timeout controls. # # The client is thread-safe and maintains an internal connection pool for @@ -84,8 +84,8 @@ class Client # from the overall timeout. # # @param read_timeout [Integer, nil] Maximum time in seconds to wait - # between reading chunks of data from the server. Applies to each - # read operation, not the entire response. + # for response headers or each body chunk. Time spent by the caller + # between body reads is excluded. Defaults to no read timeout. # # @param tcp_keepalive [Integer, nil] Time in seconds that a connection # must be idle before TCP keepalive probes are sent. Helps detect @@ -110,25 +110,37 @@ class Client # allowing the reuse of local addresses in TIME_WAIT state. Useful for # reducing port exhaustion in high-throughput scenarios. # - # @param pool_idle_timeout [Integer, nil] Time in seconds before idle - # connections in the pool are evicted and closed. Helps free up - # resources for long-running applications. + # @param pool_idle_timeout [Integer, nil] Idle connection reuse timeout in + # seconds. Defaults to 90 when omitted or nil. Does not expire a busy + # HTTP/2 or HTTP/3 connection. # - # @param pool_max_idle_per_host [Integer, nil] Maximum number of idle - # connections to maintain per host in the connection pool. Connections - # beyond this limit will be closed immediately after use. + # @param pool_max_idle_per_host [Integer, nil] Maximum idle HTTP/1 + # connections retained per compatibility group, which includes the host + # and connection configuration. Defaults to unlimited when omitted or + # nil; 0 disables connection reuse. Does not limit active connections. # - # @param pool_max_size [Integer, nil] Total maximum size of the connection - # pool across all hosts. Once reached, new requests may need to wait - # for existing connections to become available. + # @param pool_max_size [Integer, nil] Maximum compatibility groups retaining + # idle HTTP/1 or shared HTTP/2 and HTTP/3 connections. Defaults to unlimited + # when omitted, nil or 0. A full pool evicts the least recently used idle + # group; it does not make requests wait or limit physical connections. # # @param http1_only [Boolean, nil] Force the client to use HTTP/1.1 only, # even if HTTP/2 is available. Useful for compatibility with servers - # that have problematic HTTP/2 implementations. + # that have problematic HTTP/2 implementations. Cannot be combined with + # http2_only or http3_only. An explicit request version overrides this + # preference. # # @param http2_only [Boolean, nil] Force the client to use HTTP/2 only. # Requests to servers that don't support HTTP/2 will fail. Cannot be - # combined with http1_only. + # combined with http1_only or http3_only. An explicit request version + # overrides this preference, including HTTP/3 over QUIC. + # + # @param http3_only [Boolean, nil] Use HTTP/3 over QUIC without falling back + # to TCP. Defaults to false when omitted or nil. Requires HTTPS and UDP + # connectivity. Cannot be combined with http1_only or http2_only. An + # explicit HTTP/1 or HTTP/2 request version overrides this preference. + # HTTP/HTTPS proxies, including environment proxies, cannot carry HTTP/3; + # use no_proxy: true, a SOCKS5 UDP proxy, or a QUIC MASQUE proxy instead. # # @param https_only [Boolean, nil] Reject plain HTTP connections and # only allow HTTPS. Provides an additional layer of security by @@ -149,7 +161,9 @@ class Client # environment. # # @param proxy [String, nil] Proxy server URI to use for all requests. - # Supports HTTP, HTTPS, and SOCKS5 proxies. Format: "protocol://host:port" + # Supports HTTP, HTTPS, SOCKS and QUIC proxies. HTTP/3 can use SOCKS5 UDP + # ASSOCIATE or a `quic://` MASQUE proxy, but not HTTP CONNECT proxies. + # Format: "protocol://host:port" # Example: "http://proxy.example.com:8080" # @param local_address [String, nil] Bind the client's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable. # @param interface [String, nil] Bind sockets to a network interface on @@ -196,7 +210,7 @@ class Client # client = Wreq::Client.new( # timeout: 30, # 30 seconds total # connect_timeout: 5, # 5 seconds to connect - # read_timeout: 10 # 10 seconds between reads + # read_timeout: 10 # 10 seconds for headers or each body read # ) # # @example Client with redirect handling @@ -280,7 +294,7 @@ def self.new(**options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -316,7 +330,7 @@ def request(method, url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -350,7 +364,7 @@ def get(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -384,7 +398,7 @@ def head(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -418,7 +432,7 @@ def post(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -452,7 +466,7 @@ def put(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -486,7 +500,7 @@ def delete(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -520,7 +534,7 @@ def options(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. @@ -554,7 +568,7 @@ def trace(url, **options) # @param deflate [Boolean, nil] Enable deflate compression # @param zstd [Boolean, nil] Enable Zstandard compression # @param timeout [Integer, nil] Total request timeout (seconds) - # @param read_timeout [Integer, nil] Per-chunk read timeout (seconds) + # @param read_timeout [Integer, nil] Timeout for headers or each body chunk (seconds) # @param proxy [String, nil] Proxy server URI # @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail. # @param interface [String, nil] Bind to an interface on supported platforms; unsupported platforms raise ArgumentError. diff --git a/lib/wreq_ruby/emulate.rb b/lib/wreq_ruby/emulate.rb index 027ace3..cc74013 100644 --- a/lib/wreq_ruby/emulate.rb +++ b/lib/wreq_ruby/emulate.rb @@ -61,6 +61,15 @@ class Profile Chrome147 = nil Chrome148 = nil Chrome149 = nil + Chrome150 = nil + Chrome151 = nil + Chrome152 = nil + Chrome153 = nil + Chrome154 = nil + Chrome155 = nil + Chrome156 = nil + Chrome157 = nil + Chrome158 = nil Edge101 = nil Edge122 = nil @@ -102,6 +111,7 @@ class Profile Firefox149 = nil Firefox150 = nil Firefox151 = nil + Firefox152 = nil SafariIos17_2 = nil SafariIos17_4_1 = nil @@ -258,6 +268,17 @@ def hash # for HTTP/2 and automatic default headers. The actual implementation is # provided by Rust. # + # Profiles configure TLS over TCP, HTTP/2 and request headers. They do not + # configure HTTP/3 or QUIC fingerprints; HTTP/3 uses the backend defaults. + # + # Construction generates the native configuration once. For Chrome 152/153, + # the TLS trust_anchors extension's ID order is randomized at construction; + # Chrome 154 and later sort those IDs by their raw bytes instead. Reusing this object + # across clients or requests retains that order. Creating a new object generates + # a new configuration, including a fresh shuffle for Chrome 152/153. + # This does not freeze other per-handshake randomness or force a new handshake + # when a request reuses an existing connection. + # # `profile:` defaults to the library's default profile when omitted. # `platform:` defaults to the library's default platform when omitted. # @@ -283,6 +304,10 @@ class Emulation # Native fields and methods are set by the extension. # This stub is for documentation only. unless singleton_methods(false).include?(:new) + # Generates a reusable native configuration. Chrome 152/153 Trust Anchor ID + # order is chosen here and retained when this object is reused; Chrome 154–156 + # use raw-byte sorted order. See {Emulation} for connection semantics. + # # @param profile [Wreq::Profile, nil] Fingerprint profile to emulate # @param platform [Wreq::Platform, nil] Operating system platform to emulate # @param http2 [Boolean, nil] Whether HTTP/2 emulation is enabled; defaults diff --git a/lib/wreq_ruby/http.rb b/lib/wreq_ruby/http.rb index 2bf701e..4fb38fb 100644 --- a/lib/wreq_ruby/http.rb +++ b/lib/wreq_ruby/http.rb @@ -42,7 +42,7 @@ def to_sym # Value-based equality. Returns true when both represent the same HTTP method. # @param other [Object] - # @return [Boolean] + # @return [Boolean] unless method_defined?(:==) def ==(other) end @@ -77,7 +77,14 @@ class Version HTTP_10 = nil # @return [Wreq::Version] HTTP/1.0 HTTP_11 = nil # @return [Wreq::Version] HTTP/1.1 HTTP_2 = nil # @return [Wreq::Version] HTTP/2 - HTTP_3 = nil # @return [Wreq::Version] HTTP/3 + # Select HTTP/3 over QUIC with `version: Wreq::Version::HTTP_3` on a request. + # To use it by default, construct a client with `http3_only: true` instead. + # Requires an HTTPS URL and a reachable UDP endpoint. There is no automatic + # Alt-Svc discovery or fallback to HTTP/1.1 or HTTP/2. + # HTTP CONNECT proxies cannot carry these requests; use a direct connection, + # a SOCKS5 UDP relay or a `quic://` MASQUE proxy. + # @return [Wreq::Version] HTTP/3 + HTTP_3 = nil end # Returns a string representation of the HTTP version. diff --git a/src/client.rs b/src/client.rs index 1e25ecd..7859f65 100644 --- a/src/client.rs +++ b/src/client.rs @@ -76,11 +76,11 @@ struct Builder { tcp_reuse_address: Option, // ========= Connection pool options ========= - /// Set an optional timeout for idle sockets being kept-alive. (in seconds) + /// Idle connection reuse timeout, in seconds. pool_idle_timeout: Option, - /// Sets the maximum idle connection per host allowed in the pool. + /// Maximum idle HTTP/1 connections retained per compatibility group. pool_max_idle_per_host: Option, - /// Sets the maximum number of connections in the pool. + /// Maximum compatibility groups retaining reusable connections; zero is unlimited. pool_max_size: Option, // ========= Protocol options ========= @@ -88,6 +88,8 @@ struct Builder { http1_only: Option, /// Whether to use the HTTP/2 protocol only. http2_only: Option, + /// Whether to use HTTP/3 over QUIC without falling back to TCP. + http3_only: Option, /// Whether to use HTTPS only. https_only: Option, @@ -155,6 +157,7 @@ impl Builder { .reject_conflicts([ (stringify!(http1_only), builder.http1_only == Some(true)), (stringify!(http2_only), builder.http2_only == Some(true)), + (stringify!(http3_only), builder.http3_only == Some(true)), ]) .reject_conflicts([ (stringify!(proxy), options.is_non_nil(stringify!(proxy))), @@ -232,7 +235,7 @@ impl Client { .map(|jar| jar.clone_store(ruby)) .transpose()?; let result = gvl::nogvl(|| { - let mut builder = wreq::Client::builder(); + let mut builder = wreq::Client::builder_tokio(); // Emulation options. apply_option!(set_if_some_inner, builder, params.emulation, emulation); @@ -355,6 +358,7 @@ impl Client { // Protocol options. apply_option!(set_if_true, builder, params.http1_only, http1_only, false); apply_option!(set_if_true, builder, params.http2_only, http2_only, false); + apply_option!(set_if_true, builder, params.http3_only, http3_only, false); apply_option!(set_if_some, builder, params.https_only, https_only); // TLS options. diff --git a/src/emulate.rs b/src/emulate.rs index c1c20ac..bb3d45d 100644 --- a/src/emulate.rs +++ b/src/emulate.rs @@ -1,5 +1,6 @@ use ::serde::Deserialize; use magnus::{Error, Module, Object, RModule, Ruby, Value, function, method, typed_data::Obj}; +use wreq::IntoEmulation; use crate::options::{NativeOption, Options}; @@ -86,7 +87,15 @@ define_ruby_enum!( Chrome147, Chrome148, Chrome149, - + Chrome150, + Chrome151, + Chrome152, + Chrome153, + Chrome154, + Chrome155, + Chrome156, + Chrome157, + Chrome158, Edge101, Edge122, Edge127, @@ -106,7 +115,6 @@ define_ruby_enum!( Edge146, Edge147, Edge148, - Firefox109, Firefox117, Firefox128, @@ -127,7 +135,7 @@ define_ruby_enum!( Firefox149, Firefox150, Firefox151, - + Firefox152, SafariIos17_2, SafariIos17_4_1, SafariIos16_5, @@ -157,7 +165,6 @@ define_ruby_enum!( SafariIos26_2, SafariIPad26, SafariIpad26_2, - OkHttp3_9, OkHttp3_11, OkHttp3_13, @@ -166,7 +173,6 @@ define_ruby_enum!( OkHttp4_10, OkHttp4_12, OkHttp5, - Opera116, Opera117, Opera118, @@ -200,10 +206,13 @@ define_ruby_enum!( IOS => "ios", ); -/// A struct to represent the `EmulationOption` class. +/// Materialized emulation configuration owned by the Ruby object. +/// +/// Clients and requests clone this value rather than regenerating profile settings, +/// preserving configuration-level randomness for the lifetime of the object. #[derive(Clone)] #[magnus::wrap(class = "Wreq::Emulation", free_immediately, size)] -pub struct Emulation(pub wreq_util::Emulation); +pub struct Emulation(pub wreq::Emulation); // ===== impl Emulation ===== @@ -240,7 +249,8 @@ impl Emulation { ) .http2(params.http2.unwrap_or(true)) .headers(params.headers.unwrap_or(true)) - .build(); + .build() + .into_emulation(); Ok(Self(emulation)) } diff --git a/test/emulation_test.rb b/test/emulation_test.rb index 322edb7..5384458 100644 --- a/test/emulation_test.rb +++ b/test/emulation_test.rb @@ -1,8 +1,28 @@ # frozen_string_literal: true require "test_helper" +require "socket" +require "stringio" +require "timeout" class EmulationTest < Minitest::Test + def test_reused_emulation_retains_trust_anchors_across_clients_and_requests + [Wreq::Profile::Chrome152, Wreq::Profile::Chrome153, Wreq::Profile::Chrome154, Wreq::Profile::Chrome155, Wreq::Profile::Chrome156, Wreq::Profile::Chrome157].each do |profile| + emulation = Wreq::Emulation.new(profile: profile) + client = Wreq::Client.new(emulation: emulation, no_proxy: true) + expected = capture_trust_anchors { |url| client.get(url, timeout: 5) } + refute_empty expected, profile.to_s + + request_client = Wreq::Client.new(no_proxy: true) + 2.times do + actual = capture_trust_anchors do |url| + request_client.get(url, emulation: emulation, timeout: 5) + end + assert_equal expected, actual, "#{profile}: reusing an object must retain its configuration" + end + end + end + def test_all_emulation_device_constants_are_non_nil Wreq::Profile.constants.each do |name| const = Wreq::Profile.const_get(name) @@ -11,6 +31,29 @@ def test_all_emulation_device_constants_are_non_nil end end + def test_chrome151_profile_is_available + profile = Wreq::Profile::Chrome151 + + assert_equal "Chrome151", profile.to_s + assert_instance_of Wreq::Emulation, Wreq::Emulation.new(profile: profile) + end + + def test_new_browser_profiles_are_available + { + Wreq::Profile::Chrome152 => "Chrome152", + Wreq::Profile::Chrome153 => "Chrome153", + Wreq::Profile::Chrome154 => "Chrome154", + Wreq::Profile::Chrome155 => "Chrome155", + Wreq::Profile::Chrome156 => "Chrome156", + Wreq::Profile::Chrome157 => "Chrome157", + Wreq::Profile::Chrome158 => "Chrome158", + Wreq::Profile::Firefox152 => "Firefox152" + }.each do |profile, name| + assert_equal name, profile.to_s + assert_instance_of Wreq::Emulation, Wreq::Emulation.new(profile: profile) + end + end + def test_all_emulation_os_constants_are_non_nil Wreq::Platform.constants.each do |name| const = Wreq::Platform.const_get(name) @@ -18,4 +61,60 @@ def test_all_emulation_os_constants_are_non_nil "#{name} should be Platform, got #{const.inspect}" end end + + private + + # Each listener forces a new connection. Stop after ClientHello so this test + # inspects the extension bytes without depending on certificates or the network. + def capture_trust_anchors + server = TCPServer.new("127.0.0.1", 0) + thread = Thread.new do + socket = nil + Timeout.timeout(5) do + socket = server.accept + handshake = +"".b + loop do + header = read_tls_bytes(socket, 5) + raise "expected a TLS handshake record" unless header.getbyte(0) == 22 + handshake << read_tls_bytes(socket, header.byteslice(3, 2).unpack1("n")) + next if handshake.bytesize < 4 + length = handshake.byteslice(1, 3).bytes.reduce(0) { |n, byte| (n << 8) | byte } + break if handshake.bytesize >= length + 4 + end + trust_anchors_from_client_hello(handshake) + end + ensure + socket&.close + end + thread.report_on_exception = false + + assert_raises(Wreq::ConnectionError) { yield "https://127.0.0.1:#{server.addr[1]}/" } + thread.value + ensure + server&.close + thread&.kill if thread&.alive? + thread&.join + end + + def read_tls_bytes(io, length) + bytes = io.read(length) + raise EOFError, "truncated ClientHello" unless bytes&.bytesize == length + bytes + end + + def trust_anchors_from_client_hello(handshake) + io = StringIO.new(handshake) + raise "expected ClientHello" unless read_tls_bytes(io, 1).unpack1("C") == 1 + read_tls_bytes(io, 3 + 2 + 32) # Handshake length, legacy version and random. + read_tls_bytes(io, read_tls_bytes(io, 1).unpack1("C")) # Session ID. + read_tls_bytes(io, read_tls_bytes(io, 2).unpack1("n")) # Cipher suites. + read_tls_bytes(io, read_tls_bytes(io, 1).unpack1("C")) # Compression methods. + extensions = StringIO.new(read_tls_bytes(io, read_tls_bytes(io, 2).unpack1("n"))) + until extensions.eof? + type, length = read_tls_bytes(extensions, 4).unpack("nn") + data = read_tls_bytes(extensions, length) + return data if type == 51764 + end + raise "missing trust_anchors extension" + end end diff --git a/test/error_handling_test.rb b/test/error_handling_test.rb index e229dba..abee6f9 100644 --- a/test/error_handling_test.rb +++ b/test/error_handling_test.rb @@ -121,8 +121,47 @@ def test_proxy_error_handling end end + def test_proxy_tcp_connect_timeout_keeps_proxy_error + skip "Requires a stalled TCP handshake from a full loopback accept queue" unless RUBY_PLATFORM.include?("linux") || Gem.win_platform? + + with_stalled_tcp_listener do |port| + %w[http socks5h].each do |scheme| + client = Wreq::Client.new(proxy: "#{scheme}://127.0.0.1:#{port}", connect_timeout: 1, timeout: 5) + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) + + error = assert_raises(Wreq::ProxyConnectionError, "#{scheme} proxy TCP deadline") do + client.get("https://127.0.0.1:443/") + end + assert_instance_of Wreq::ProxyConnectionError, error + assert_operator Process.clock_gettime(Process::CLOCK_MONOTONIC) - start, :>=, 0.9, + "#{scheme} proxy should time out, not fail immediately" + end + end + end + private + def with_stalled_tcp_listener + sockets = [] + listener = Socket.new(:INET, :STREAM) + listener.bind(Socket.sockaddr_in(0, "127.0.0.1")) + listener.listen(0) + address = listener.local_address + + # Leave the accept queue full and verify a subsequent dial stays pending. + pending = 8.times.any? do + socket = Socket.new(:INET, :STREAM) + sockets << socket + socket.connect_nonblock(address, exception: false) == :wait_writable && + IO.select(nil, [socket], nil, 0.2).nil? + end + assert pending, "Expected a stalled TCP handshake on the loopback fixture" + yield address.ip_port + ensure + sockets.each(&:close) + listener&.close + end + def with_hanging_server server = TCPServer.new("127.0.0.1", 0) accepted = Queue.new diff --git a/test/option_validation_test.rb b/test/option_validation_test.rb index fce6e06..75c76c2 100644 --- a/test/option_validation_test.rb +++ b/test/option_validation_test.rb @@ -227,12 +227,21 @@ def test_authentication_options_are_mutually_exclusive end def test_protocol_only_options_are_mutually_exclusive - error = assert_raises(ArgumentError) do - Wreq::Client.new(http1_only: true, http2_only: true) + [:http1_only, :http2_only, :http3_only].combination(2) do |first, second| + error = assert_raises(ArgumentError) do + Wreq::Client.new(**{first => true, second => true}) + end + + assert_includes error.message, ":#{first}" + assert_includes error.message, ":#{second}" end - assert_includes error.message, ":http1_only" - assert_includes error.message, ":http2_only" + assert_instance_of Wreq::Client, + Wreq::Client.new(http3_only: true, http1_only: false, http2_only: nil) + assert_instance_of Wreq::Client, + Wreq::Client.new(http1_only: true, http3_only: false) + assert_instance_of Wreq::Client, + Wreq::Client.new(http2_only: true, http3_only: nil) end def test_validation_reports_the_first_failed_rule diff --git a/wreq.gemspec b/wreq.gemspec index 8fd8fb3..f4de445 100644 --- a/wreq.gemspec +++ b/wreq.gemspec @@ -56,7 +56,7 @@ Gem::Specification.new do |spec| # Exclude non-Ruby files from RDoc to prevent parsing errors spec.rdoc_options = ["--exclude", "Cargo\\..*", "--exclude", "\\.rs$"] - spec.requirements = ["Rust >= 1.97"] + spec.requirements = ["Rust >= 1.98"] # use a Ruby version which: # - supports Rubygems with the ability of compilation of Rust gem # - not end of life