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 all 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
1 change: 1 addition & 0 deletions tower-http/CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Added

- Add `NormalizePath` middleware
- Add `ValidateRequest` middleware

## Changed

Expand Down
2 changes: 2 additions & 0 deletions tower-http/Cargo.toml
Expand Up @@ -76,6 +76,7 @@ full = [
"timeout",
"trace",
"util",
"validate-request",
]

add-extension = []
Expand All @@ -98,6 +99,7 @@ set-status = []
timeout = ["tokio/time"]
trace = ["tracing"]
util = ["tower"]
validate-request = ["mime"]

compression-br = ["async-compression/brotli", "tokio-util", "tokio"]
compression-deflate = ["async-compression/zlib", "tokio-util", "tokio"]
Expand Down
6 changes: 6 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,9 @@ mod builder;
#[doc(inline)]
pub use self::builder::ServiceBuilderExt;

#[cfg(feature = "validate-request")]
pub mod validate_request;

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