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
use bytes::Bytes;
use solicit::header::*;
use bytesx::*;
use http_common::*;
pub struct SimpleHttpMessage {
pub headers: Headers,
pub body: Bytes,
}
impl Default for SimpleHttpMessage {
fn default() -> Self {
SimpleHttpMessage {
headers: Default::default(),
body: Bytes::new(),
}
}
}
impl SimpleHttpMessage {
pub fn from_parts<I>(iter: I) -> SimpleHttpMessage
where I : IntoIterator<Item= HttpStreamPart>
{
SimpleHttpMessage::from_part_content(iter.into_iter().map(|c| c.content))
}
pub fn from_part_content<I>(iter: I) -> SimpleHttpMessage
where I : IntoIterator<Item=HttpStreamPartContent>
{
let mut r: SimpleHttpMessage = Default::default();
for c in iter {
r.add(c);
}
r
}
pub fn add(&mut self, part: HttpStreamPartContent) {
match part {
HttpStreamPartContent::Headers(headers) => {
self.headers.extend(headers);
}
HttpStreamPartContent::Data(data) => {
bytes_extend_with(&mut self.body, data);
}
}
}
}