Context
When an OpenAPI spec defines Content-Encoding as a response header, Prism adds this header to mock responses but doesn't actually compress the response body. This causes HTTP clients to fail when attempting to decompress the uncompressed data.
Current Behavior
When an OpenAPI spec includes Content-Encoding as a response header with enum values like:
"headers": {
"Content-Encoding": {
"schema": {
"type": "string",
"enum": ["gzip", "deflate", "br", "compress"]
}
}
}
Prism randomly selects one of these enum values and adds it to the response headers, but the response body remains uncompressed. When HTTP clients (like Python's requests library) see the Content-Encoding header, they attempt to decompress the body and fail with:
zlib.error: Error -3 while decompressing data: incorrect header check
or
requests.exceptions.ContentDecodingError: ('Received response with content-encoding: gzip, but failed to decode it.')
Expected Behavior
Prism should not add Content-Encoding headers to responses unless it's actually compressing the response body. The Content-Encoding header in an OpenAPI spec is describing what the real API does - the mock server shouldn't blindly add it without implementing the actual compression.
Alternatively, Prism could compress the response body to match the header, but that seems unnecessary for a mock server (or maybe not 🤷 ).
Possible Workaround/Solution
Workaround 1: Remove Content-Encoding from the response headers in your OpenAPI spec when using with Prism.
Workaround 2: Use nginx (or another reverse proxy) in front of Prism to strip the Content-Encoding header:
location / {
proxy_pass http://prism:4010;
proxy_hide_header Content-Encoding;
}
Suggested Fix: Prism should ignore Content-Encoding when generating response headers, or at minimum, document that this header should not be included in OpenAPI specs used with Prism.
Steps to Reproduce
-
Create a minimal OpenAPI spec with Content-Encoding in response headers (see below)
-
Start Prism:
npx @stoplight/prism-cli@5.15.10 mock -h 0.0.0.0 -p 4010 prism-minimal-bug-spec.json
-
Make requests with a client that supports decompression:
import requests
session = requests.Session()
session.headers.update({'Accept-Encoding': 'gzip, deflate'})
for i in range(10):
try:
r = session.get('http://localhost:4010/test')
print(f"Run {i+1}: SUCCESS")
except requests.exceptions.ContentDecodingError as e:
print(f"Run {i+1}: FAILED - {e}")
-
Result: 100% of requests fail with decompression errors
Minimal OpenAPI Spec (prism-minimal-bug-spec.json):
{
"openapi": "3.0.0",
"info": {
"title": "Minimal Prism Content-Encoding Bug",
"version": "1.0.0"
},
"paths": {
"/test": {
"get": {
"summary": "Test endpoint",
"responses": {
"200": {
"description": "Success",
"headers": {
"Content-Encoding": {
"description": "The compression algorithm used",
"schema": {
"type": "string",
"enum": ["gzip", "deflate", "br", "compress"]
}
}
},
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
Environment
- Prism Version: 5.14.2 and 5.15.10 (bug exists in both)
- Environment: Node.js v20.19.5 and v25.9.0
- Client: Python 3.11+ with requests library
- Operating System: macOS, Linux (Docker)
- Installation method:
npx @stoplight/prism-cli@5.15.10
Context
When an OpenAPI spec defines
Content-Encodingas a response header, Prism adds this header to mock responses but doesn't actually compress the response body. This causes HTTP clients to fail when attempting to decompress the uncompressed data.Current Behavior
When an OpenAPI spec includes
Content-Encodingas a response header with enum values like:Prism randomly selects one of these enum values and adds it to the response headers, but the response body remains uncompressed. When HTTP clients (like Python's
requestslibrary) see theContent-Encodingheader, they attempt to decompress the body and fail with:or
Expected Behavior
Prism should not add
Content-Encodingheaders to responses unless it's actually compressing the response body. TheContent-Encodingheader in an OpenAPI spec is describing what the real API does - the mock server shouldn't blindly add it without implementing the actual compression.Alternatively, Prism could compress the response body to match the header, but that seems unnecessary for a mock server (or maybe not 🤷 ).
Possible Workaround/Solution
Workaround 1: Remove
Content-Encodingfrom the response headers in your OpenAPI spec when using with Prism.Workaround 2: Use nginx (or another reverse proxy) in front of Prism to strip the
Content-Encodingheader:Suggested Fix: Prism should ignore
Content-Encodingwhen generating response headers, or at minimum, document that this header should not be included in OpenAPI specs used with Prism.Steps to Reproduce
Create a minimal OpenAPI spec with
Content-Encodingin response headers (see below)Start Prism:
Make requests with a client that supports decompression:
Result: 100% of requests fail with decompression errors
Minimal OpenAPI Spec (
prism-minimal-bug-spec.json):{ "openapi": "3.0.0", "info": { "title": "Minimal Prism Content-Encoding Bug", "version": "1.0.0" }, "paths": { "/test": { "get": { "summary": "Test endpoint", "responses": { "200": { "description": "Success", "headers": { "Content-Encoding": { "description": "The compression algorithm used", "schema": { "type": "string", "enum": ["gzip", "deflate", "br", "compress"] } } }, "content": { "application/json": { "schema": { "type": "object", "properties": { "message": { "type": "string" } } } } } } } } } } }Environment
npx @stoplight/prism-cli@5.15.10