5

My code looks like the following:

let fetches = futures::stream::iter(
    hosts.into_iter().map(|url| {
        async move {
                match reqwest::get(&url).await {
                    // Ok and Err statements here!
                }

But, the problem here is that it gives an error for URLs with invalid or self-signed SSL certificate. So, I tried to do the following:

let fetches = futures::stream::iter(
    hosts.into_iter().map(|url| {
        async move {
            match reqwest::Client::builder().danger_accept_invalid_certs(true).build().unwrap().get(&url).await {
                // Ok and Err statements here!
            }

When I try to build it with Cargo, it says "error[E0277]: `RequestBuilder` is not a future".

So, how can I make my code accept invalid certificates?

Binit Ghimire
  • 53
  • 1
  • 5

1 Answers1

6

Unlike the top-level get() function, which returns a Response, the Client::get() method which you call in the second snippet, returns a RequestBuilder, which you must send() to actually communicate.

Adding the missing send() allows the code to compile (playgropund):

fn main() {
    let hosts: Vec<String> = vec![];
    let fetches = futures::stream::iter(hosts.into_iter().map(|url| async move {
        match reqwest::Client::builder()
            .danger_accept_invalid_certs(true)
            .build()
            .unwrap()
            .get(&url)
            .send()
            .await
        {
            Ok(x) => x,
            Err(x) => panic!(),
        }
    }));
}
user4815162342
  • 141,790
  • 18
  • 296
  • 355
  • Thank you for your answer! It worked for me as the code compiled. However, I am still unable to solve my major problem of accepting URLs with invalid or self-signed SSL certificates. Is there any idea regarding this? – Binit Ghimire Jan 31 '21 at 12:14
  • @BinitGhimire I would expect accept_invalid_certs to fix that. If it doesn't, you might want to raise an issue at the [project issue tracker](https://github.com/seanmonstar/reqwest). – user4815162342 Jan 31 '21 at 12:17