Is it possible to use this legacy https client also for a simple DELETE call?

25 views Asked by At

I have this hyper client:

use http_body_util::{combinators::UnsyncBoxBody, BodyExt, BodyStream, StreamBody};
use hyper_tls::HttpsConnector;
use hyper_util::{
  client::legacy::{self, connect::HttpConnector},
  rt::TokioExecutor,
}
use tokio_util::{
  bytes::Bytes,
  io::{ReaderStream, StreamReader},
};

pub struct HttpsClient {
  legacy_client: legacy::Client<HttpsConnector<HttpConnector>, UnsyncBoxBody<Bytes, std::io::Error>>,
}

and I'm using legacy_client for code like:

legacy_client
  .request(
    hyper::Request::builder()
      .method(Method::PUT)
      .uri(uri)
      .header(header::CONTENT_LENGTH, size)
      .body(BodyExt::boxed_unsync(StreamBody::new(ReaderStream::new(stream).map_ok(Frame::data))))
      .unwrap(),
  )
  .await?;

Now I would like to use that legacy_client also for a simple DELETE call. Is it possible?

I tried with:

let req = hyper::Request::builder()
  .uri(uri)
  .method("DELETE")
  .body(())
  .unwrap();

let resp = legacy_client.request(req).await?;

but it throws with:

error[E0308]: mismatched types
    |
128 |     let resp = legacy_client.request(req).await?;
    |                              ------- ^^^ expected `Request<UnsyncBoxBody<Bytes, ...>>`, found `Request<()>`
    |                              |
    |                              arguments to this method are incorrect
    |
    = note: expected struct `hyper::Request<http_body_util::combinators::UnsyncBoxBody<hyper::body::Bytes, std::io::Error>>`
               found struct `hyper::Request<()>`
note: method defined here
    |
201 |     pub fn request(&self, mut req: Request<B>) -> ResponseFuture {
    |            ^^^^^^^

How can I fix this?

I would like to use the hyper_util::client::legacy because I don't want to add another dependency such as "reqwest" to my project.

0

There are 0 answers