use normalize path layer to trim trailing slash
This commit is contained in:
parent
03bfd7148f
commit
0b1cfeffed
@ -93,7 +93,7 @@ tokio-console = { version = "0.1.9", optional = true }
|
|||||||
tokio-stream = { version = "0.1.14", features = ["sync"] }
|
tokio-stream = { version = "0.1.14", features = ["sync"] }
|
||||||
toml = "0.7.6"
|
toml = "0.7.6"
|
||||||
tower = { version = "0.4.13", features = ["timeout", "tracing"] }
|
tower = { version = "0.4.13", features = ["timeout", "tracing"] }
|
||||||
tower-http = { version = "0.4.3", features = ["cors", "sensitive-headers", "trace"] }
|
tower-http = { version = "0.4.3", features = ["cors", "normalize-path", "sensitive-headers", "trace"] }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
ulid = { version = "1.0.0", features = ["rand", "uuid", "serde"] }
|
ulid = { version = "1.0.0", features = ["rand", "uuid", "serde"] }
|
||||||
|
@ -29,7 +29,7 @@ use tokio::sync::broadcast;
|
|||||||
use tower::timeout::TimeoutLayer;
|
use tower::timeout::TimeoutLayer;
|
||||||
use tower::ServiceBuilder;
|
use tower::ServiceBuilder;
|
||||||
use tower_http::sensitive_headers::SetSensitiveRequestHeadersLayer;
|
use tower_http::sensitive_headers::SetSensitiveRequestHeadersLayer;
|
||||||
use tower_http::{cors::CorsLayer, trace::TraceLayer};
|
use tower_http::{cors::CorsLayer, normalize_path::NormalizePathLayer, trace::TraceLayer};
|
||||||
use tracing::{error_span, info};
|
use tracing::{error_span, info};
|
||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
|
|
||||||
@ -76,64 +76,35 @@ pub async fn serve(
|
|||||||
post(rpc_proxy_http::proxy_web3_rpc).get(rpc_proxy_ws::websocket_handler),
|
post(rpc_proxy_http::proxy_web3_rpc).get(rpc_proxy_ws::websocket_handler),
|
||||||
)
|
)
|
||||||
// authenticated with and without trailing slash
|
// authenticated with and without trailing slash
|
||||||
.route(
|
|
||||||
"/rpc/:rpc_key/",
|
|
||||||
post(rpc_proxy_http::proxy_web3_rpc_with_key)
|
|
||||||
.get(rpc_proxy_ws::websocket_handler_with_key),
|
|
||||||
)
|
|
||||||
.route(
|
.route(
|
||||||
"/rpc/:rpc_key",
|
"/rpc/:rpc_key",
|
||||||
post(rpc_proxy_http::proxy_web3_rpc_with_key)
|
post(rpc_proxy_http::proxy_web3_rpc_with_key)
|
||||||
.get(rpc_proxy_ws::websocket_handler_with_key),
|
.get(rpc_proxy_ws::websocket_handler_with_key),
|
||||||
)
|
)
|
||||||
// authenticated debug route with and without trailing slash
|
// authenticated debug route
|
||||||
.route(
|
|
||||||
"/debug/:rpc_key/",
|
|
||||||
post(rpc_proxy_http::debug_proxy_web3_rpc_with_key)
|
|
||||||
.get(rpc_proxy_ws::debug_websocket_handler_with_key),
|
|
||||||
)
|
|
||||||
.route(
|
.route(
|
||||||
"/debug/:rpc_key",
|
"/debug/:rpc_key",
|
||||||
post(rpc_proxy_http::debug_proxy_web3_rpc_with_key)
|
post(rpc_proxy_http::debug_proxy_web3_rpc_with_key)
|
||||||
.get(rpc_proxy_ws::debug_websocket_handler_with_key),
|
.get(rpc_proxy_ws::debug_websocket_handler_with_key),
|
||||||
)
|
)
|
||||||
// public fastest with and without trailing slash
|
// public fastest
|
||||||
.route(
|
|
||||||
"/fastest/",
|
|
||||||
post(rpc_proxy_http::fastest_proxy_web3_rpc)
|
|
||||||
.get(rpc_proxy_ws::fastest_websocket_handler),
|
|
||||||
)
|
|
||||||
.route(
|
.route(
|
||||||
"/fastest",
|
"/fastest",
|
||||||
post(rpc_proxy_http::fastest_proxy_web3_rpc)
|
post(rpc_proxy_http::fastest_proxy_web3_rpc)
|
||||||
.get(rpc_proxy_ws::fastest_websocket_handler),
|
.get(rpc_proxy_ws::fastest_websocket_handler),
|
||||||
)
|
)
|
||||||
// authenticated fastest with and without trailing slash
|
// authenticated fastest with and without trailing slash
|
||||||
.route(
|
|
||||||
"/fastest/:rpc_key/",
|
|
||||||
post(rpc_proxy_http::fastest_proxy_web3_rpc_with_key)
|
|
||||||
.get(rpc_proxy_ws::fastest_websocket_handler_with_key),
|
|
||||||
)
|
|
||||||
.route(
|
.route(
|
||||||
"/fastest/:rpc_key",
|
"/fastest/:rpc_key",
|
||||||
post(rpc_proxy_http::fastest_proxy_web3_rpc_with_key)
|
post(rpc_proxy_http::fastest_proxy_web3_rpc_with_key)
|
||||||
.get(rpc_proxy_ws::fastest_websocket_handler_with_key),
|
.get(rpc_proxy_ws::fastest_websocket_handler_with_key),
|
||||||
)
|
)
|
||||||
// public versus
|
// public versus
|
||||||
.route(
|
|
||||||
"/versus/",
|
|
||||||
post(rpc_proxy_http::versus_proxy_web3_rpc).get(rpc_proxy_ws::versus_websocket_handler),
|
|
||||||
)
|
|
||||||
.route(
|
.route(
|
||||||
"/versus",
|
"/versus",
|
||||||
post(rpc_proxy_http::versus_proxy_web3_rpc).get(rpc_proxy_ws::versus_websocket_handler),
|
post(rpc_proxy_http::versus_proxy_web3_rpc).get(rpc_proxy_ws::versus_websocket_handler),
|
||||||
)
|
)
|
||||||
// authenticated versus with and without trailing slash
|
// authenticated versus
|
||||||
.route(
|
|
||||||
"/versus/:rpc_key/",
|
|
||||||
post(rpc_proxy_http::versus_proxy_web3_rpc_with_key)
|
|
||||||
.get(rpc_proxy_ws::versus_websocket_handler_with_key),
|
|
||||||
)
|
|
||||||
.route(
|
.route(
|
||||||
"/versus/:rpc_key",
|
"/versus/:rpc_key",
|
||||||
post(rpc_proxy_http::versus_proxy_web3_rpc_with_key)
|
post(rpc_proxy_http::versus_proxy_web3_rpc_with_key)
|
||||||
@ -256,6 +227,8 @@ pub async fn serve(
|
|||||||
// layers are ordered bottom up
|
// layers are ordered bottom up
|
||||||
// the last layer is first for requests and last for responses
|
// the last layer is first for requests and last for responses
|
||||||
//
|
//
|
||||||
|
// Remove trailing slashes
|
||||||
|
.layer(NormalizePathLayer::trim_trailing_slash())
|
||||||
// Mark the `Authorization` request header as sensitive so it doesn't show in logs
|
// Mark the `Authorization` request header as sensitive so it doesn't show in logs
|
||||||
.layer(SetSensitiveRequestHeadersLayer::new(once(AUTHORIZATION)))
|
.layer(SetSensitiveRequestHeadersLayer::new(once(AUTHORIZATION)))
|
||||||
// handle cors
|
// handle cors
|
||||||
|
Loading…
Reference in New Issue
Block a user