{"record":{"id":"2e7711da69c650e3","repo":"eclipse-vertx/vert.x","slug":"request-method-must-be-one-of-post-put-patch-or","errorCode":null,"errorMessage":"Request method must be one of POST, PUT, PATCH or DELETE to decode a multipart request","messagePattern":"Request method must be one of POST, PUT, PATCH or DELETE to decode a multipart request","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/http/impl/HttpServerRequestImpl.java","lineNumber":421,"sourceCode":"    return response.netSocket(this);\n  }\n\n  @Override\n  public HttpServerRequest setExpectMultipart(boolean expect) {\n    synchronized (connection) {\n      checkEnded();\n      expectMultipart = expect;\n      if (expect) {\n        if (postRequestDecoder == null) {\n          String contentType = headersMap.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(method.toNetty())) {\n            throw new IllegalStateException(\"Request method must be one of POST, PUT, PATCH or DELETE to decode a multipart request\");\n          }\n          HttpRequest req = new DefaultHttpRequest(\n            io.netty.handler.codec.http.HttpVersion.HTTP_1_1,\n            method.toNetty(),\n            uri);\n          req.headers().add(HttpHeaderNames.CONTENT_TYPE, contentType);\n          NettyFileUploadDataFactory factory = new NettyFileUploadDataFactory(context, this, () -> uploadHandler);\n          factory.setMaxLimit(maxFormAttributeSize);\n          postRequestDecoder = new HttpPostRequestDecoder(factory, req, HttpConstants.DEFAULT_CHARSET, maxFormFields, maxFormBufferedBytes);\n        }\n      } else {\n        postRequestDecoder = null;\n      }\n    }\n    return this;\n  }\n\n  @Override","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/http/impl/HttpServerRequestImpl.java#L403-L439","documentation":"Multipart decoding via setExpectMultipart(true) is only supported for methods with a body semantics — POST, PUT, PATCH, DELETE (validated by HttpUtils.isValidMultipartMethod). Using it on GET, HEAD, OPTIONS, etc. throws IllegalStateException because those requests normally carry no multipart body.","triggerScenarios":"Calling request.setExpectMultipart(true) on a GET, HEAD, OPTIONS, or other non POST/PUT/PATCH/DELETE request.","commonSituations":"Shared middleware that enables multipart on every route including GET endpoints; misconfigured client sending form data with GET; framework routing that applies the same body handling to all methods.","solutions":["Send the multipart upload with POST, PUT, PATCH, or DELETE instead of GET","Guard setExpectMultipart(true) with a method check","Move file uploads to a POST endpoint"],"exampleFix":"// before\nrouter.route(\"/upload\").handler(ctx -> {\n  ctx.request().setExpectMultipart(true); // throws for GET\n});\n\n// after\nrouter.post(\"/upload\").handler(ctx -> {\n  ctx.request().setExpectMultipart(true);\n});","handlingStrategy":"validation","validationCode":"HttpMethod m = request.method();\nif (m != HttpMethod.POST && m != HttpMethod.PUT && m != HttpMethod.PATCH && m != HttpMethod.DELETE) {\n  request.response().setStatusCode(405).end();\n  return;\n}\nrequest.setExpectMultipart(true);","typeGuard":null,"tryCatchPattern":"try {\n  request.setExpectMultipart(true);\n} catch (IllegalStateException e) {\n  // method not multipart-capable\n}","preventionTips":["Bind multipart handling only to POST/PUT/PATCH/DELETE routes","Use router.post(...) instead of router.route(...) for upload endpoints","Upload files with POST, not GET"],"tags":["http","multipart","http-method","validation"],"backgroundTag":"invalid-config-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"}