Struct webparse::http::http2::Decoder

source ·
pub struct Decoder {
    pub index: Arc<RwLock<HeaderIndex>>,
}

Fields§

§index: Arc<RwLock<HeaderIndex>>

Implementations§

source§

impl Decoder

source

pub fn new() -> Decoder

Examples found in repository?
examples/demo.rs (line 82)
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
fn debug_request_parse_http2() {
    let mut decode = Decoder::new();
    let _http2 = vec![
        0x82, 0x86, 0x84, 0x41, 0x8c, 0xf1, 0xe3, 0xc2, 0xe5, 0xf2, 0x3a, 0x6b, 0xa0, 0xab, 0x90,
        0xf4, 0xff,
    ];
    let http2 = hexstr_to_vec("8286 8441 0f77 7777 2e65 7861 6d70 6c65 2e63 6f6d ");

    let mut buf = BinaryMut::from(http2);

    let _result = decode.decode_with_cb(&mut buf, |n, v| {
        println!("n = {:?}, v = {:?}", n, v);
    });
    // println!("result = {:?}", result);
    // let http2 = vec![
    //     0x82, 0x86, 0x84, 0xbe, 0x58, 0x08, 0x6e, 0x6f, 0x2d, 0x63, 0x61, 0x63, 0x68, 0x65,
    // ];
    // let http2 = hexstr_to_vec("8286 84be 5808 6e6f 2d63 6163 6865");

    // let mut buf = BinaryMut::from(http2);
    // let result = decode.decode_with_cb(&mut buf, |n, v| {
    //     println!("n = {:?}, v = {:?}", n, v);
    // });
    // println!("result = {:?}", result);

    // {
    //     //         8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925 | ....@.%.I.[.}..%
    //     //          a849 e95b b8e8 b4bf
    //     let http2 = vec![
    //         0x82, 0x87, 0x85, 0xbf, 0x40, 0x88, 0x25, 0xa8, 0x49, 0xe9, 0x5b, 0xa9, 0x7d, 0x7f,
    //         0x89, 0x25, 0xa8, 0x49, 0xe9, 0x5b, 0xb8, 0xe8, 0xb4, 0xbf,
    //     ];
    //     let http2 = hexstr_to_vec(
    //         "8287 85bf 400a 6375 7374 6f6d 2d6b 6579 0c63 7573 746f 6d2d 7661 6c75 65",
    //     );

    //     let mut buf = BinaryMut::from(http2);

    //     let result = decode.decode_with_cb(&mut buf, |n, v| {
    //         println!("n = {:?}, v = {:?}", n, v);
    //     });
    //     println!("result = {:?}", result);
    // }
}
More examples
Hide additional examples
examples/http2.rs (line 5)
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
fn parse_header() {
    let mut decoder = Decoder::new();
    // C.4.1
    let buf = Helper::hex_to_vec("8286 8441 8cf1 e3c2 e5f2 3a6b a0ab 90f4 ff");
    let buf_len = buf.len();
    let mut header = Headers::empty();
    let size = header.parse(BinaryMut::from(buf), &mut decoder, DEFAULT_SETTINGS_HEADER_TABLE_SIZE).unwrap();
    assert!(size == buf_len);
    assert!(header.method() == &Some(Method::Get));
    assert!(header.path() == &Some("/".to_string()));
    assert!(header.scheme() == &Some(Scheme::Http));
    assert!(header.authority() == &Some("www.example.com".to_string()));

    // C.4.2
    let buf = Helper::hex_to_vec("8286 84be 5886 a8eb 1064 9cbf");
    let buf_len = buf.len();
    let mut header = Headers::empty();
    let size = header.parse(BinaryMut::from(buf), &mut decoder, DEFAULT_SETTINGS_HEADER_TABLE_SIZE).unwrap();
    assert!(size == buf_len);
    assert!(header.method() == &Some(Method::Get));
    assert!(header.path() == &Some("/".to_string()));
    assert!(header.scheme() == &Some(Scheme::Http));
    assert!(header.authority() == &Some("www.example.com".to_string()));
    assert!(header.fields()["cache-control"] == "no-cache");

    // C.4.3
    let buf = Helper::hex_to_vec("8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925 a849 e95b b8e8 b4bf ");
    let buf_len = buf.len();
    let mut header = Headers::empty();
    let size = header.parse(BinaryMut::from(buf), &mut decoder, DEFAULT_SETTINGS_HEADER_TABLE_SIZE).unwrap();
    assert!(size == buf_len);
    assert!(header.method() == &Some(Method::Get));
    assert!(header.path() == &Some("/index.html".to_string()));
    assert!(header.scheme() == &Some(Scheme::Https));
    assert!(header.authority() == &Some("www.example.com".to_string()));
    assert!(header.fields()["custom-key"] == "custom-value");
}
source

