Open Source API Gateway

400 Bad Request: Request Path or Host Header Is Malformed

Membrane API Gateway returns 400 Bad Request with the title Request path or 'Host' header is malformed when the HTTP client at the end of the flow cannot build a valid backend URL. Nothing is sent to the backend.

The Error Response

The response contains the status 400 Bad Request, the title Request path or 'Host' header is malformed, the problem type https://membrane-api.io/problems/user and a link to this page. The type user means that the request or the configuration caused the problem. Although the title mentions the request, the cause is usually the gateway configuration.

How Membrane Builds the Backend URL

The target of an API sets the destination of the request, either with a url or with host and port. The HTTP client then needs an absolute http:// or https:// URL with a valid host and port. If the destination is not such a URL, it reports this error.

api:
port: 2000
target:
url: https://api.predic8.de
api:
  port: 2000
  target:
    url: https://api.predic8.de

Common Causes

The API Has No Target

The API has neither a target url nor a host, and no plugin set a destination. The destination is then the relative path of the request, for example /orders, which is not an absolute URL.

An Expression in the Target URL Evaluates to an Invalid URL

A target url that contains an expression evaluates to a string that is not a valid absolute URL, for example because a header or property it uses is missing or empty.

The Host or Port Cannot Be Parsed

The host or port of the destination is invalid, for example a non-numeric port or a malformed IPv6 address.

A Forward Proxy Request Has No Absolute URL

When Membrane is used as a forward proxy, a request line that contains only a path instead of an absolute URL gives the gateway no host to connect to.

How to Fix It

  1. Give the API a target with a valid absolute URL, or a host and port.
  2. If the target URL uses expressions, make sure every value it references is always present. The log line Malformed URL. Requested path is: ... shows the destination that failed.
  3. Client: send a well-formed request line and Host header. When using Membrane as a forward proxy, use absolute URLs in the request line.

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:

Tutorials with runnable examples:

← All Membrane error messages

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