tower_http/follow_redirect/policy/
clone_body_fn.rs1use super::{Action, Attempt, Policy};
2use std::fmt;
3
4#[derive(Clone, Copy)]
8pub struct CloneBodyFn<F> {
9 f: F,
10}
11
12impl<F> fmt::Debug for CloneBodyFn<F> {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 f.debug_struct("CloneBodyFn")
15 .field("f", &std::any::type_name::<F>())
16 .finish()
17 }
18}
19
20impl<F, B, E> Policy<B, E> for CloneBodyFn<F>
21where
22 F: Fn(&B) -> Option<B>,
23{
24 fn redirect(&mut self, _: &Attempt<'_>) -> Result<Action, E> {
25 Ok(Action::Follow)
26 }
27
28 fn clone_body(&self, body: &B) -> Option<B> {
29 (self.f)(body)
30 }
31}
32
33pub fn clone_body_fn<F, B>(f: F) -> CloneBodyFn<F>
38where
39 F: Fn(&B) -> Option<B>,
40{
41 CloneBodyFn { f }
42}