Open Source API Gateway

500 Internal Server Error: Message Body Could Not Be Read

Membrane API Gateway returns 500 Internal Server Error with the message Could not read the message body. when the xml-protection plugin cannot read a message body that is not the client's request. Usually it is the response of the backend.

The Error Response

The response contains the status 500, the problem type https://membrane-api.io/problems/internal and a link to this page. The type internal means that the problem is on the gateway side, usually the backend. In production mode, the title is replaced with Internal Server Error.

Common Causes

The Backend Sent a Broken Body

The backend closed the connection early or sent a truncated or malformed response body, for example with bad chunked framing or fewer bytes than its Content-Length.

An Invalid Content-Encoding

The backend response is labelled Content-Encoding: gzip, deflate or br, but the body is not valid in that format.

A Streaming Body Is Read by a Plugin

A streaming body, for example from sseDemoStream, cannot be read completely. Combined with a plugin that reads the body, it fails with Streaming body cannot be materialized. Remove the plugin from that API.

How to Fix It

  1. Call the backend directly, for example with curl -v, and inspect its response body and headers.
  2. Fix the backend so that its response bodies match their Content-Length, chunked framing and Content-Encoding.
  3. Check the Membrane log for the stack trace. In production mode, the response carries a log key to search for. For the openapi plugin, no log entry is written.
  4. If neither the backend nor the configuration explains the error, report it on GitHub Issues.

Hide Details in Production

By default, Membrane runs in development mode and adds details to error responses that help you find the problem. These details may reveal information about your setup. In production, turn them off:

configuration:
production: true
configuration:
  production: true

Add the configuration document to your apis.yaml and separate it from the APIs with ---.

Related Documentation

Configuration reference:

← All Membrane error messages

Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.