pub fn new_index(index: Arc<RwLock<HeaderIndex>>) -> Decoder

source

pub fn decode<B: Buf>( &mut self, buf: &mut B ) -> WebResult<Vec<(HeaderName, HeaderValue)>>

source

pub fn decode_with_cb<F, B: Buf>(&mut self, buf: &mut B, cb: F) -> WebResult<()>
where F: FnMut(Cow<'_, HeaderName>, Cow<'_, HeaderValue>),

Examples found in repository?
examples/demo.rs (lines 91-93)
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
fn debug_request_parse_http2() {
    let mut decode = Decoder::new();
    let _http2 = vec![
        0x82, 0x86, 0x84, 0x41, 0x8c, 0xf1, 0xe3, 0xc2, 0xe5, 0xf2, 0x3a, 0x6b, 0xa0, 0xab, 0x90,
        0xf4, 0xff,
    ];
    let http2 = hexstr_to_vec("8286 8441 0f77 7777 2e65 7861 6d70 6c65 2e63 6f6d ");

    let mut buf = BinaryMut::from(http2);

    let _result = decode.decode_with_cb(&mut buf, |n, v| {
        println!("n = {:?}, v = {:?}", n, v);
    });
    // println!("result = {:?}", result);
    // let http2 = vec![
    //     0x82, 0x86, 0x84, 0xbe, 0x58, 0x08, 0x6e, 0x6f, 0x2d, 0x63, 0x61, 0x63, 0x68, 0x65,
    // ];
    // let http2 = hexstr_to_vec("8286 84be 5808 6e6f 2d63 6163 6865");

    // let mut buf = BinaryMut::from(http2);
    // let result = decode.decode_with_cb(&mut buf, |n, v| {
    //     println!("n = {:?}, v = {:?}", n, v);
    // });
    // println!("result = {:?}", result);

    // {
    //     //         8287 85bf 4088 25a8 49e9 5ba9 7d7f 8925 | ....@.%.I.[.}..%
    //     //          a849 e95b b8e8 b4bf
    //     let http2 = vec![
    //         0x82, 0x87, 0x85, 0xbf, 0x40, 0x88, 0x25, 0xa8, 0x49, 0xe9, 0x5b, 0xa9, 0x7d, 0x7f,
    //         0x89, 0x25, 0xa8, 0x49, 0xe9, 0x5b, 0xb8, 0xe8, 0xb4, 0xbf,
    //     ];
    //     let http2 = hexstr_to_vec(
    //         "8287 85bf 400a 6375 7374 6f6d 2d6b 6579 0c63 7573 746f 6d2d 7661 6c75 65",
    //     );

    //     let mut buf = BinaryMut::from(http2);

    //     let result = decode.decode_with_cb(&mut buf, |n, v| {
    //         println!("n = {:?}, v = {:?}", n, v);
    //     });
    //     println!("result = {:?}", result);
    // }
}

Trait Implementations§

source§

impl Debug for Decoder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.