Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for HTTP extension methods #871

Closed
outergod opened this issue Jun 26, 2021 · 1 comment · Fixed by #877
Closed

Support for HTTP extension methods #871

outergod opened this issue Jun 26, 2021 · 1 comment · Fixed by #877
Labels
feature New feature or request

Comments

@outergod
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I'm trying to implement WebDAV handlers using warp, which requires filters for non-standard HTTP methods, as documented in RFC 4918. While http::Method allows defining custom methods, warp only provides a pre-defined set of filters for the standard methods and keeps method_is in filters::method private, so I couldn't figure out any other way to filter for custom methods.

Describe the solution you'd like
Making method_is public would probably be enough already. warp could provide some sugar for Method::from_bytes, but that is not absolutely necessary.

Describe alternatives you've considered
I could't figure out any other way to filter for the method in warp.

Additional context
N/A

@outergod outergod added the feature New feature or request label Jun 26, 2021
@outergod
Copy link
Contributor Author

Update, I was now able to write my own filter but it's not particularly pretty vs. what could be achieved if warp supported it directly.

fn method(name: &str) -> impl Filter<Extract = (), Error = Rejection> + Clone {
    let method =
        Method::from_str(name).expect(&format!("Method name {} could not be converted", name));

    warp::method()
        .and_then(move |m: Method| {
            let method = method.clone();
            async move {
                if m == method {
                    Ok(())
                } else {
                    Err(reject::custom(GatewayHandlerError::MethodNotAllowed))
                }
            }
        })
        .untuple_one()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
1 participant