zaproxy/zaproxy · error · HttpMalformedHeaderException

Failed to find pattern:

Error message

Failed to find pattern: 

What it means

HttpMalformedHeaderException thrown by HttpResponseHeader.parse when the status line does not match the expected HTTP/version status-code pattern. The response bytes at fault are not a valid HTTP response start line (e.g. garbage, HTML error page from a non-HTTP service).

Source

Thrown at zap/src/main/java/org/parosproxy/paros/network/HttpResponseHeader.java:212

    /**
     * Sets the reason phrase.
     *
     * <p>If {@code null} it's set an empty string.
     *
     * @param reasonPhrase the new reason phrase.
     * @see #getReasonPhrase()
     * @since 2.7.0
     */
    public void setReasonPhrase(String reasonPhrase) {
        this.mReasonPhrase = reasonPhrase != null ? reasonPhrase : "";
    }

    private void parse() throws HttpMalformedHeaderException {

        Matcher matcher = patternStatusLine.matcher(mStartLine);
        if (!matcher.find()) {
            mMalformedHeader = true;
            throw new HttpMalformedHeaderException("Failed to find pattern: " + patternStatusLine);
        }

        mVersion = matcher.group(1);
        mStatusCodeString = matcher.group(2);
        setReasonPhrase(matcher.group(3));

        try {
            mStatusCode = Integer.parseInt(mStatusCodeString);
        } catch (NumberFormatException e) {
            mMalformedHeader = true;
            throw new HttpMalformedHeaderException("Unexpected status code: " + mStatusCodeString);
        }
    }

    @Override
    public int getContentLength() {
        int len = super.getContentLength();

View on GitHub (pinned to 9d1970a436)

Solutions

  1. Check you are connecting to an HTTP service on the expected port
  2. Catch HttpMalformedHeaderException and treat the message as non-HTTP
  3. Validate raw response bytes before wrapping in HttpResponseHeader
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at zap/src/main/java/org/parosproxy/paros/network/HttpResponseHeader.java:212 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zaproxy/zaproxy@9d1970a436 (2026-09-05). Data as JSON: /api/errors/febd9edf39f6d1d7. Report an issue: GitHub.