{"record":{"id":"9ee4278bfab30778","repo":"eclipse-vertx/vert.x","slug":"411-length-required","errorCode":null,"errorMessage":"411 Length Required","messagePattern":"411 Length Required","errorType":"http","errorClass":null,"httpStatus":411,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/http/HttpResponseExpectation.java","lineNumber":205,"sourceCode":"  /**\n   * 408 Request Timeout\n   */\n  HttpResponseExpectation SC_REQUEST_TIMEOUT = status(408);\n\n  /**\n   * 409 Conflict\n   */\n  HttpResponseExpectation SC_CONFLICT = status(409);\n\n  /**\n   * 410 Gone\n   */\n  HttpResponseExpectation SC_GONE = status(410);\n\n  /**\n   * 411 Length Required\n   */\n  HttpResponseExpectation SC_LENGTH_REQUIRED = status(411);\n\n  /**\n   * 412 Precondition Failed\n   */\n  HttpResponseExpectation SC_PRECONDITION_FAILED = status(412);\n\n  /**\n   * 413 Request Entity Too Large\n   */\n  HttpResponseExpectation SC_REQUEST_ENTITY_TOO_LARGE = status(413);\n\n  /**\n   * 414 Request-URI Too Long\n   */\n  HttpResponseExpectation SC_REQUEST_URI_TOO_LONG = status(414);\n\n  /**\n   * 415 Unsupported Media Type","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/http/HttpResponseExpectation.java#L187-L223","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Call request.setChunked(true) when the body size is unknown before sending","Compute and set the Content-Length header explicitly with putHeader(\"Content-Length\", String.valueOf(buf.length()))","Prefer WebClient.sendBuffer/sendJson helpers which frame the body correctly","If proxying, ensure the framing headers from the original request are forwarded","If the body is empty, end the request without a body so no framing is expected"],"exampleFix":"// before\nrequest.write(buffer).end(); // 411 Length Required\n// after\nrequest.putHeader(\"Content-Length\", String.valueOf(buffer.length()))\n       .write(buffer).end();\n// or for streaming: request.setChunked(true);","handlingStrategy":"validation","validationCode":"// Before sending a body, ensure framing is set\nif (body != null && body.length() > 0) {\n  if (request instanceof HttpClientRequest r && !r.isChunked()\n      && r.getHeader(\"Content-Length\") == null) {\n    r.putHeader(\"Content-Length\", String.valueOf(body.length()));\n  }\n}","typeGuard":"boolean isLengthRequired(Throwable t) {\n  return t instanceof VertxHttpResponseException\n    && ((VertxHttpResponseException) t).getResponse().statusCode() == 411;\n}","tryCatchPattern":"if (isLengthRequired(t)) { resendWithFraming(body); } else { throw t; }","preventionTips":["Always set Content-Length or call setChunked(true) for bodied requests","Prefer WebClient helpers (sendBuffer/sendJson) over raw writes","When proxying, forward framing headers","Don't set framing headers on bodiless requests"],"tags":["http","content-length","request-framing","vertx"],"backgroundTag":"http-request-failed","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}