worker_route/http/
request.rsuse super::HttpHeaders;
use worker::{Method, Request, Url};
#[allow(clippy::module_name_repetitions)]
#[derive(Debug)]
pub struct HttpRequest {
headers: HttpHeaders,
method: Method,
path: String,
url: Option<Url>,
}
impl HttpRequest {
pub fn headers(&self) -> &HttpHeaders {
&self.headers
}
pub fn method(&self) -> &Method {
&self.method
}
pub fn path(&self) -> &str {
&self.path
}
pub fn url(&self) -> Option<&Url> {
self.url.as_ref()
}
#[cfg_attr(docsrs, doc(cfg(feature = "cookies")))]
#[cfg(feature = "cookies")]
pub fn cookies(&self) -> impl Iterator<Item = cookie::Cookie<'_>> {
use crate::http::cookies::CookieHelper;
CookieHelper::Get.get(&self.headers)
}
}
impl From<&Request> for HttpRequest {
fn from(req: &Request) -> Self {
Self {
headers: req.headers().into(),
method: req.method(),
path: req.path(),
url: req.url().ok(),
}
}
}