src/client/http_client.rs: simplify send_request

This commit is contained in:
Dietmar Maurer 2019-09-05 15:07:37 +02:00
parent 9edd3bf1b8
commit 2a05048b93

View File

@ -1133,12 +1133,12 @@ impl H2Client {
let mut send_request = self.h2.clone().ready().await?; let mut send_request = self.h2.clone().ready().await?;
let (response, stream) = send_request.send_request(request, false).unwrap(); let (response, stream) = send_request.send_request(request, false).unwrap();
PipeToSendStream::new(bytes::Bytes::from(data), stream)
.and_then(|_| { PipeToSendStream::new(bytes::Bytes::from(data), stream).await?;
response
.map_err(Error::from) response
.and_then(Self::h2api_response) .map_err(Error::from)
}) .and_then(Self::h2api_response)
.await .await
} }
@ -1165,16 +1165,14 @@ impl H2Client {
self.h2.clone() self.h2.clone()
.ready() .ready()
.map_err(Error::from) .map_err(Error::from)
.and_then(move |mut send_request| { .and_then(move |mut send_request| async move {
if let Some(data) = data { if let Some(data) = data {
let (response, stream) = send_request.send_request(request, false).unwrap(); let (response, stream) = send_request.send_request(request, false).unwrap();
future::Either::Left(PipeToSendStream::new(data, stream) PipeToSendStream::new(data, stream).await?;
.and_then(move |_| { Ok(response)
future::ok(response)
}))
} else { } else {
let (response, _stream) = send_request.send_request(request, true).unwrap(); let (response, _stream) = send_request.send_request(request, true).unwrap();
future::Either::Right(future::ok(response)) Ok(response)
} }
}) })
} }