eclipse-vertx/vert.x · error

411 Length Required

Error message

411 Length Required

What it means

SC_LENGTH_REQUIRED is the HttpResponseExpectation constant for HTTP 411 Length Required. Vert.x offers it for response validation; a 411 response failing this expectation yields '411 Length Required'. The server requires a Content-Length (or valid chunked framing) on the request and rejected it because none was present.

Source

Thrown at vertx-core/src/main/java/io/vertx/core/http/HttpResponseExpectation.java:205

  /**
   * 408 Request Timeout
   */
  HttpResponseExpectation SC_REQUEST_TIMEOUT = status(408);

  /**
   * 409 Conflict
   */
  HttpResponseExpectation SC_CONFLICT = status(409);

  /**
   * 410 Gone
   */
  HttpResponseExpectation SC_GONE = status(410);

  /**
   * 411 Length Required
   */
  HttpResponseExpectation SC_LENGTH_REQUIRED = status(411);

  /**
   * 412 Precondition Failed
   */
  HttpResponseExpectation SC_PRECONDITION_FAILED = status(412);

  /**
   * 413 Request Entity Too Large
   */
  HttpResponseExpectation SC_REQUEST_ENTITY_TOO_LARGE = status(413);

  /**
   * 414 Request-URI Too Long
   */
  HttpResponseExpectation SC_REQUEST_URI_TOO_LONG = status(414);

  /**
   * 415 Unsupported Media Type

View on GitHub (pinned to fb308bd8c3)

Solutions

  1. Call request.setChunked(true) when the body size is unknown before sending
  2. Compute and set the Content-Length header explicitly with putHeader("Content-Length", String.valueOf(buf.length()))
  3. Prefer WebClient.sendBuffer/sendJson helpers which frame the body correctly
  4. If proxying, ensure the framing headers from the original request are forwarded
  5. If the body is empty, end the request without a body so no framing is expected

Example fix

// before
request.write(buffer).end(); // 411 Length Required
// after
request.putHeader("Content-Length", String.valueOf(buffer.length()))
       .write(buffer).end();
// or for streaming: request.setChunked(true);
Defensive patterns

Strategy: validation

Validate before calling

// Before sending a body, ensure framing is set
if (body != null && body.length() > 0) {
  if (request instanceof HttpClientRequest r && !r.isChunked()
      && r.getHeader("Content-Length") == null) {
    r.putHeader("Content-Length", String.valueOf(body.length()));
  }
}

Type guard

boolean isLengthRequired(Throwable t) {
  return t instanceof VertxHttpResponseException
    && ((VertxHttpResponseException) t).getResponse().statusCode() == 411;
}

Try / catch

if (isLengthRequired(t)) { resendWithFraming(body); } else { throw t; }

Prevention

When it happens

Trigger: Sending a request with a body via Vert.x HttpClient without setting Content-Length and without chunked transfer encoding — e.g. writing the body directly with write(Buffer) and ending without framing headers, or a proxy stripping the header.

Common situations: Raw HttpClientRequest usage where the developer forgets `putHeader("Content-Length", ...)` or `setChunked(true)`, streaming bodies of unknown size over servers that mandate length, custom/proxied setups that remove transfer headers.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of eclipse-vertx/vert.x@fb308bd8c3 (2026-09-06). Data as JSON: /api/errors/9ee4278bfab30778. Report an issue: GitHub.