Skip to content

Commit

Permalink
implement http body trait method (#1452)
Browse files Browse the repository at this point in the history
Signed-off-by: tottoto <tottotodev@gmail.com>
  • Loading branch information
tottoto authored Mar 30, 2024
1 parent ff5a9e4 commit 02c99f2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion kube-client/src/client/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

use bytes::Bytes;
use futures::stream::Stream;
use http_body::{Body as HttpBody, Frame};
use http_body::{Body as HttpBody, Frame, SizeHint};
use http_body_util::{combinators::UnsyncBoxBody, BodyExt};
use pin_project::pin_project;

Expand Down Expand Up @@ -84,6 +84,22 @@ impl HttpBody for Body {
),
}
}

fn size_hint(&self) -> SizeHint {
match &self.kind {
Kind::Once(Some(bytes)) => SizeHint::with_exact(bytes.len() as u64),
Kind::Once(None) => SizeHint::with_exact(0),
Kind::Wrap(body) => body.size_hint(),
}
}

fn is_end_stream(&self) -> bool {
match &self.kind {
Kind::Once(Some(bytes)) => bytes.is_empty(),
Kind::Once(None) => true,
Kind::Wrap(body) => body.is_end_stream(),
}
}
}

// Wrap `http_body::Body` to implement `Stream`.
Expand Down

0 comments on commit 02c99f2

Please sign in to comment.