Skip to content

refactor(server): use tower-http DefaultPredicate.and() for compression skip rules #172

Description

@momics

Summary

crates/iroh-http-core/src/server.rs#L863-906 implements the compression-skip predicates as hand-written closures. tower_http::compression::predicate::DefaultPredicate already covers the standard set and chains via .and(). Use it instead, then add only the project-specific predicates on top.

Follow-up to the post-rework review at reviews/2026-04-30-post-rework-review.md §5.4.

Evidence

  • tower_http::compression::predicate provides DefaultPredicate (size + content-type + already-encoded) and NotForContentType, SizeAbove building blocks.
  • Our predicate logic (server.rs#L863-906) duplicates the "already encoded" and "no-transform" checks.

Impact

  • Drift risk if upstream improves the default predicate (e.g. adds a media-type).
  • More code to read and test for the same effect.

Remediation

  1. Replace the manual closure stack with DefaultPredicate::default().and(NotForContentType::new("application/zstd")).and(NoTransformCacheControl) (where NoTransformCacheControl is a small custom predicate if not in tower-http).
  2. Verify the threshold passes through (SizeAbove(min_body_bytes) is part of DefaultPredicate configurable via .with_size_above).
  3. Remove the bespoke closures.

Acceptance criteria

  • Predicate composition uses DefaultPredicate + named building blocks.
  • All compression behaviour preserved (covered by existing tests).
  • ~30 lines removed from server.rs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4enhancementNew feature or requestrustPull requests that update rust code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions