Skip to content

fix: bypass Content-Type validation when request has no body#111

Merged
sjorobekov merged 1 commit intomainfrom
fix_bypass_header_validation_for_empty_body_requests
Mar 20, 2026
Merged

fix: bypass Content-Type validation when request has no body#111
sjorobekov merged 1 commit intomainfrom
fix_bypass_header_validation_for_empty_body_requests

Conversation

@sjorobekov
Copy link
Contributor

@sjorobekov sjorobekov commented Mar 20, 2026

Description:

What changed?

Updated the withContract function to only enforce Content-Type header validation if the incoming request actually contains a payload.

Why?

Previously, if a route contract defined a body schema but the client sent a request without a body (and thus no Content-Type header), the function would throw an Unsupported content-type error. This fix ensures that requests without a body bypass the strict Content-Type check and correctly fall through to the standard schema validation, which will properly handle the missing body.

Details:

  • Added a hasBody check using transfer-encoding and content-length headers.
  • Wrapped the Content-Type validation logic inside the hasBody condition.
  • Added a test case to verify that empty body requests bypass the content-type check and return standard validation errors.

@sjorobekov sjorobekov marked this pull request as ready for review March 20, 2026 09:37
@sjorobekov sjorobekov merged commit f0a6eb0 into main Mar 20, 2026
5 checks passed
@sjorobekov sjorobekov deleted the fix_bypass_header_validation_for_empty_body_requests branch March 20, 2026 12:12
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