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

Add layer to validate requests #289

Merged
merged 10 commits into from Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions tower-http/Cargo.toml
Expand Up @@ -19,6 +19,7 @@ futures-core = "0.3"
futures-util = { version = "0.3.14", default_features = false, features = [] }
http = "0.2.2"
http-body = "0.4.5"
mime = { version = "0.3", default_features = false }
82marbag marked this conversation as resolved.
Show resolved Hide resolved
pin-project-lite = "0.2.7"
tower-layer = "0.3"
tower-service = "0.3"
Expand All @@ -28,7 +29,6 @@ async-compression = { version = "0.3", optional = true, features = ["tokio"] }
base64 = { version = "0.13", optional = true }
http-range-header = "0.3.0"
iri-string = { version = "0.4", optional = true }
mime = { version = "0.3", optional = true, default_features = false }
mime_guess = { version = "2", optional = true, default_features = false }
percent-encoding = { version = "2.1.0", optional = true }
tokio = { version = "1.6", optional = true, default_features = false }
Expand Down Expand Up @@ -83,7 +83,7 @@ auth = ["base64"]
catch-panic = ["tracing", "futures-util/std"]
cors = []
follow-redirect = ["iri-string", "tower/util"]
fs = ["tokio/fs", "tokio-util/io", "tokio/io-util", "mime_guess", "mime", "percent-encoding", "httpdate", "set-status", "futures-util/alloc"]
fs = ["tokio/fs", "tokio-util/io", "tokio/io-util", "mime_guess", "percent-encoding", "httpdate", "set-status", "futures-util/alloc"]
82marbag marked this conversation as resolved.
Show resolved Hide resolved
limit = []
map-request-body = []
map-response-body = []
Expand Down
5 changes: 5 additions & 0 deletions tower-http/src/lib.rs
Expand Up @@ -23,6 +23,7 @@
//! sensitive_headers::SetSensitiveRequestHeadersLayer,
//! set_header::SetResponseHeaderLayer,
//! trace::TraceLayer,
//! validate_request::ValidateRequestHeaderLayer,
//! };
//! use tower::{ServiceBuilder, service_fn, make::Shared};
//! use http::{Request, Response, header::{HeaderName, CONTENT_TYPE, AUTHORIZATION}};
Expand Down Expand Up @@ -71,6 +72,8 @@
//! .layer(SetResponseHeaderLayer::overriding(CONTENT_TYPE, content_length_from_response))
//! // Authorize requests using a token
//! .layer(RequireAuthorizationLayer::bearer("passwordlol"))
//! // Accept only application/json, application/* and */* in a request's ACCEPT header
//! .layer(ValidateRequestHeaderLayer::accept("application/json"))
//! // Wrap a `Service` in our middleware stack
//! .service_fn(handler);
//!
Expand Down Expand Up @@ -319,6 +322,8 @@ mod builder;
#[doc(inline)]
pub use self::builder::ServiceBuilderExt;

pub mod validate_request;

/// The latency unit used to report latencies by middleware.
#[non_exhaustive]
#[derive(Copy, Clone, Debug)]
Expand Down