-
Notifications
You must be signed in to change notification settings - Fork 302
Description
π Bug Summary
Encountered a scenario in deployed environments where the content-length
header is occasionally missing from the response when calling the version/metrics tab. This is causing issues in content-length validation and proper response processing.
In cases where the Content-Length header is absent, we should be able to verify the content length using the content itself. The lack of this header leads to inconsistencies and bugs in client-side or server-side code that depend on it.
Root cause could be:
- Intermediaries such as Proxies or load balancers might strip or modify the Content-Length header.
- In case of Chunked transfer encoding, response body is sent in chunks, making Content-Length unnecessary.
- Compressed content may omit Content-Length as the server doesnβt adjust for compressed size.
π§© Affected Component
Select the area of the project impacted:
-
mcpgateway
- API -
mcpgateway
- UI (admin panel) -
mcpgateway.wrapper
- stdio wrapper - Federation or Transports
- CLI, Makefiles, or shell scripts
- Container setup (Docker/Podman/Compose)
- Other (explain below)
π Steps to Reproduce
- In deployed Environments, with middleware in place.
- Version and Metrics tab fails to load.
π€ Expected Behavior
Check for content-length header in response, if not present, check the length on the response received to confirm if the content is empty or not.
π Logs / Error Output
π§© Additional Context (optional)
Code changes:
Current code:
if (
response.status === 0 ||
(response.ok &&
response.status === 200 &&
!response.headers.get("content-length"))
) {
console.warn(`Empty response received from ${url}`);
throw new Error("Server returned an empty response");
}
New Code:
if (response.status === 0 || (response.ok && response.status === 200)) {
const contentLength = response.headers.get("content-length");
// Check Content-Length if present
if (contentLength !== null) {
if (parseInt(contentLength, 10) === 0) {
throw new Error("Server returned an empty response (via header)");
}
} else {
// Fallback: check actual body
const cloned = response.clone();
const text = await cloned.text();
if (!text.trim()) {
throw new Error("Server returned an empty response (via body)");
}
}
}
π§ Environment Info
You can retrieve most of this from the /version
endpoint.
Key | Value |
---|---|
Version or commit | e.g. v0.9.0 or main@a1b2c3d |
Runtime | e.g. Python 3.11, Gunicorn |
Platform / OS | e.g. Ubuntu 22.04, macOS |
Container | e.g. Docker, Podman, none |