Skip to content

Commit

Permalink
refactor(hickory-dns): async new_resolver (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x676e67 authored Aug 6, 2024
1 parent c6def57 commit 73ff128
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 5 additions & 1 deletion examples/headers_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Build a client to mimic Edge127
let client = rquest::Client::builder()
.impersonate(Impersonate::Edge127)
.header_order(vec![header::HOST, HeaderName::from_static("priority"), header::COOKIE])
.header_order(vec![
header::HOST,
HeaderName::from_static("priority"),
header::COOKIE,
])
.build()?;

// Use the API you're already familiar with
Expand Down
2 changes: 1 addition & 1 deletion src/blocking/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl ClientBuilder {
///
/// The host header needs to be manually inserted if you want to modify its order.
/// Otherwise it will be inserted by hyper after sorting.
pub fn header_order(mut self, order: Vec<HeaderName>) -> ClientBuilder {
pub fn header_order(self, order: Vec<HeaderName>) -> ClientBuilder {
self.with_inner(|inner| inner.header_order(order))
}

Expand Down
7 changes: 2 additions & 5 deletions src/dns/hickory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ impl Resolve for HickoryDnsResolver {
fn resolve(&self, name: Name) -> Resolving {
let resolver = self.clone();
Box::pin(async move {
let resolver = resolver
.state
.get_or_try_init(|| async { new_resolver() })
.await?;
let resolver = resolver.state.get_or_try_init(new_resolver).await?;

let lookup = resolver.lookup_ip(name.as_str()).await?;
let addrs: Addrs = Box::new(SocketAddrs {
Expand All @@ -48,7 +45,7 @@ impl Iterator for SocketAddrs {

/// Create a new resolver with the default configuration,
/// which reads from `/etc/resolve.conf`.
fn new_resolver() -> io::Result<TokioAsyncResolver> {
async fn new_resolver() -> io::Result<TokioAsyncResolver> {
let (config, opts) = system_conf::read_system_conf().map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
Expand Down

0 comments on commit 73ff128

Please sign in to comment.