tower-http

A collection of Tower middleware and utilities for building HTTP clients and servers in Rust

Library
Cargo
v0.7.0
903stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
87/100Excellent
Development Activity92
Maintenance84
Community84
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture83
Code Quality85
Innovation78
Learning Curve76

tower-http provides a large collection of ready-made Service/Layer middleware built on the tower ecosystem, covering the HTTP cross-cutting concerns almost every server or client needs: compression and decompression, CORS, request tracing, timeouts, authentication, sensitive-header redaction, request ID propagation, path normalization, and more. Because everything implements Tower’s standard Service/Layer traits, these middlewares compose with any Tower-compatible framework or client — most commonly axum and hyper — via tower::ServiceBuilder.

Rather than each framework reimplementing compression or CORS handling itself, tower-http centralizes these concerns as reusable, independently-versioned building blocks that any Tower-based HTTP stack can opt into per-feature via Cargo feature flags.

What You Get

  • Compression/decompression middleware supporting gzip, brotli, deflate, and zstd
  • CorsLayer for configuring cross-origin resource sharing headers declaratively
  • TraceLayer for structured request/response tracing integrated with the tracing crate
  • Auth-adjacent middleware: RequireAuthorizationLayer, sensitive-header redaction, and CSRF helpers
  • Operational middleware: TimeoutLayer, RequestIdLayer, CatchPanicLayer, path normalization, and metrics hooks
  • Everything implemented as standard Tower Service/Layers, composable via tower::ServiceBuilder with any Tower-compatible framework

Common Use Cases

  • Adding gzip/brotli response compression to an axum or hyper server with a single ServiceBuilder layer
  • Configuring CORS for a Rust API consumed by a browser-based frontend without hand-writing header logic
  • Instrumenting every request/response with structured tracing spans for observability
  • Redacting sensitive headers (Authorization, Cookie) from logs while still tracing requests
  • Adding consistent timeouts, panic recovery, and request-ID propagation across every route in a service

Under The Hood

Architecture — The crate is organized as one middleware family per top-level module under tower-http/src/compression/, decompression/, cors/, trace/, auth/, csrf/, follow_redirect/, metrics/, set_header/, timeout/, and standalone files like catch_panic.rs, normalize_path.rs, request_id.rs, and sensitive_headers.rs — each exposing a Layer type that wraps an inner Tower Service. service_ext.rs provides a ServiceBuilderExt trait that adds ergonomic .trace_for_http()/.compression()-style methods directly onto tower::ServiceBuilder, so consumers rarely construct layer types by hand.

Tech Stack — Pure Rust (edition 2018, MSRV 1.65), built directly on the Tower ecosystem: tower-layer/tower-service for the middleware contract, http/bytes for HTTP types, pin-project-lite for safe pinned futures, and bitflags for compact option sets. Nearly every middleware family is gated behind its own Cargo feature flag, so consumers pay compile-time and dependency cost only for the middleware they actually enable.

Code Quality — Each middleware module ships its own focused unit tests colocated with the implementation, plus test-files/ fixtures used by the compression/decompression tests to verify round-tripping across gzip/brotli/deflate/zstd. deny.toml enforces dependency/license auditing via cargo-deny in CI, and the project has sustained very active, well-maintained development (350M+ cumulative downloads, frequent releases) as one of the standard middleware crates for the axum/Tower ecosystem.

API Design — The ServiceBuilderExt trait is the primary ergonomic surface: chaining .layer(CompressionLayer::new()).layer(CorsLayer::permissive()).layer(TraceLayer::new_for_http()) reads as a declarative middleware stack rather than nested wrapper types, and most layers ship sensible ::new() or preset constructors (CorsLayer::permissive()) so getting started requires minimal configuration. Because every middleware follows the same Layer/Service shape, learning one (e.g. CompressionLayer) transfers directly to using any other in the crate.

Used by 13 apps in this directory

Rust
54%
Other

Cameleer

AI Agents

23

A local-first desktop workspace for managing AI agents in an enterprise-style workflow — agent directory, Kanban task tracking, workspace chat, and a full runtime/audit log of agent actions and tool approvals.

View details
48
Repo Health
65
Technical
76
Dependency
Built with
Rust54%
JavaScript24%
TypeScript15%
Updated 4 weeks ago
Svelte
46%
MIT

Cryptgeon

File Storage · Security

1,506

Self-destructing encrypted notes and files that vanish after viewing — the server never sees your keys.

View details
80
Repo Health
80
Technical
74
Dependency
Built with
Svelte46%
TypeScript30%
Rust14%
Updated 1 months ago
Go
32%
Apache 2.0

CubeSandbox

Developer Tools · Security · AI Agents

11,247

Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.

View details
83
Repo Health
88
Technical
63
Dependency
Built with
Go32%
Rust31%
C21%
Updated today
Rust
87%
MIT

fabro

Developer Tools · Devops

1,516

Define AI agent workflows as code graphs, route tasks across any LLM, and intervene only where it matters.

View details
81
Repo Health
83
Technical
70
Dependency
Built with
Rust87%
TypeScript11%
Updated yesterday
Rust
69%
Other

GitButler

Developer Tools · Devops · AI Development

21,531

Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.

View details
89
Repo Health
84
Technical
68
Dependency
Built with
Rust69%
TypeScript18%
Svelte12%
Updated today
Python
80%
Apache 2.0

headroom

AI Development · Developer Tools

66,835

Compress everything your AI agent reads — tool outputs, logs, RAG chunks, and files — before it reaches the LLM, achieving 60–95% fewer tokens with the same answers.

View details
84
Repo Health
86
Technical
73
Dependency
Built with
Python80%
Rust14%
Updated today
Rust
41%
Other

Hook0

Devops

1,477

Open-source Webhooks-as-a-Service: deliver events to your users with auto-retry, signed payloads, and a real-time subscriber dashboard — all without building the infrastructure yourself.

View details
83
Repo Health
82
Technical
70
Dependency
Built with
Rust41%
TypeScript17%
JavaScript15%
Updated today
TypeScript
67%
MIT

Hoppscotch

Developer Tools

80,055

A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.

View details
91
Repo Health
83
Technical
66
Dependency
Built with
TypeScript67%
Vue23%
Updated 3 days ago
Rust
72%
Other

iii

Developer Tools · Devops

18,604

Compose, extend, and observe every backend service in real time using three primitives: Workers, Functions, and Triggers.

View details
86
Repo Health
85
Technical
69
Dependency
Built with
Rust72%
TypeScript17%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search