leptos_spin/
request_parts.rs

1use spin_sdk::http::{conversions::IntoHeaders, IncomingRequest, Method, Scheme};
2
3// Because IncomingRequest is not Clone, we provide this struct with the
4// easily cloneable parts.
5// TODO: Evaluate whether Body can go here(perhaps as Bytes) without breaking Streaming
6#[derive(Debug, Clone)]
7pub struct RequestParts {
8    method: Method,
9    scheme: Option<Scheme>,
10    headers: Vec<(String, Vec<u8>)>,
11}
12impl RequestParts {
13    pub fn new_from_req(req: &IncomingRequest) -> Self {
14        Self {
15            method: req.method(),
16            scheme: req.scheme(),
17            headers: req.headers().into_headers(),
18        }
19    }
20    /// Get the Headers for the Request
21    pub fn headers(&self) -> &Vec<(String, Vec<u8>)> {
22        &self.headers
23    }
24    /// Get the Method for the Request
25    pub fn method(&self) -> &Method {
26        &self.method
27    }
28    /// Get the Scheme for the Request
29    pub fn scheme(&self) -> &Option<Scheme> {
30        &self.scheme
31    }
32}