2019-11-15 10:54:11 +01:00
|
|
|
use std::task::{Context, Poll};
|
2021-03-07 20:29:02 +01:00
|
|
|
use std::{cmp, future::Future, marker::PhantomData, net, pin::Pin, rc::Rc};
|
2019-02-06 20:44:15 +01:00
|
|
|
|
|
|
|
use actix_codec::{AsyncRead, AsyncWrite};
|
|
|
|
use actix_service::Service;
|
|
|
|
use bytes::{Bytes, BytesMut};
|
2021-01-04 01:49:02 +01:00
|
|
|
use futures_core::ready;
|
2021-03-11 04:48:38 +01:00
|
|
|
use h2::{
|
|
|
|
server::{Connection, SendResponse},
|
|
|
|
SendStream,
|
|
|
|
};
|
2019-12-13 05:59:02 +01:00
|
|
|
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING};
|
|
|
|
use log::{error, trace};
|
2019-02-06 20:44:15 +01:00
|
|
|
|
2021-05-09 21:12:48 +02:00
|
|
|
use crate::body::{Body, BodySize, MessageBody};
|
2019-02-06 20:44:15 +01:00
|
|
|
use crate::config::ServiceConfig;
|
2019-12-13 05:59:02 +01:00
|
|
|
use crate::error::{DispatchError, Error};
|
2019-02-06 20:44:15 +01:00
|
|
|
use crate::message::ResponseHead;
|
2019-02-07 22:41:50 +01:00
|
|
|
use crate::payload::Payload;
|
2019-02-06 20:44:15 +01:00
|
|
|
use crate::request::Request;
|
|
|
|
use crate::response::Response;
|
2021-01-06 19:43:52 +01:00
|
|
|
use crate::service::HttpFlow;
|
|
|
|
use crate::OnConnectData;
|
2019-02-06 20:44:15 +01:00
|
|
|
|
|
|
|
const CHUNK_SIZE: usize = 16_384;
|
|
|
|
|
2021-01-04 01:49:02 +01:00
|
|
|
/// Dispatcher for HTTP/2 protocol.
|
2019-11-19 13:54:19 +01:00
|
|
|
#[pin_project::pin_project]
|
2021-01-06 19:43:52 +01:00
|
|
|
pub struct Dispatcher<T, S, B, X, U>
|
2019-12-02 12:33:11 +01:00
|
|
|
where
|
|
|
|
T: AsyncRead + AsyncWrite + Unpin,
|
2021-01-04 00:47:04 +01:00
|
|
|
S: Service<Request>,
|
|
|
|
B: MessageBody,
|
2019-12-02 12:33:11 +01:00
|
|
|
{
|
2021-02-07 02:00:40 +01:00
|
|
|
flow: Rc<HttpFlow<S, X, U>>,
|
2019-02-06 20:44:15 +01:00
|
|
|
connection: Connection<T, Bytes>,
|
2021-01-06 19:43:52 +01:00
|
|
|
on_connect_data: OnConnectData,
|
2019-02-06 20:44:15 +01:00
|
|
|
config: ServiceConfig,
|
2019-04-16 18:54:02 +02:00
|
|
|
peer_addr: Option<net::SocketAddr>,
|
2021-01-04 01:49:02 +01:00
|
|
|
_phantom: PhantomData<B>,
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
|
|
|
|
2021-01-06 19:43:52 +01:00
|
|
|
impl<T, S, B, X, U> Dispatcher<T, S, B, X, U>
|
2019-02-06 20:44:15 +01:00
|
|
|
where
|
2019-12-02 12:33:11 +01:00
|
|
|
T: AsyncRead + AsyncWrite + Unpin,
|
2021-01-04 00:47:04 +01:00
|
|
|
S: Service<Request>,
|
2019-11-20 18:33:22 +01:00
|
|
|
S::Error: Into<Error>,
|
|
|
|
S::Response: Into<Response<B>>,
|
|
|
|
B: MessageBody,
|
2019-02-06 20:44:15 +01:00
|
|
|
{
|
2019-06-28 10:34:26 +02:00
|
|
|
pub(crate) fn new(
|
2021-02-07 02:00:40 +01:00
|
|
|
flow: Rc<HttpFlow<S, X, U>>,
|
2019-02-06 20:44:15 +01:00
|
|
|
connection: Connection<T, Bytes>,
|
2021-01-06 19:43:52 +01:00
|
|
|
on_connect_data: OnConnectData,
|
2019-02-06 20:44:15 +01:00
|
|
|
config: ServiceConfig,
|
2019-04-16 18:54:02 +02:00
|
|
|
peer_addr: Option<net::SocketAddr>,
|
2019-02-06 20:44:15 +01:00
|
|
|
) -> Self {
|
|
|
|
Dispatcher {
|
2021-02-07 02:00:40 +01:00
|
|
|
flow,
|
2019-02-06 20:44:15 +01:00
|
|
|
config,
|
2019-04-16 18:54:02 +02:00
|
|
|
peer_addr,
|
|
|
|
connection,
|
2020-10-30 03:03:26 +01:00
|
|
|
on_connect_data,
|
2021-01-04 01:49:02 +01:00
|
|
|
_phantom: PhantomData,
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-06 19:43:52 +01:00
|
|
|
impl<T, S, B, X, U> Future for Dispatcher<T, S, B, X, U>
|
2019-02-06 20:44:15 +01:00
|
|
|
where
|
2019-12-02 12:33:11 +01:00
|
|
|
T: AsyncRead + AsyncWrite + Unpin,
|
2021-05-05 19:36:02 +02:00
|
|
|
|
2021-01-04 00:47:04 +01:00
|
|
|
S: Service<Request>,
|
2019-11-19 13:54:19 +01:00
|
|
|
S::Error: Into<Error> + 'static,
|
|
|
|
S::Future: 'static,
|
|
|
|
S::Response: Into<Response<B>> + 'static,
|
2021-05-05 19:36:02 +02:00
|
|
|
|
2019-02-06 20:44:15 +01:00
|
|
|
B: MessageBody + 'static,
|
2021-05-05 19:36:02 +02:00
|
|
|
B::Error: Into<Error>,
|
2019-02-06 20:44:15 +01:00
|
|
|
{
|
2019-11-15 10:54:11 +01:00
|
|
|
type Output = Result<(), DispatchError>;
|
2019-02-06 20:44:15 +01:00
|
|
|
|
|
|
|
#[inline]
|
2019-12-07 19:46:51 +01:00
|
|
|
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
2019-11-15 10:54:11 +01:00
|
|
|
let this = self.get_mut();
|
|
|
|
|
2019-02-06 20:44:15 +01:00
|
|
|
loop {
|
2021-01-04 01:49:02 +01:00
|
|
|
match ready!(Pin::new(&mut this.connection).poll_accept(cx)) {
|
|
|
|
None => return Poll::Ready(Ok(())),
|
|
|
|
|
|
|
|
Some(Err(err)) => return Poll::Ready(Err(err.into())),
|
|
|
|
|
|
|
|
Some(Ok((req, res))) => {
|
2019-02-06 20:44:15 +01:00
|
|
|
let (parts, body) = req.into_parts();
|
2021-01-04 01:49:02 +01:00
|
|
|
let pl = crate::h2::Payload::new(body);
|
|
|
|
let pl = Payload::<crate::payload::PayloadStream>::H2(pl);
|
|
|
|
let mut req = Request::with_payload(pl);
|
2019-02-06 20:44:15 +01:00
|
|
|
|
2021-03-07 20:29:02 +01:00
|
|
|
let head = req.head_mut();
|
2019-02-06 20:44:15 +01:00
|
|
|
head.uri = parts.uri;
|
|
|
|
head.method = parts.method;
|
|
|
|
head.version = parts.version;
|
2019-04-07 00:02:02 +02:00
|
|
|
head.headers = parts.headers.into();
|
2019-11-15 10:54:11 +01:00
|
|
|
head.peer_addr = this.peer_addr;
|
2019-09-01 09:15:02 +02:00
|
|
|
|
2020-10-30 03:03:26 +01:00
|
|
|
// merge on_connect_ext data into request extensions
|
2021-01-06 19:43:52 +01:00
|
|
|
this.on_connect_data.merge_into(&mut req);
|
2020-10-30 03:03:26 +01:00
|
|
|
|
2021-03-08 21:00:20 +01:00
|
|
|
let svc = ServiceResponse {
|
2019-11-19 13:54:19 +01:00
|
|
|
state: ServiceResponseState::ServiceCall(
|
2021-02-07 02:00:40 +01:00
|
|
|
this.flow.service.call(req),
|
2019-11-19 13:54:19 +01:00
|
|
|
Some(res),
|
|
|
|
),
|
|
|
|
config: this.config.clone(),
|
|
|
|
buffer: None,
|
2021-01-04 01:49:02 +01:00
|
|
|
_phantom: PhantomData,
|
|
|
|
};
|
|
|
|
|
|
|
|
actix_rt::spawn(svc);
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 13:54:19 +01:00
|
|
|
#[pin_project::pin_project]
|
2019-11-15 10:54:11 +01:00
|
|
|
struct ServiceResponse<F, I, E, B> {
|
2020-01-28 04:35:51 +01:00
|
|
|
#[pin]
|
2019-04-04 19:59:34 +02:00
|
|
|
state: ServiceResponseState<F, B>,
|
2019-02-06 20:44:15 +01:00
|
|
|
config: ServiceConfig,
|
|
|
|
buffer: Option<Bytes>,
|
2021-01-04 01:49:02 +01:00
|
|
|
_phantom: PhantomData<(I, E)>,
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
|
|
|
|
2020-06-05 23:44:14 +02:00
|
|
|
#[pin_project::pin_project(project = ServiceResponseStateProj)]
|
2019-04-04 19:59:34 +02:00
|
|
|
enum ServiceResponseState<F, B> {
|
2020-01-28 04:35:51 +01:00
|
|
|
ServiceCall(#[pin] F, Option<SendResponse<Bytes>>),
|
2021-05-09 21:12:48 +02:00
|
|
|
SendPayload(SendStream<Bytes>, #[pin] B),
|
|
|
|
SendErrorPayload(SendStream<Bytes>, #[pin] Body),
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
|
|
|
|
2019-11-15 10:54:11 +01:00
|
|
|
impl<F, I, E, B> ServiceResponse<F, I, E, B>
|
2019-02-06 20:44:15 +01:00
|
|
|
where
|
2019-11-19 13:54:19 +01:00
|
|
|
F: Future<Output = Result<I, E>>,
|
2019-11-20 18:33:22 +01:00
|
|
|
E: Into<Error>,
|
|
|
|
I: Into<Response<B>>,
|
2021-05-05 19:36:02 +02:00
|
|
|
|
2019-11-20 18:33:22 +01:00
|
|
|
B: MessageBody,
|
2021-05-05 19:36:02 +02:00
|
|
|
B::Error: Into<Error>,
|
2019-02-06 20:44:15 +01:00
|
|
|
{
|
|
|
|
fn prepare_response(
|
|
|
|
&self,
|
|
|
|
head: &ResponseHead,
|
2019-04-10 21:24:17 +02:00
|
|
|
size: &mut BodySize,
|
2019-02-06 20:44:15 +01:00
|
|
|
) -> http::Response<()> {
|
|
|
|
let mut has_date = false;
|
2019-04-10 21:24:17 +02:00
|
|
|
let mut skip_len = size != &BodySize::Stream;
|
2019-02-06 20:44:15 +01:00
|
|
|
|
|
|
|
let mut res = http::Response::new(());
|
|
|
|
*res.status_mut() = head.status;
|
|
|
|
*res.version_mut() = http::Version::HTTP_2;
|
|
|
|
|
|
|
|
// Content length
|
|
|
|
match head.status {
|
|
|
|
http::StatusCode::NO_CONTENT
|
|
|
|
| http::StatusCode::CONTINUE
|
2019-04-10 21:24:17 +02:00
|
|
|
| http::StatusCode::PROCESSING => *size = BodySize::None,
|
2019-02-06 20:44:15 +01:00
|
|
|
http::StatusCode::SWITCHING_PROTOCOLS => {
|
|
|
|
skip_len = true;
|
2019-04-10 21:24:17 +02:00
|
|
|
*size = BodySize::Stream;
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
2021-01-04 01:49:02 +01:00
|
|
|
_ => {}
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
2021-01-04 01:49:02 +01:00
|
|
|
|
2019-04-10 21:24:17 +02:00
|
|
|
let _ = match size {
|
2019-03-27 17:24:55 +01:00
|
|
|
BodySize::None | BodySize::Stream => None,
|
|
|
|
BodySize::Empty => res
|
2019-02-06 20:44:15 +01:00
|
|
|
.headers_mut()
|
|
|
|
.insert(CONTENT_LENGTH, HeaderValue::from_static("0")),
|
2021-03-07 20:29:02 +01:00
|
|
|
BodySize::Sized(len) => {
|
|
|
|
let mut buf = itoa::Buffer::new();
|
|
|
|
|
|
|
|
res.headers_mut().insert(
|
|
|
|
CONTENT_LENGTH,
|
|
|
|
HeaderValue::from_str(buf.format(*len)).unwrap(),
|
|
|
|
)
|
|
|
|
}
|
2019-02-06 20:44:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// copy headers
|
|
|
|
for (key, value) in head.headers.iter() {
|
|
|
|
match *key {
|
2021-03-07 20:29:02 +01:00
|
|
|
// TODO: consider skipping other headers according to:
|
|
|
|
// https://tools.ietf.org/html/rfc7540#section-8.1.2.2
|
|
|
|
// omit HTTP/1.x only headers
|
2021-01-04 01:49:02 +01:00
|
|
|
CONNECTION | TRANSFER_ENCODING => continue,
|
2019-02-06 20:44:15 +01:00
|
|
|
CONTENT_LENGTH if skip_len => continue,
|
|
|
|
DATE => has_date = true,
|
2021-01-04 01:49:02 +01:00
|
|
|
_ => {}
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
2021-01-04 01:49:02 +01:00
|
|
|
|
2019-02-06 20:44:15 +01:00
|
|
|
res.headers_mut().append(key, value.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
// set date header
|
|
|
|
if !has_date {
|
|
|
|
let mut bytes = BytesMut::with_capacity(29);
|
|
|
|
self.config.set_date_header(&mut bytes);
|
2020-09-03 11:00:24 +02:00
|
|
|
res.headers_mut().insert(
|
|
|
|
DATE,
|
|
|
|
// SAFETY: serialized date-times are known ASCII strings
|
|
|
|
unsafe { HeaderValue::from_maybe_shared_unchecked(bytes.freeze()) },
|
|
|
|
);
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-15 10:54:11 +01:00
|
|
|
impl<F, I, E, B> Future for ServiceResponse<F, I, E, B>
|
2019-02-06 20:44:15 +01:00
|
|
|
where
|
2019-11-19 13:54:19 +01:00
|
|
|
F: Future<Output = Result<I, E>>,
|
2019-11-20 18:33:22 +01:00
|
|
|
E: Into<Error>,
|
|
|
|
I: Into<Response<B>>,
|
2021-05-05 19:36:02 +02:00
|
|
|
|
2019-11-20 18:33:22 +01:00
|
|
|
B: MessageBody,
|
2021-05-05 19:36:02 +02:00
|
|
|
B::Error: Into<Error>,
|
2019-02-06 20:44:15 +01:00
|
|
|
{
|
2019-11-15 10:54:11 +01:00
|
|
|
type Output = ();
|
|
|
|
|
2019-12-07 19:46:51 +01:00
|
|
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
2019-11-19 13:54:19 +01:00
|
|
|
let mut this = self.as_mut().project();
|
2019-02-06 20:44:15 +01:00
|
|
|
|
2020-01-28 04:35:51 +01:00
|
|
|
match this.state.project() {
|
2021-01-04 01:49:02 +01:00
|
|
|
ServiceResponseStateProj::ServiceCall(call, send) => {
|
|
|
|
match ready!(call.poll(cx)) {
|
|
|
|
Ok(res) => {
|
|
|
|
let (res, body) = res.into().replace_body(());
|
|
|
|
|
|
|
|
let mut send = send.take().unwrap();
|
|
|
|
let mut size = body.size();
|
|
|
|
let h2_res =
|
|
|
|
self.as_mut().prepare_response(res.head(), &mut size);
|
|
|
|
this = self.as_mut().project();
|
|
|
|
|
|
|
|
let stream = match send.send_response(h2_res, size.is_eof()) {
|
|
|
|
Err(e) => {
|
|
|
|
trace!("Error sending HTTP/2 response: {:?}", e);
|
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
Ok(stream) => stream,
|
|
|
|
};
|
2019-02-06 20:44:15 +01:00
|
|
|
|
2021-01-04 01:49:02 +01:00
|
|
|
if size.is_eof() {
|
|
|
|
Poll::Ready(())
|
|
|
|
} else {
|
|
|
|
this.state
|
|
|
|
.set(ServiceResponseState::SendPayload(stream, body));
|
|
|
|
self.poll(cx)
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
2021-01-04 01:49:02 +01:00
|
|
|
}
|
|
|
|
|
2021-04-13 12:16:12 +02:00
|
|
|
Err(err) => {
|
|
|
|
let res = Response::from_error(err.into());
|
2021-01-04 01:49:02 +01:00
|
|
|
let (res, body) = res.replace_body(());
|
|
|
|
|
|
|
|
let mut send = send.take().unwrap();
|
|
|
|
let mut size = body.size();
|
|
|
|
let h2_res =
|
|
|
|
self.as_mut().prepare_response(res.head(), &mut size);
|
|
|
|
this = self.as_mut().project();
|
2020-02-27 03:10:55 +01:00
|
|
|
|
2021-01-04 01:49:02 +01:00
|
|
|
let stream = match send.send_response(h2_res, size.is_eof()) {
|
|
|
|
Err(e) => {
|
|
|
|
trace!("Error sending HTTP/2 response: {:?}", e);
|
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
Ok(stream) => stream,
|
|
|
|
};
|
|
|
|
|
|
|
|
if size.is_eof() {
|
|
|
|
Poll::Ready(())
|
|
|
|
} else {
|
2021-05-09 21:12:48 +02:00
|
|
|
this.state.set(ServiceResponseState::SendErrorPayload(
|
|
|
|
stream, body,
|
2021-01-04 01:49:02 +01:00
|
|
|
));
|
|
|
|
self.poll(cx)
|
|
|
|
}
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-04 01:49:02 +01:00
|
|
|
}
|
|
|
|
|
2020-07-22 01:28:33 +02:00
|
|
|
ServiceResponseStateProj::SendPayload(ref mut stream, ref mut body) => {
|
2019-02-06 20:44:15 +01:00
|
|
|
loop {
|
2021-03-08 21:00:20 +01:00
|
|
|
match this.buffer {
|
|
|
|
Some(ref mut buffer) => match ready!(stream.poll_capacity(cx)) {
|
|
|
|
None => return Poll::Ready(()),
|
|
|
|
|
|
|
|
Some(Ok(cap)) => {
|
|
|
|
let len = buffer.len();
|
|
|
|
let bytes = buffer.split_to(cmp::min(cap, len));
|
2021-01-04 01:49:02 +01:00
|
|
|
|
2021-03-08 21:00:20 +01:00
|
|
|
if let Err(e) = stream.send_data(bytes, false) {
|
|
|
|
warn!("{:?}", e);
|
2020-07-22 01:28:33 +02:00
|
|
|
return Poll::Ready(());
|
2021-03-08 21:00:20 +01:00
|
|
|
} else if !buffer.is_empty() {
|
|
|
|
let cap = cmp::min(buffer.len(), CHUNK_SIZE);
|
|
|
|
stream.reserve_capacity(cap);
|
|
|
|
} else {
|
|
|
|
this.buffer.take();
|
2020-07-22 01:28:33 +02:00
|
|
|
}
|
2021-03-08 21:00:20 +01:00
|
|
|
}
|
2021-01-04 01:49:02 +01:00
|
|
|
|
2021-03-08 21:00:20 +01:00
|
|
|
Some(Err(e)) => {
|
|
|
|
warn!("{:?}", e);
|
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
},
|
2021-01-04 01:49:02 +01:00
|
|
|
|
2021-03-08 21:00:20 +01:00
|
|
|
None => match ready!(body.as_mut().poll_next(cx)) {
|
|
|
|
None => {
|
|
|
|
if let Err(e) = stream.send_data(Bytes::new(), true) {
|
|
|
|
warn!("{:?}", e);
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
2021-03-08 21:00:20 +01:00
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(Ok(chunk)) => {
|
|
|
|
stream
|
|
|
|
.reserve_capacity(cmp::min(chunk.len(), CHUNK_SIZE));
|
|
|
|
*this.buffer = Some(chunk);
|
|
|
|
}
|
|
|
|
|
2021-05-09 21:12:48 +02:00
|
|
|
Some(Err(err)) => {
|
|
|
|
error!(
|
|
|
|
"Response payload stream error: {:?}",
|
|
|
|
err.into()
|
|
|
|
);
|
|
|
|
|
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ServiceResponseStateProj::SendErrorPayload(ref mut stream, ref mut body) => {
|
|
|
|
// TODO: de-dupe impl with SendPayload
|
|
|
|
|
|
|
|
loop {
|
|
|
|
match this.buffer {
|
|
|
|
Some(ref mut buffer) => match ready!(stream.poll_capacity(cx)) {
|
|
|
|
None => return Poll::Ready(()),
|
|
|
|
|
|
|
|
Some(Ok(cap)) => {
|
|
|
|
let len = buffer.len();
|
|
|
|
let bytes = buffer.split_to(cmp::min(cap, len));
|
|
|
|
|
|
|
|
if let Err(e) = stream.send_data(bytes, false) {
|
|
|
|
warn!("{:?}", e);
|
|
|
|
return Poll::Ready(());
|
|
|
|
} else if !buffer.is_empty() {
|
|
|
|
let cap = cmp::min(buffer.len(), CHUNK_SIZE);
|
|
|
|
stream.reserve_capacity(cap);
|
|
|
|
} else {
|
|
|
|
this.buffer.take();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-08 21:00:20 +01:00
|
|
|
Some(Err(e)) => {
|
2021-05-09 21:12:48 +02:00
|
|
|
warn!("{:?}", e);
|
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
None => match ready!(body.as_mut().poll_next(cx)) {
|
|
|
|
None => {
|
|
|
|
if let Err(e) = stream.send_data(Bytes::new(), true) {
|
|
|
|
warn!("{:?}", e);
|
|
|
|
}
|
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(Ok(chunk)) => {
|
|
|
|
stream
|
|
|
|
.reserve_capacity(cmp::min(chunk.len(), CHUNK_SIZE));
|
|
|
|
*this.buffer = Some(chunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(Err(err)) => {
|
|
|
|
error!("Response payload stream error: {:?}", err);
|
|
|
|
|
2021-03-08 21:00:20 +01:00
|
|
|
return Poll::Ready(());
|
|
|
|
}
|
|
|
|
},
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
|
|
|
}
|
2020-07-22 01:28:33 +02:00
|
|
|
}
|
2019-02-06 20:44:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|