Visitar URL original
fix(humafiber): correct Fiber v2 EachHeader iteration and body decompression by robtme · Pull Request #1058 · danielgtaylor/huma · GitHub
Skip to content

fix(humafiber): correct Fiber v2 EachHeader iteration and body decompression - #1058

Merged
robtme merged 1 commit into
mainfrom
fix/fiber-v2-eachheader-bodyreader
Jul 11, 2026
Merged

robtme merged 1 commit into
mainfrom
fix/fiber-v2-eachheader-bodyreader

Conversation

@robtme

@robtme robtme commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1055

Problem

The Fiber v2 adapter (humafiber.NewV2, added in #962) has two bugs in its huma.Context implementation:

  1. EachHeader iterates bytes, not headers. (*fasthttp.RequestHeader).All() returns iter.Seq2[[]byte, []byte] yielding (name, value) pairs, but the code treated the value as a slice of values and ranged over it, invoking the callback once per byte. A request with Authorization: Bearer abc produced ten single-character callbacks. This broke huma.ReadCookie/huma.ReadCookies, which collect the Cookie header via EachHeader, so cookies were no longer found.

  2. BodyReader used BodyRaw() instead of Body(). BodyRaw() returns the raw bytes without decompressing, so compressed request bodies reached handlers still compressed. The Fiber v3 adapter and v2.37.3 both use Body(), which decompresses per Content-Encoding.

Fix

  • EachHeader: range both values of the Seq2, one callback per header value.
  • BodyReader: use orig.Body(), matching the v3 adapter and v2.37.3.

Tests

  • TestFiberV2EachHeaderAndCookie — asserts one callback per header value and a readable cookie.
  • TestFiberV2BodyReaderDecompresses — sends a gzip body with Content-Encoding: gzip and asserts the handler receives decompressed, parseable JSON.

Both tests fail against the unfixed source and pass with the fix.

…ression

Header.All() returns iter.Seq2[[]byte, []byte] yielding (name, value)
pairs, but EachHeader ranged the value as a byte slice, invoking the
callback once per byte. This broke huma.ReadCookie/ReadCookies, which
collect the Cookie header via EachHeader. Range both values instead.

Also switch BodyReader from BodyRaw() to Body() to match the Fiber v3
adapter and v2.37.3, so compressed request bodies are decompressed
before reaching handlers.

Fixes #1055
@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (770e618) to head (efe8931).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1058   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          23       23           
  Lines        4919     4919           
=======================================
  Hits         4583     4583           
  Misses        272      272           
  Partials       64       64           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@robtme
robtme merged commit fcd9058 into main Jul 11, 2026
7 checks passed
@robtme
robtme deleted the fix/fiber-v2-eachheader-bodyreader branch July 11, 2026 15:46
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.

v2.38.0: humafiber's Fiber v2 EachHeader iterates bytes, breaking huma.ReadCookie

1 participant