Skip to content

fix(http): skip transport-level headers in mock response generation#2788

Open
rnagulapalle wants to merge 1 commit into
stoplightio:masterfrom
rnagulapalle:fix/skip-transport-headers-in-mock
Open

fix(http): skip transport-level headers in mock response generation#2788
rnagulapalle wants to merge 1 commit into
stoplightio:masterfrom
rnagulapalle:fix/skip-transport-headers-in-mock

Conversation

@rnagulapalle
Copy link
Copy Markdown

Summary

When an OpenAPI spec defines transport-level headers like Content-Encoding as response headers, Prism's computeMockedHeaders generates values from the schema (e.g. picking gzip from an enum) but doesn't actually compress the response body. This causes HTTP clients to fail with decompression errors like zlib.error: Error -3 while decompressing data.

The root cause is that computeMockedHeaders treats 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_HEADERS set containing content-encoding, content-length, transfer-encoding, and content-md5. These are filtered out before header generation in computeMockedHeaders.

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 generation
  • packages/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 preserved

Fixes #2787

Made with Cursor

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
@rnagulapalle rnagulapalle requested a review from a team as a code owner April 28, 2026 18:23
@rnagulapalle
Copy link
Copy Markdown
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?

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.

Prism adds Content-Encoding headers from spec but doesn't compress response body

1 participant