fix(http): skip transport-level headers in mock response generation#2788
Open
rnagulapalle wants to merge 1 commit into
Open
fix(http): skip transport-level headers in mock response generation#2788rnagulapalle wants to merge 1 commit into
rnagulapalle wants to merge 1 commit into
Conversation
When an OpenAPI spec defines transport-level headers like Content-Encoding, Content-Length, or Transfer-Encoding as response headers, Prism generates values from the schema but does not implement the actual transport behavior (e.g. compression). This causes HTTP clients to fail when they try to decompress an uncompressed body that has Content-Encoding: gzip set. Filter out transport-derived headers (Content-Encoding, Content-Length, Transfer-Encoding, Content-MD5) in computeMockedHeaders since their values must be derived from the actual response, not from the spec schema. Fixes stoplightio#2787 Made-with: Cursor
Author
|
Hi Prism maintainers — gentle review nudge on this one. The checks are green, and the change is scoped to skipping transport-level headers when generating mock responses. Is there anything else you'd like adjusted before review? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When an OpenAPI spec defines transport-level headers like
Content-Encodingas response headers, Prism'scomputeMockedHeadersgenerates values from the schema (e.g. pickinggzipfrom an enum) but doesn't actually compress the response body. This causes HTTP clients to fail with decompression errors likezlib.error: Error -3 while decompressing data.The root cause is that
computeMockedHeaderstreats every spec-defined header equally — including transport-level headers whose values must be derived from the actual response, not generated from the spec schema.Fix
Added a
TRANSPORT_HEADERSset containingcontent-encoding,content-length,transfer-encoding, andcontent-md5. These are filtered out before header generation incomputeMockedHeaders.These headers describe transport behavior the mock server doesn't implement, so generating values for them is actively harmful.
Changes
packages/http/src/mocker/index.ts— filter transport-level headers before mock generationpackages/http/src/mocker/__tests__/HttpMocker.spec.ts— added tests verifying Content-Encoding, Transfer-Encoding, and Content-Length are excluded from mocked responses while application headers like X-Request-Id are preservedFixes #2787
Made with Cursor