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

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

There is a newer version: 7.9.0
Show newest version

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

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

    /// Configure size limit when inspecting 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
    }
{{/apiUsesMultipartFormData}}
}

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

    fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> {
        Poll::Ready(Ok(()))
    }

    fn call(&mut self, target: Target) -> Self::Future {
        let service = Service::new(self.api_impl.clone()){{^apiUsesMultipartFormData}};{{/apiUsesMultipartFormData}}
{{#apiUsesMultipartFormData}}
            .multipart_form_size_limit(self.multipart_form_size_limit);
{{/apiUsesMultipartFormData}}

        future::ok(service)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy