use super::IntoResponse;
use crate::{HeaderMap, header, mime, request::Parts};
pub mod host;
#[doc(inline)]
pub use host::Host;
pub mod authority;
#[doc(inline)]
pub use authority::Authority;
pub mod path;
#[doc(inline)]
pub use path::Path;
pub mod query;
#[doc(inline)]
pub use query::Query;
mod uri;
mod header_map;
mod method;
mod request;
mod state;
pub use state::State;
mod extensions;
pub mod typed_header;
#[doc(inline)]
pub use typed_header::TypedHeader;
pub mod body;
#[doc(inline)]
pub use body::{Body, Bytes, Csv, Form, Json, OctetStream, Text};
#[cfg(feature = "multipart")]
#[doc(inline)]
pub use body::multipart;
#[cfg(feature = "multipart")]
#[doc(inline)]
pub use body::multipart::Multipart;
pub mod datastar;
mod option;
#[doc(inline)]
pub use option::{OptionalFromPartsStateRefPair, OptionalFromRequest, OptionalFromRequestBody};
#[diagnostic::on_unimplemented(
note = "Function argument is not a valid web endpoint extractor. \nSee `https://ramaproxy.org/docs/rama/http/service/web/extract/index.html` for details"
)]
pub trait FromPartsStateRefPair<State>: Sized + Send + Sync + 'static {
type Rejection;
fn from_parts_state_ref_pair(
parts: &Parts,
state: &State,
) -> impl Future<Output = Result<Self, Self::Rejection>> + Send;
}
#[diagnostic::on_unimplemented(
note = "Owned request-parts extractors must be the final argument, or immediately precede a body extractor that implements `FromRequestBody`."
)]
pub trait FromOwnedRequestParts: Sized + Send + 'static {
type Rejection;
fn from_owned_request_parts(
parts: Parts,
) -> impl Future<Output = Result<Self, Self::Rejection>> + Send + 'static;
}
#[diagnostic::on_unimplemented(
note = "The final argument after an owned request-parts extractor must implement `FromRequestBody`."
)]
pub trait FromRequestBody: FromRequest {
fn from_request_body(
parts: &Parts,
body: crate::Body,
) -> impl Future<Output = Result<Self, Self::Rejection>> + Send + 'static;
}
#[diagnostic::on_unimplemented(
note = "Function argument is not a valid web endpoint extractor. \nSee `https://ramaproxy.org/docs/rama/http/service/web/extract/index.html` for details"
)]
pub trait FromRequest: Sized + Send + 'static {
type Rejection;
fn from_request(
req: crate::Request,
) -> impl Future<Output = Result<Self, Self::Rejection>> + Send;
}
impl<T> FromRequest for T
where
T: FromOwnedRequestParts,
{
type Rejection = T::Rejection;
async fn from_request(req: crate::Request) -> Result<Self, Self::Rejection> {
Self::from_owned_request_parts(req.into_parts().0).await
}
}
fn has_any_content_type(headers: &HeaderMap, expected_content_types: &[&mime::Mime]) -> bool {
let Some(content_type) = headers.get(header::CONTENT_TYPE) else {
return false;
};
let Ok(content_type) = content_type.to_str() else {
return false;
};
expected_content_types
.iter()
.any(|ct| content_type.starts_with(ct.as_ref()))
}