The HTTP status code 421 indicates a “Misdirected Request.” This is a relatively new status code introduced in the HTTP/2 specification.
Definition
- The 421 status code signifies that the server believes the request was misdirected to a server that cannot produce a response.
Reason for Introduction
- This status code was primarily introduced to address specific issues in HTTP/2, particularly those related to connection multiplexing.
Use Cases
- When a client sends a request over an HTTP/2 connection, but the server cannot provide service for that specific request.
- In cases of misconfiguration with load balancers or proxy servers.
- When a request reaches the wrong server, which knows it should not handle the request.
Specific Examples
- In a web application using multiple virtual hosts, if a request reaches the wrong virtual host, the server might return a 421.
- In environments using TLS SNI (Server Name Indication), if the client connects to the incorrect server.
Server Behavior
- When returning a 421 status code, the server should close the connection, or if using HTTP/2, it may only close the corresponding stream.
Client Behavior
- Upon receiving a 421 response, the client should typically:
- Attempt to re-establish the connection and resend the request.
- Check whether it is using the correct server address and port.
Distinction from Other Status Codes
- Unlike 404 (Not Found), 421 indicates that the entire server is incorrect, rather than just that the requested resource does not exist.
- It is also different from 503 (Service Unavailable), as 421 explicitly states that the request was misdirected, rather than the server being temporarily unable to handle the request.
Importance in HTTP/2
- Since HTTP/2 allows multiple requests to be multiplexed over a single TCP connection, 421 can help clients identify when a new connection is needed for a specific request.
Implementation Considerations
- Server developers should use this status code judiciously, ensuring it is returned only in genuinely suitable cases.
- Client developers should be prepared to handle this status code, especially when implementing HTTP/2 clients.
Potential Issues
- Overuse of 421 may lead to unnecessary connection re-establishment, increasing network load and latency.
Although this status code is not as widely used as some more common codes, it can be a valuable tool in modern web architectures, particularly in complex server setups, load balancing, and HTTP/2 implementations. Understanding and correctly using 421 can help developers build more robust and efficient web applications and services.
Related 4xx error code
- 400 Bad Request
- 401 Unauthorized
- 402 Payment Required
- 403 Forbidden
- 404 Not Found
- 405 Method Not Allowed
- 406 Not Acceptable
- 407 Proxy Authentication Required
- 408 Request Timeout
- 409 Conflict
- 410 Gone
- 411 Length Required
- 412 Precondition Failed
- 413 Payload Too Large
- 414 URI Too Long
- 415 Unsupported Media Type
- 416 Range Not Satisfiable
- 417 Expectation Failed
- 418 I’m a teapot
- 422 Unprocessable Entity (WebDAV)
- 423 Locked (WebDAV)
- 424 Failed Dependency (WebDAV)
- 425 Too Early
- 426 Upgrade Required
- 428 Precondition Required
- 429 Too Many Requests
- 431 Request Header Fields Too Large
- 451 Unavailable For Legal Reasons
- 499 Client Closed Request