Skip to content

feat: add x-response-size header to all HTTP responses#85

Merged
krabat-l merged 1 commit intomainfrom
krabat/feat/x-response-size-header
Feb 9, 2026
Merged

feat: add x-response-size header to all HTTP responses#85
krabat-l merged 1 commit intomainfrom
krabat/feat/x-response-size-header

Conversation

@krabat-l
Copy link
Collaborator

@krabat-l krabat-l commented Feb 9, 2026

Summary

  • Add a new x-response-size HTTP response header that reports the response body size (in bytes) on every RPC response
  • Implemented as a Tower Layer/Service middleware (ResponseSizeLayer / ResponseSizeService), following the same pattern as the existing x-execution-time-ns
    timing header
  • Uses http_body::Body::size_hint().exact() to read body size without consuming it

Changes

  • bin/debug-trace-server/src/response_size.rs (new): ResponseSizeLayer + ResponseSizeService + ResponseSizeFuture with pin_project_lite
  • bin/debug-trace-server/src/main.rs: Chain ResponseSizeLayer as the outermost HTTP middleware wrapping TimingHeaderLayer
  • Cargo.toml / bin/debug-trace-server/Cargo.toml: Add http-body dep; bytes + http-body-util as dev-deps

Test plan

  • test_response_size_header_set"hello world" body → header value 11
  • test_response_size_empty_body — empty body → header value 0
  • test_response_size_large_body — 1 MB body → header value 1000000
  • test_format_u64_zero / test_format_u64_max — formatting edge cases

@krabat-l krabat-l requested a review from Troublor February 9, 2026 11:43
@krabat-l krabat-l merged commit c714a38 into main Feb 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments