Skip to main content

g_server/http/
request.rs

1use super::{body::Body, header::Header, method::Method, uri::Uri};
2
3/// An HTTP request.
4#[derive(Debug)]
5pub struct Request {
6    method: Method,
7    uri: Uri,
8    headers: Header,
9    body: Body,
10}
11
12impl Request {
13    pub fn new(
14        method: impl Into<Method>,
15        uri: impl Into<Uri>,
16        headers: Header,
17        body: impl Into<Body>,
18    ) -> Self {
19        Self {
20            method: method.into(),
21            uri: uri.into(),
22            headers,
23            body: body.into(),
24        }
25    }
26
27    pub fn method(&self) -> &Method {
28        &self.method
29    }
30
31    pub fn uri(&self) -> &Uri {
32        &self.uri
33    }
34
35    pub fn headers(&self) -> &Header {
36        &self.headers
37    }
38
39    pub fn body(&self) -> &Body {
40        &self.body
41    }
42
43    pub fn method_mut(&mut self) -> &mut Method {
44        &mut self.method
45    }
46
47    pub fn uri_mut(&mut self) -> &mut Uri {
48        &mut self.uri
49    }
50
51    pub fn headers_mut(&mut self) -> &mut Header {
52        &mut self.headers
53    }
54
55    pub fn body_mut(&mut self) -> &mut Body {
56        &mut self.body
57    }
58
59    pub fn into_body(self) -> Body {
60        self.body
61    }
62
63    pub fn into_parts(self) -> (Method, Uri, Header, Body) {
64        (self.method, self.uri, self.headers, self.body)
65    }
66}