warp
warp copied to clipboard
Docs for cors filters are misleading.
Description In the docs it states:
// If you want to allow any route
use warp::Filter;
let cors = warp::cors()
.allow_any_origin();
Trying this with a simple websocket server did not work at all. After some research I found that I had to allow methods as well. Coming from actix_web where there is something like Cors::permissive()
it was not an easy one to catch. I wish the docs were more like:
use warp::Filter;
let cors = warp::cors()
.allow_any_origin()
.allow_any_methods()
.allow_any_headers()
perhaps it could be useful for development to create a cors filter to allow anything or have methods allow_any_methods
and allow_any_headers
defined on the filter builder. In any case stating that the current example code allows any route will fool people into believing so.
I'd say that having a helper method in the builder (like allow_all
) would ease this a bit (one could also then go back and adjust things)
yeah we could add a permissive
method on the builder that would call:
.allow_any_origin()
.allow_any_methods()
.allow_any_headers()
Hey, I wonder if allow_credentials()
should also be part of this?
@phungleson allow_credentials and allow_any_origin cannot coexist tho unless allow_any_origin adds requested origin dynamically rather than using *