All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rust-server.server-service-header.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
fn method_not_allowed() -> Result, crate::ServiceError> {
    Ok(
        Response::builder().status(StatusCode::METHOD_NOT_ALLOWED)
            .body(Body::empty())
            .expect("Unable to create Method Not Allowed response")
    )
}

pub struct Service where
    T: Api + Clone + Send + 'static,
    C: Has {{#hasAuthMethods}}+ Has>{{/hasAuthMethods}} + Send + Sync + 'static
{
    api_impl: T,
{{#apiUsesMultipart}}
    multipart_form_size_limit: Option,
{{/apiUsesMultipart}}
    marker: PhantomData,
}

impl Service where
    T: Api + Clone + Send + 'static,
    C: Has {{#hasAuthMethods}}+ Has>{{/hasAuthMethods}} + Send + Sync + 'static
{
    pub fn new(api_impl: T) -> Self {
        Service {
            api_impl,
{{#apiUsesMultipart}}
            multipart_form_size_limit: Some(8 * 1024 * 1024),
{{/apiUsesMultipart}}
            marker: PhantomData
        }
    }
{{#apiUsesMultipart}}

    /// Configure size limit when extracting a multipart/form body.
    ///
    /// Default is 8 MiB.
    ///
    /// Set to None for no size limit, which presents a Denial of Service attack risk.
    pub fn multipart_form_size_limit(mut self, multipart_form_size_limit: Option) -> Self {
        self.multipart_form_size_limit = multipart_form_size_limit;
        self
    }
{{/apiUsesMultipart}}
}

impl Clone for Service where
    T: Api + Clone + Send + 'static,
    C: Has {{#hasAuthMethods}}+ Has>{{/hasAuthMethods}} + Send + Sync + 'static
{
    fn clone(&self) -> Self {
        Service {
            api_impl: self.api_impl.clone(),
{{#apiUsesMultipart}}
            multipart_form_size_limit: Some(8 * 1024 * 1024),
{{/apiUsesMultipart}}
            marker: self.marker,
        }
    }
}

impl hyper::service::Service<(Request, C)> for Service where
    T: Api + Clone + Send + Sync + 'static,
    C: Has {{#hasAuthMethods}}+ Has>{{/hasAuthMethods}} + Send + Sync + 'static
{
    type Response = Response;
    type Error = crate::ServiceError;
    type Future = ServiceFuture;

    fn poll_ready(&mut self, cx: &mut Context) -> Poll> {
        self.api_impl.poll_ready(cx)
    }

    fn call(&mut self, req: (Request, C)) -> Self::Future {
        async fn run(
            mut api_impl: T,
            req: (Request, C),
{{#apiUsesMultipartFormData}}
            multipart_form_size_limit: Option,
{{/apiUsesMultipartFormData}}
        ) -> Result, crate::ServiceError> where
            T: Api + Clone + Send + 'static,
            C: Has {{#hasAuthMethods}}+ Has>{{/hasAuthMethods}} + Send + Sync + 'static
        {
            let (request, context) = req;
            let (parts, body) = request.into_parts();
            let (method, uri, headers) = (parts.method, parts.uri, parts.headers);
            let path = paths::GLOBAL_REGEX_SET.matches(uri.path());

            {{!
            This match statement is duplicated below in `parse_operation_id()`.
            Please update both places if changing how this code is autogenerated.
            }}
            match method {




© 2015 - 2024 Weber Informatics LLC | Privacy Policy