Skip to content

Commit

Permalink
Merge #386: Added tower-http compression as middleware on both HTTP r…
Browse files Browse the repository at this point in the history
…outers

22bb98a #326: Use only compression features of tower-http (Alex Wellnitz)
76b270b #326: Add tower-http compression as middleware (Alex Wellnitz)

Pull request description:

  Modified:
  I have added tower-http compression as middleware on both HTTP routers(API, Tracker HTTP).

  All tests were run and were okay.

ACKs for top commit:
  josecelano:
    ACK 22bb98a

Tree-SHA512: 0513f81731d8e0f57e3f26039f727dae01a41ecacd01cabd0b77ee5644e680302e59da762b932afda59ba6a4a7b40c31baf580082031e1a893f09128425055f3
  • Loading branch information
josecelano committed Aug 26, 2023
2 parents d36d655 + 22bb98a commit 8b48b0c
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 4 deletions.
120 changes: 120 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ uuid = { version = "1", features = ["v4"] }
axum = "0.6.20"
axum-server = { version = "0.5", features = ["tls-rustls"] }
axum-client-ip = "0.4.1"
tower-http = { version= "0.4.3", features = ["compression-full"] }
bencode = { version = "1.0.0-alpha.1", path = "contrib/bencode" }
torrust-tracker-primitives = { version = "3.0.0-alpha.3", path = "packages/primitives" }
torrust-tracker-configuration = { version = "3.0.0-alpha.3", path = "packages/configuration" }
Expand Down
11 changes: 7 additions & 4 deletions src/servers/apis/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use std::sync::Arc;

use axum::{middleware, Router};
use tower_http::compression::CompressionLayer;

use super::v1;
use crate::tracker::Tracker;
Expand All @@ -21,8 +22,10 @@ pub fn router(tracker: Arc<Tracker>) -> Router {

let router = v1::routes::add(prefix, router, tracker.clone());

router.layer(middleware::from_fn_with_state(
tracker.config.clone(),
v1::middlewares::auth::auth,
))
router
.layer(middleware::from_fn_with_state(
tracker.config.clone(),
v1::middlewares::auth::auth,
))
.layer(CompressionLayer::new())
}
2 changes: 2 additions & 0 deletions src/servers/http/v1/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::Arc;
use axum::routing::get;
use axum::Router;
use axum_client_ip::SecureClientIpSource;
use tower_http::compression::CompressionLayer;

use super::handlers::{announce, scrape};
use crate::tracker::Tracker;
Expand All @@ -23,4 +24,5 @@ pub fn router(tracker: Arc<Tracker>) -> Router {
.route("/scrape/:key", get(scrape::handle_with_key).with_state(tracker))
// Add extension to get the client IP from the connection info
.layer(SecureClientIpSource::ConnectInfo.into_extension())
.layer(CompressionLayer::new())
}

0 comments on commit 8b48b0c

Please sign in to comment.