{"record":{"id":"834566bf75a478d6","repo":"alibaba/Sentinel","slug":"no-legal-content-length","errorCode":null,"errorMessage":"No legal Content-Length","messagePattern":"No legal Content-Length","errorType":"http","errorClass":"RequestException","httpStatus":411,"severity":"warning","filePath":"sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/http/HttpEventTask.java","lineNumber":191,"sourceCode":"            throw new RequestException(StatusCode.BAD_REQUEST, \"\");\n        }\n\n        if (headerMap.containsKey(\"content-type\") && !checkContentTypeSupported(headerMap.get(\"content-type\"))) {\n            // not supported Content-type\n            CommandCenterLog.warn(\"Request not supported: unsupported Content-Type: \" + headerMap.get(\"content-type\"));\n            throw new RequestException(StatusCode.UNSUPPORTED_MEDIA_TYPE,\n                \"Only form-encoded post request is supported\");\n        }\n\n        int bodyLength = 0;\n        try {\n            bodyLength = Integer.parseInt(headerMap.get(\"content-length\"));\n        } catch (Exception e) {\n        }\n        if (bodyLength < 1) {\n            // illegal request without Content-length header\n            CommandCenterLog.warn(\"Request not supported: no available Content-Length in headers\");\n            throw new RequestException(StatusCode.LENGTH_REQUIRED, \"No legal Content-Length\");\n        }\n\n        parseParams(readBody(in, bodyLength), request);\n    }\n\n    /**\n     * Process header line in request\n     *\n     * @param in\n     * @return return headers in a Map, null for illegal request\n     * @throws IOException\n     */\n    protected static Map<String, String> parsePostHeaders(InputStream in) throws IOException {\n        Map<String, String> headerMap = new HashMap<String, String>(4);\n        String line;\n        while (true) {\n            line = readLine(in);\n            if (line == null || line.length() == 0) {","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/http/HttpEventTask.java#L173-L209","documentation":"The simple-http command center requires every POST to carry a parseable, positive Content-Length header. processPostRequest parses headerMap.get(\"content-length\") with Integer.parseInt (failures silently leave 0) and throws RequestException(StatusCode.LENGTH_REQUIRED, \"No legal Content-Length\") when bodyLength < 1 — returned to the client as HTTP 411. Without a length it cannot know how many body bytes to read.","triggerScenarios":"POSTing with chunked transfer encoding (curl -H 'Transfer-Encoding: chunked'), using HTTP/1.0 without Content-Length, or a Content-Length of 0/negative/non-numeric to the simple-http command port; header name case variants are handled, but a missing or malformed value is not.","commonSituations":"HTTP client libraries defaulting to chunked encoding for streaming bodies; proxies stripping Content-Length; curl with --data-binary on a pipe choosing chunked; empty-body POSTs where the sender omits the header entirely.","solutions":["Always send Content-Length: use a fixed-size body (curl -d @file or byte[] with the client's default buffering) instead of chunked streaming","Disable chunked transfer in your HTTP client for command-center calls (e.g. Apache HttpClient entity with known length)","If the body is empty, still send Content-Length: 0? No — this endpoint requires a body, so send at least one form parameter"],"exampleFix":"// before (chunked, no Content-Length)\nHttpPost post = new HttpPost(url);\npost.setEntity(new InputStreamEntity(stream, -1)); // -1 -> chunked -> 411\n\n// after\nbyte[] body = formBytes;\npost.setEntity(new ByteArrayEntity(body)); // sets Content-Length automatically","handlingStrategy":"validation","validationCode":"// client-side: ensure a fixed-length body so Content-Length is sent\nif (bodyBytes == null || bodyBytes.length < 1) {\n    throw new IllegalStateException(\"POST to command center requires a non-empty body\");\n}\nconnection.setRequestProperty(\"Content-Length\", String.valueOf(bodyBytes.length));\nconnection.setChunkedStreamingMode(-1); // never chunked: 0 disables chunking","typeGuard":null,"tryCatchPattern":"if (status == 411) {\n    // resend with buffered, fixed-length body so Content-Length is present\n}","preventionTips":["Disable chunked transfer encoding for command-center POSTs","Always POST at least one form parameter"],"tags":["sentinel","transport","http","content-length","simple-http"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}