Skip to content

Commit

Permalink
implement http body trait method
Browse files Browse the repository at this point in the history
Signed-off-by: tottoto <[email protected]>
  • Loading branch information
tottoto committed Mar 29, 2024
1 parent ff5a9e4 commit 044452d
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(),

Check warning on line 92 in kube-client/src/client/body.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/body.rs#L91-L92

Added lines #L91 - L92 were not covered by tests
}
}

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(),

Check warning on line 100 in kube-client/src/client/body.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/body.rs#L100

Added line #L100 was not covered by tests
}
}
}

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

0 comments on commit 044452d

Please sign in to comment.