{"record":{"id":"fceeaa045c62d059","repo":"eclipse-vertx/vert.x","slug":"request-must-have-a-valid-content-type-header-to-d-fceeaa","errorCode":null,"errorMessage":"Request must have a valid content-type header to decode a multipart request","messagePattern":"Request must have a valid content-type header to decode a multipart request","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/http/impl/http1/Http1ServerRequest.java","lineNumber":480,"sourceCode":"      }\n    });\n    // In case we were paused\n    resume();\n  }\n\n  @Override\n  public HttpServerRequest setExpectMultipart(boolean expect) {\n    synchronized (conn) {\n      checkEnded();\n      expectMultipart = expect;\n      if (expect) {\n        if (decoder == null) {\n          String contentType = request.headers().get(HttpHeaderNames.CONTENT_TYPE);\n          if (contentType == null) {\n            throw new IllegalStateException(\"Request must have a content-type header to decode a multipart request\");\n          }\n          if (!HttpUtils.isValidMultipartContentType(contentType)) {\n            throw new IllegalStateException(\"Request must have a valid content-type header to decode a multipart request\");\n          }\n          if (!HttpUtils.isValidMultipartMethod(request.method())) {\n            throw new IllegalStateException(\"Request method must be one of POST, PUT, PATCH or DELETE to decode a multipart request\");\n          }\n          NettyFileUploadDataFactory factory = new NettyFileUploadDataFactory(context, this, () -> uploadHandler);\n          factory.setMaxLimit(conn.maxFormAttributeSize());\n          int maxFields = conn.maxFormFields();\n          int maxBufferedBytes = conn.maxFormBufferedBytes();\n          decoder = new HttpPostRequestDecoder(factory, request, HttpConstants.DEFAULT_CHARSET, maxFields, maxBufferedBytes);\n        }\n      } else {\n        decoder = null;\n      }\n      return this;\n    }\n  }\n\n  @Override","sourceCodeStart":462,"sourceCodeEnd":498,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/http/impl/http1/Http1ServerRequest.java#L462-L498","documentation":"Thrown by Http1ServerRequest.setExpectMultipart(true) when the Content-Type header is present but not a valid multipart type (checked by HttpUtils.isValidMultipartContentType, i.e. not multipart/form-data, multipart/mixed etc.). Vert.x only installs a multipart decoder when the content type actually declares multipart.","triggerScenarios":"Calling request.setExpectMultipart(true) on a request whose Content-Type is e.g. application/x-www-form-urlencoded, application/json, or 'multipart' missing the boundary parameter where required.","commonSituations":"Server code enabling multipart unconditionally but clients sending urlencoded forms; mismatched client Content-Type; middleware rewriting the header.","solutions":["Set the client Content-Type to multipart/form-data with a boundary parameter","Only call setExpectMultipart(true) when the header starts with 'multipart/'","If the body is urlencoded, do not enable multipart decoding; use request.formAttributes() instead"],"exampleFix":"// before\nif (request.method() == HttpMethod.POST) { request.setExpectMultipart(true); }\n// after\nString ct = request.getHeader(HttpHeaderNames.CONTENT_TYPE);\nif (ct != null && ct.toLowerCase().startsWith(\"multipart/\")) { request.setExpectMultipart(true); }","handlingStrategy":"validation","validationCode":"String ct = request.getHeader(HttpHeaderNames.CONTENT_TYPE);\nif (ct != null && ct.toLowerCase().startsWith(\"multipart/\")) {\n  request.setExpectMultipart(true);\n}","typeGuard":null,"tryCatchPattern":"try { request.setExpectMultipart(true); } catch (IllegalStateException e) { logger.warn(\"Not a multipart request: \" + ct); }","preventionTips":["Verify client Content-Type is multipart/form-data with boundary","Check for proxies stripping/rewriting Content-Type","Route urlencoded forms to formAttributes() instead"],"tags":["http","multipart","content-type","http1"],"backgroundTag":"invalid-argument-value","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"}