{"record":{"id":"522a107b66f9fc83","repo":"eclipse-vertx/vert.x","slug":"request-method-must-be-one-of-post-put-patch-or-522a10","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":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/http/impl/http1/Http1ServerRequest.java","lineNumber":483,"sourceCode":"    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\n  public synchronized boolean isExpectMultipart() {\n    return expectMultipart;\n  }","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/http/impl/http1/Http1ServerRequest.java#L465-L501","documentation":"Thrown by Http1ServerRequest.setExpectMultipart(true) when the HTTP method is not one of POST, PUT, PATCH or DELETE (checked by HttpUtils.isValidMultipartMethod). Multipart body decoding is only meaningful for methods that can carry a body.","triggerScenarios":"Calling request.setExpectMultipart(true) inside handlers for GET, HEAD, OPTIONS, TRACE or CONNECT requests, e.g. a shared handler registered on multiple routes including GET.","commonSituations":"A catch-all route handler that enables multipart regardless of method; routing an upload endpoint with the wrong HTTP method from the client.","solutions":["Ensure the client uses POST/PUT/PATCH/DELETE for the upload","Restrict the route to body-carrying methods, or check request.method() before enabling multipart","Move setExpectMultipart(true) into the POST/PUT handler only"],"exampleFix":"// before\nrequest.setExpectMultipart(true);\n// after\nif (request.method() == HttpMethod.POST || request.method() == HttpMethod.PUT) {\n  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.setExpectMultipart(true);\n}","typeGuard":null,"tryCatchPattern":"try { request.setExpectMultipart(true); } catch (IllegalStateException e) { response.setStatusCode(405).end(); }","preventionTips":["Restrict upload routes to POST/PUT/PATCH/DELETE","Check the method before enabling multipart","Use router methods that limit allowed HTTP methods"],"tags":["http","multipart","http-method","http1"],"backgroundTag":"unsupported-operation","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"}