{"record":{"id":"39391e06fe537db4","repo":"seanmonstar/warp","slug":"method-not-allowed","errorCode":null,"errorMessage":"method_not_allowed","messagePattern":"method_not_allowed","errorType":"http","errorClass":null,"httpStatus":405,"severity":"error","filePath":"src/filters/method.rs","lineNumber":138,"sourceCode":"/// ```\npub fn method() -> impl Filter<Extract = One<Method>, Error = Infallible> + Copy {\n    filter_fn_one(|route| future::ok::<_, Infallible>(route.method().clone()))\n}\n\n// NOTE: This takes a static function instead of `&'static Method` directly\n// so that the `impl Filter` can be zero-sized. Moving it around should be\n// cheaper than holding a single static pointer (which would make it 1 word).\nfn method_is<F>(func: F) -> impl Filter<Extract = (), Error = Rejection> + Copy\nwhere\n    F: Fn() -> &'static Method + Copy,\n{\n    filter_fn(move |route| {\n        let method = func();\n        tracing::trace!(\"method::{:?}?: {:?}\", method, route.method());\n        if route.method() == method {\n            future::ok(())\n        } else {\n            future::err(crate::reject::method_not_allowed())\n        }\n    })\n}\n\n#[cfg(test)]\nmod tests {\n    #[test]\n    fn method_size_of() {\n        // See comment on `method_is` function.\n        assert_eq!(std::mem::size_of_val(&super::get()), 0,);\n    }\n}\n","sourceCodeStart":120,"sourceCodeEnd":151,"githubUrl":"https://github.com/seanmonstar/warp/blob/ff34d7213ed55ec342304aa7ff6ac4b351da9e66/src/filters/method.rs#L120-L151","documentation":"This is warp's rejection produced when a route matched by path does not accept the HTTP method of the incoming request. The method filter (src/filters/method.rs:138) compares the request's method against the method bound via get()/post()/put()/delete()/head()/options() and rejects with method_not_allowed when they differ. It is the framework's way of signalling HTTP 405 Method Not Allowed.","triggerScenarios":"A request whose path matches a filter chain but whose HTTP method was bound to a different method — e.g. calling warp::post() on a route the client hits with GET, or chaining warp::get() and warp::post() on separate routes where the client uses PATCH/PUT which was never registered.","commonSituations":"Clients using the wrong verb against a REST endpoint; forgetting to add warp::put() or warp::patch() for an endpoint; a frontend sending GET with a body where the server expects POST; CORS preflight OPTIONS requests not handled because warp::options() wasn't composed; proxy or client library defaulting to GET.","solutions":["Check the client's HTTP method matches the method filter bound in the route (warp::get(), warp::post(), etc.) and fix the client or add the missing method filter","Compose the route with additional method filters if the endpoint should accept multiple methods (warp::get().or(warp::post()))","Verify any reverse proxy/load balancer isn't rewriting the method","Handle the rejection explicitly with .recover() to return a proper 405 with an Allow header"],"exampleFix":"// before\nlet routes = warp::post().and(warp::path(\"items\")).map(create_item);\n// client calls GET /items -> method_not_allowed\n\n// after\nlet routes = warp::get()\n    .and(warp::path(\"items\"))\n    .map(list_items)\n    .or(warp::post().and(warp::path(\"items\")).map(create_item));","handlingStrategy":"try-catch","validationCode":"// client-side: ensure the verb matches the endpoint's contract\nconst ALLOWED = ['GET','POST','PUT','DELETE'];\nif (!ALLOWED.includes(request.method)) throw new Error(`use one of ${ALLOWED} for ${url}`);","typeGuard":"fn is_supported_method(m: &Method) -> bool {\n    matches!(m, &Method::GET | &Method::POST | &Method::PUT | &Method::DELETE | &Method::HEAD | &Method::OPTIONS)\n}","tryCatchPattern":"let resp = routes.recover(|rej: warp::Rejection| async move {\n    if rej.is_not_found() || rej.find::<crate::reject::MethodNotAllowed>().is_some() {\n        Ok(warp::reply::with_status(warp::reply(), warp::http::StatusCode::METHOD_NOT_ALLOWED))\n    } else { Err(rej) }\n});","preventionTips":["Bind every intended HTTP method in the route with .or() composition","Document each endpoint's allowed verbs and generate clients from them (OpenAPI)","Test each endpoint with all verbs to catch 405s early","Check proxy configs for method rewriting"],"tags":["http","routing","method-not-allowed","warp"],"backgroundTag":"http-error-response","analyzedSha":"ff34d7213ed55ec342304aa7ff6ac4b351da9e66","analyzedAt":"2026-09-09T16:57:46.316Z","contentChangedAt":"2026-09-09T16:57:46.316Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}