tower-http

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

Library
Cargo
v0.7.1
918 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
82 /100 Excellent
Development Activity 84
Maintenance 72
Community 84
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
81 /100 Excellent
Architecture 83
Code Quality 85
Innovation 78
Learning Curve 76

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 15 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
40
Repo Health
65
Technical
76
Dependency
Built with
Rust 54%
JavaScript 24%
TypeScript 15%
Updated 2 months ago
Svelte
44%
MIT

Cryptgeon

File Storage · Security

1,538

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

View details
88
Repo Health
80
Technical
74
Dependency
Built with
Svelte 44%
TypeScript 39%
Rust 13%
Updated 6 days ago
Go
32%
Apache 2.0

CubeSandbox

AI Agents · Developer Tools · Security

12,728

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
82
Repo Health
88
Technical
63
Dependency
Built with
Go 32%
Rust 26%
C 22%
Updated 1 weeks ago
Rust
80%
MIT

fabro

Developer Tools · Devops

1,658

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

View details
82
Repo Health
83
Technical
67
Dependency
Built with
Rust 80%
TypeScript 15%
Updated 5 days ago
Rust
65%
Other

GitButler

AI Development · Developer Tools · Devops

21,726

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
66
Dependency
Built with
Rust 65%
TypeScript 22%
Svelte 10%
Updated 4 days ago
Python
82%
Apache 2.0

headroom

AI Development · Developer Tools

73,966

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
85
Repo Health
86
Technical
69
Dependency
Built with
Python 82%
Rust 12%
Updated 5 days ago
Rust
37%
Other

Hook0

Devops

1,491

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
82
Repo Health
82
Technical
69
Dependency
Built with
Rust 37%
TypeScript 12%
Updated 1 weeks ago
TypeScript
67%
MIT

Hoppscotch

Developer Tools

80,529

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
65
Dependency
Built with
TypeScript 67%
Vue 25%
Updated 6 days ago
Rust
73%
Other

iii

Developer Tools · Devops

18,814

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

View details
87
Repo Health
85
Technical
65
Dependency
Built with
Rust 73%
TypeScript 16%
Updated 5 days ago

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