{"record":{"id":"241756975de4f37d","repo":"eclipse-vertx/vert.x","slug":"421-misdirected-request","errorCode":null,"errorMessage":"421 Misdirected Request","messagePattern":"421 Misdirected Request","errorType":"http","errorClass":null,"httpStatus":421,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/http/HttpResponseExpectation.java","lineNumber":240,"sourceCode":"  /**\n   * 415 Unsupported Media Type\n   */\n  HttpResponseExpectation SC_UNSUPPORTED_MEDIA_TYPE = status(415);\n\n  /**\n   * 416 Requested Range Not Satisfiable\n   */\n  HttpResponseExpectation SC_REQUESTED_RANGE_NOT_SATISFIABLE = status(416);\n\n  /**\n   * 417 Expectation Failed\n   */\n  HttpResponseExpectation SC_EXPECTATION_FAILED = status(417);\n\n  /**\n   * 421 Misdirected Request\n   */\n  HttpResponseExpectation SC_MISDIRECTED_REQUEST = status(421);\n\n  /**\n   * 422 Unprocessable Entity (WebDAV, RFC4918)\n   */\n  HttpResponseExpectation SC_UNPROCESSABLE_ENTITY = status(422);\n\n  /**\n   * 423 Locked (WebDAV, RFC4918)\n   */\n  HttpResponseExpectation SC_LOCKED = status(423);\n\n  /**\n   * 424 Failed Dependency (WebDAV, RFC4918)\n   */\n  HttpResponseExpectation SC_FAILED_DEPENDENCY = status(424);\n\n  /**\n   * 425 Unordered Collection (WebDAV, RFC3648)","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/http/HttpResponseExpectation.java#L222-L258","documentation":"SC_MISDIRECTED_REQUEST is a Vert.x HttpResponseExpectation constant representing HTTP status 421. It is used with the HttpClient 'expecting(...)' API to assert that a response has status 421, or to fail a request chain when the server reports the response was sent to a server unable to produce a response for the combination of scheme/authority in the request URI. HTTP/2 servers (e.g. when connection coalescing is misconfigured) commonly emit 421.","triggerScenarios":"A request is sent to a host/port combination the server is not the authoritative server for, typically over HTTP/2 after connection reuse/coalescing, or when SNI/hostname does not match the virtual host the client targeted. Used as a validation expectation: client.request(...).expecting(HttpResponseExpectation.SC_MISDIRECTED_REQUEST).","commonSituations":"HTTP/2 connection coalescing across origins with mismatched TLS certificates; reverse proxy or load balancer routing a request to the wrong backend vhost; SNI misconfiguration after a domain move; CDN pointing at a server that does not serve that Host header.","solutions":["Verify the request URI authority (host:port) matches a virtual host the target server actually serves, and that SNI/TLS certificates cover it.","Disable connection sharing/coalescing (e.g. per-host HttpClients or set the correct authority) so requests are not reused across mismatched origins.","Fix reverse proxy / load balancer routing rules so the Host header is forwarded and routed to the correct backend.","If you intentionally test for 421, keep the expectation; otherwise switch to a success expectation (SC_OK or SC_SUCCESSFUL)."],"exampleFix":"// before\nclient.request(new RequestOptions().setHost(\"wrong.example.com\"))\n  .compose(HttpClientRequest::send)\n  .expecting(HttpResponseExpectation.SC_OK)...\n// after\nclient.request(new RequestOptions().setHost(\"correct.example.com\").setPort(443).setSsl(true))\n  .compose(HttpClientRequest::send)\n  .expecting(HttpResponseExpectation.SC_OK)...","handlingStrategy":"try-catch","validationCode":"if (!expectedHosts.contains(requestOptions.getHost())) {\n  throw new IllegalStateException(\"host \" + requestOptions.getHost() + \" not served by this connection\");\n}","typeGuard":"boolean is421(HttpClientResponse resp) { return resp.statusCode() == 421; }","tryCatchPattern":"// expectation failure surfaces as VertxException/HttpException in the future\nrequest.compose(HttpClientRequest::send)\n  .expecting(HttpResponseExpectation.SC_OK)\n  .onFailure(err -> { if (isCauseStatus(err, 421)) rerouteToCorrectAuthority(); });","preventionTips":["Match request authority (scheme, host, port) to servers that actually serve it","Avoid HTTP/2 connection reuse across origins with different certificates","Keep SNI and Host header consistent with backend vhost routing","Test after any certificate or proxy routing change"],"tags":["http","http2","routing","vertx-http-client"],"backgroundTag":"http-error-status","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}