1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
pub use http::request::{Builder as RequestBuilder, Parts as RequestHead};

use super::BorrowHeaderMap;
use crate::{
    common::{FromParts, IntoParts},
    h1::payload::Payload,
};

pub type Request<P = Payload> = http::request::Request<P>;

impl<P> FromParts<RequestHead, P> for Request<P> {
    fn from_parts(parts: RequestHead, body: P) -> Self {
        Self::from_parts(parts, body)
    }
}

impl<P> IntoParts for Request<P> {
    type Parts = RequestHead;
    type Body = P;
    fn into_parts(self) -> (Self::Parts, Self::Body) {
        self.into_parts()
    }
}

pub struct RequestForEncoder<'a, P = Payload> {
    parts: &'a mut RequestHead,
    body: P,
}

impl<'a, P> FromParts<&'a mut RequestHead, P> for RequestForEncoder<'a, P> {
    fn from_parts(parts: &'a mut RequestHead, body: P) -> Self {
        Self { parts, body }
    }
}

impl<'a, P> IntoParts for RequestForEncoder<'a, P> {
    type Parts = &'a mut RequestHead;
    type Body = P;
    fn into_parts(self) -> (Self::Parts, Self::Body) {
        (self.parts, self.body)
    }
}

impl BorrowHeaderMap for RequestHead {
    fn header_map(&self) -> &http::HeaderMap {
        &self.headers
    }

    fn header_map_mut(&mut self) -> &mut http::HeaderMap {
        &mut self.headers
    }
}

impl BorrowHeaderMap for &mut RequestHead {
    fn header_map(&self) -> &http::HeaderMap {
        &self.headers
    }

    fn header_map_mut(&mut self) -> &mut http::HeaderMap {
        &mut self.headers
    }
}