Skip to content

Commit

Permalink
http compression
Browse files Browse the repository at this point in the history
  • Loading branch information
cbackas committed Feb 11, 2024
1 parent cb4a013 commit 219a25a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
33 changes: 33 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sha2 = "0.10.7"
tokio = { version = "1.31.0", features = ["full"] }
tokio-tungstenite = { version = "0.20.1", features = ["native-tls"] }
tower = "0.4.13"
tower-http = { version = "0.4.3", features = ["fs"] }
tower-http = { version = "0.4.3", features = ["fs", "compression-gzip"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
url = "2.4.0"
Expand Down
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use axum::{
use lazy_static::lazy_static;
use strava_api_service::StravaAPIService;
use tokio::{sync::Mutex, time::Instant};
use tower_http::compression::{
predicate::{DefaultPredicate, NotForContentType, Predicate},
CompressionLayer,
};
use tower_http::{
services::{ServeDir, ServeFile},
trace::TraceLayer,
Expand Down Expand Up @@ -70,11 +74,15 @@ async fn main() -> anyhow::Result<()> {

info!("Starting server at host: {}", host_uri);

let predicate = DefaultPredicate::new().and(NotForContentType::new("application/json"));
let compression_layer = CompressionLayer::new().gzip(true).compress_when(predicate);

axum::Server::bind(&addr)
.serve(
get_main_router()
.with_state(SharedAppState::default())
.layer(TraceLayer::new_for_http())
.layer(compression_layer)
.into_make_service(),
)
.await
Expand Down

0 comments on commit 219a25a

Please sign in to comment.