use crate::headers::Headers;
use crate::method::Method;
use crate::url::Url;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Request {
method: Method,
url: Url,
headers: Headers,
body: Vec<u8>,
}
impl Request {
#[must_use]
pub fn new(method: Method, url: Url) -> Self {
Self {
method,
url,
headers: Headers::new(),
body: Vec::new(),
}
}
#[must_use]
pub fn method(&self) -> Method {
self.method
}
#[must_use]
pub fn url(&self) -> &Url {
&self.url
}
#[must_use]
pub fn headers(&self) -> &Headers {
&self.headers
}
#[must_use]
pub fn body(&self) -> &[u8] {
&self.body
}
#[must_use]
pub fn with_header(self, name: impl Into<String>, value: impl Into<String>) -> Self {
let headers = self.headers.with(name, value);
Self { headers, ..self }
}
#[must_use]
pub fn with_body(self, body: Vec<u8>) -> Self {
Self { body, ..self }
}
}