Skip to main content

flowparser_sflow/counter_records/
http_counters.rs

1use nom::IResult;
2use nom::number::complete::be_u32;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6pub struct HttpCounters {
7    pub method_option_count: u32,
8    pub method_get_count: u32,
9    pub method_head_count: u32,
10    pub method_post_count: u32,
11    pub method_put_count: u32,
12    pub method_delete_count: u32,
13    pub method_trace_count: u32,
14    pub method_connect_count: u32,
15    pub method_other_count: u32,
16    pub status_1xx_count: u32,
17    pub status_2xx_count: u32,
18    pub status_3xx_count: u32,
19    pub status_4xx_count: u32,
20    pub status_5xx_count: u32,
21    pub status_other_count: u32,
22}
23
24pub(crate) fn parse_http_counters(input: &[u8]) -> IResult<&[u8], HttpCounters> {
25    let (input, method_option_count) = be_u32(input)?;
26    let (input, method_get_count) = be_u32(input)?;
27    let (input, method_head_count) = be_u32(input)?;
28    let (input, method_post_count) = be_u32(input)?;
29    let (input, method_put_count) = be_u32(input)?;
30    let (input, method_delete_count) = be_u32(input)?;
31    let (input, method_trace_count) = be_u32(input)?;
32    let (input, method_connect_count) = be_u32(input)?;
33    let (input, method_other_count) = be_u32(input)?;
34    let (input, status_1xx_count) = be_u32(input)?;
35    let (input, status_2xx_count) = be_u32(input)?;
36    let (input, status_3xx_count) = be_u32(input)?;
37    let (input, status_4xx_count) = be_u32(input)?;
38    let (input, status_5xx_count) = be_u32(input)?;
39    let (input, status_other_count) = be_u32(input)?;
40
41    Ok((
42        input,
43        HttpCounters {
44            method_option_count,
45            method_get_count,
46            method_head_count,
47            method_post_count,
48            method_put_count,
49            method_delete_count,
50            method_trace_count,
51            method_connect_count,
52            method_other_count,
53            status_1xx_count,
54            status_2xx_count,
55            status_3xx_count,
56            status_4xx_count,
57            status_5xx_count,
58            status_other_count,
59        },
60    ))
61}