From 8622a5068be5652ece1669dcf07ead68dabda52e Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Thu, 21 Mar 2024 20:04:42 +0800 Subject: [PATCH] feat: merge to reqwest:0.12.0 remove hyper --- rust/Cargo.toml | 17 ++++++++--------- rust/src/api/http_api.rs | 2 +- rust/src/http_package/dns.rs | 9 ++++----- rust/src/http_package/mod.rs | 4 ++-- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 7eb0232..829fbba 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -12,14 +12,13 @@ crate-type = ["cdylib", "staticlib"] [dependencies] flutter_rust_bridge = "=2.0.0-dev.28" -tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros","process"] } -url = "2.5.0" -async-std = "1.12.0" -hyper = { version = "0.14.28"} -once_cell = "1.19.0" -reqwest = { version = "0.11", features = ["rustls-tls-webpki-roots", "cookies", "gzip", "json","stream"] } -hickory-resolver = {version = "0.24.0"} +tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros", "process"] } +url = "2.5" +async-std = "1.12" +once_cell = "1.19" +reqwest = { version = "0.12", features = ["rustls-tls-webpki-roots", "cookies", "gzip", "json", "stream"] } +hickory-resolver = { version = "0.24" } anyhow = "1.0" win32job = "2" -lazy_static = "1.4.0" -scopeguard = "1.2.0" +lazy_static = "1.4" +scopeguard = "1.2" diff --git a/rust/src/api/http_api.rs b/rust/src/api/http_api.rs index b13a5ad..fe3a702 100644 --- a/rust/src/api/http_api.rs +++ b/rust/src/api/http_api.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use hyper::Method; +use reqwest::Method; use crate::http_package; use crate::http_package::RustHttpResponse; diff --git a/rust/src/http_package/dns.rs b/rust/src/http_package/dns.rs index 6e85766..16fa84c 100644 --- a/rust/src/http_package/dns.rs +++ b/rust/src/http_package/dns.rs @@ -1,8 +1,7 @@ use hickory_resolver::config::{NameServerConfigGroup, ResolverConfig, ResolverOpts}; use hickory_resolver::{lookup_ip::LookupIpIntoIter, TokioAsyncResolver}; -use hyper::client::connect::dns::Name; use once_cell::sync::OnceCell; -use reqwest::dns::{Addrs, Resolve, Resolving}; +use reqwest::dns::{Addrs, Name, Resolve, Resolving}; use std::collections::HashMap; use std::io; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; @@ -29,8 +28,8 @@ struct SocketAddrs { impl Resolve for MyHickoryDnsResolver { fn resolve(&self, name: Name) -> Resolving { let my_hosts = MY_HOSTS_MAP.read().unwrap(); - let name_str = name.to_string(); - if let Some(ip) = my_hosts.get(name_str.as_str()) { + let name_str = name.as_str(); + if let Some(ip) = my_hosts.get(name_str) { let addrs: Addrs = Box::new(std::iter::once(SocketAddr::new(*ip, 0))); println!("using host map === {:?}", name_str); return Box::pin(async move { Ok(addrs) }); @@ -89,7 +88,7 @@ fn new_resolver() -> io::Result { IpAddr::V4(Ipv4Addr::new(166, 111, 8, 28)), IpAddr::V4(Ipv4Addr::new(101, 226, 4, 6)), IpAddr::V4(Ipv4Addr::new(114, 114, 114, 114)), - ], 53, true, + ], 53, false, ); let cfg = ResolverConfig::from_parts(None, vec![], group); let mut opts = ResolverOpts::default(); diff --git a/rust/src/http_package/mod.rs b/rust/src/http_package/mod.rs index b55551e..067a7db 100644 --- a/rust/src/http_package/mod.rs +++ b/rust/src/http_package/mod.rs @@ -2,13 +2,13 @@ pub mod dns; use scopeguard::defer; use lazy_static::lazy_static; -use hyper::Uri; use reqwest::header::{HeaderMap, HeaderName, HeaderValue}; use reqwest::{Method, RequestBuilder}; use std::collections::HashMap; use std::str::FromStr; use std::sync::{Arc, RwLock}; use std::time::Duration; +use url::Url; #[derive(Debug)] #[allow(non_camel_case_types)] @@ -88,7 +88,7 @@ pub async fn fetch( if address_clone.is_some() { let addr = std::net::IpAddr::from_str(with_ip_address.unwrap().as_str()).unwrap(); let mut hosts = dns::MY_HOSTS_MAP.write().unwrap(); - let url_host = Uri::from_str(url.as_str()).unwrap().host().unwrap().to_string(); + let url_host = Url::from_str(url.as_str()).unwrap().host().unwrap().to_string(); hosts.insert(url_host, addr); }