partial tower/tower-http sentry and gzip/brotli compression

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-03-29 23:16:55 -04:00 committed by June
parent 3103ad2205
commit b437e47d8c
3 changed files with 53 additions and 6 deletions

41
Cargo.lock generated
View File

@ -38,6 +38,21 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "alloc-no-stdlib"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3"
[[package]]
name = "alloc-stdlib"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece"
dependencies = [
"alloc-no-stdlib",
]
[[package]] [[package]]
name = "allocator-api2" name = "allocator-api2"
version = "0.2.16" version = "0.2.16"
@ -86,6 +101,8 @@ version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a116f46a969224200a0a97f29cfd4c50e7534e4b4826bd23ea2c3c533039c82c" checksum = "a116f46a969224200a0a97f29cfd4c50e7534e4b4826bd23ea2c3c533039c82c"
dependencies = [ dependencies = [
"brotli",
"flate2",
"futures-core", "futures-core",
"memchr", "memchr",
"pin-project-lite", "pin-project-lite",
@ -289,6 +306,27 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "brotli"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "516074a47ef4bce09577a3b379392300159ce5b1ba2e501ff1c819950066100f"
dependencies = [
"alloc-no-stdlib",
"alloc-stdlib",
"brotli-decompressor",
]
[[package]]
name = "brotli-decompressor"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e2e4afe60d7dd600fdd3de8d0f08c2b7ec039712e3b6137ff98b7004e82de4f"
dependencies = [
"alloc-no-stdlib",
"alloc-stdlib",
]
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.15.4" version = "3.15.4"
@ -462,6 +500,7 @@ dependencies = [
"rust-rocksdb", "rust-rocksdb",
"sd-notify", "sd-notify",
"sentry", "sentry",
"sentry-tower",
"sentry-tracing", "sentry-tracing",
"serde", "serde",
"serde_html_form", "serde_html_form",
@ -2137,6 +2176,7 @@ version = "0.11.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62"
dependencies = [ dependencies = [
"async-compression",
"base64 0.21.7", "base64 0.21.7",
"bytes", "bytes",
"encoding_rs", "encoding_rs",
@ -2166,6 +2206,7 @@ dependencies = [
"tokio", "tokio",
"tokio-rustls", "tokio-rustls",
"tokio-socks", "tokio-socks",
"tokio-util",
"tower-service", "tower-service",
"url", "url",
"wasm-bindgen", "wasm-bindgen",

View File

@ -135,12 +135,10 @@ features = ["jpeg", "png", "gif", "webp"]
version = "0.4.21" version = "0.4.21"
default-features = false default-features = false
features = ["max_level_trace", "release_max_level_info"] features = ["max_level_trace", "release_max_level_info"]
[dependencies.tracing] [dependencies.tracing]
version = "0.1.40" version = "0.1.40"
default-features = false default-features = false
features = ["max_level_trace", "release_max_level_info"] features = ["max_level_trace", "release_max_level_info"]
[dependencies.tracing-subscriber] [dependencies.tracing-subscriber]
version = "0.3.18" version = "0.3.18"
features = ["env-filter"] features = ["env-filter"]
@ -178,6 +176,9 @@ features = ["backtrace", "contexts", "debug-images", "panic", "rustls", "tower",
[dependencies.sentry-tracing] [dependencies.sentry-tracing]
version = "0.32.2" version = "0.32.2"
optional = true optional = true
[dependencies.sentry-tower]
version = "0.32.2"
optional = true
# optional jemalloc usage # optional jemalloc usage
[dependencies.tikv-jemallocator] [dependencies.tikv-jemallocator]
@ -300,11 +301,11 @@ rocksdb = ["rust-rocksdb", "num_cpus"]
jemalloc = ["tikv-jemalloc-ctl", "tikv-jemallocator"] jemalloc = ["tikv-jemalloc-ctl", "tikv-jemallocator"]
sqlite = ["rusqlite", "parking_lot", "thread_local", "num_cpus"] sqlite = ["rusqlite", "parking_lot", "thread_local", "num_cpus"]
systemd = ["sd-notify"] systemd = ["sd-notify"]
sentry_telemetry = ["sentry", "sentry-tracing"] sentry_telemetry = ["sentry", "sentry-tracing", "sentry-tower"]
#gzip_compression = ["tower-http/compression-gzip"] gzip_compression = ["tower-http/compression-gzip", "reqwest/gzip"]
zstd_compression = ["tower-http/compression-zstd"] zstd_compression = ["tower-http/compression-zstd"]
#brotli_compression = ["tower-http/compression-br"] brotli_compression = ["tower-http/compression-br", "reqwest/brotli"]
#all_compression = ["tower-http/compression-full"] # all compression algos #all_compression = ["tower-http/compression-full"] # all compression algos
sha256_media = ["sha2"] sha256_media = ["sha2"]

View File

@ -243,7 +243,12 @@ async fn run_server() -> io::Result<()> {
let x_requested_with = HeaderName::from_static("x-requested-with"); let x_requested_with = HeaderName::from_static("x-requested-with");
let x_forwarded_for = HeaderName::from_static("x-forwarded-for"); let x_forwarded_for = HeaderName::from_static("x-forwarded-for");
let middlewares = ServiceBuilder::new() let base_middlewares = ServiceBuilder::new();
#[cfg(feature = "sentry_telemetry")]
let base_middlewares = base_middlewares.layer(sentry_tower::NewSentryLayer::<http::Request<_>>::new_from_top());
let middlewares = base_middlewares
.sensitive_headers([header::AUTHORIZATION]) .sensitive_headers([header::AUTHORIZATION])
.sensitive_request_headers([x_forwarded_for].into()) .sensitive_request_headers([x_forwarded_for].into())
.layer(axum::middleware::from_fn(spawn_task)) .layer(axum::middleware::from_fn(spawn_task))