1

I am aware of standard HTTP response codes and their categorization (1xx, 2xx, 3xx, 4xx and 5xx)

But, I have seen certain web requests return non-standard HTTP response codes, like 999, 1001, 1002, 1006 etc. However, I have never seen any HTTP response code that contains alphanumeric characters. Is it possible for any server to send non-integer response codes?

3
  • Might be an interesting way to find bugs in HTTP clients but otherwise what would be the point? Commented May 14, 2022 at 0:50
  • @PresidentJamesK.Polk One use case could be to avoid crawling. Say, I have a web client which I suspect will be crawled frequently. One blocking mechanism that I could implement is to respond with alphanumeric status code which would cause many crawler scripts to cause exception. That's non-standard obvs...but an idea. Commented May 16, 2022 at 18:26
  • Oh, you play dirty. I like it:) Commented May 16, 2022 at 19:12

2 Answers 2

2

Non-standard is non-standard. You might call it impossible, or you might say that everything is possible until it breaks something you need.

Practically, most software passes around HTTP status codes as integers, and will reject, break, or behave in unexpected ways if they aren't.

Don't do it.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not planning to do it. I was thinking of an edge case while doing something with python requests module. And there I realised, response.status_code is treated as int value. So, I was wondering if it is possible my requests could fail if a non-standard server would send alpha-numeric response code.
0

A server response is just a sequence of bytes sent over the network. HTTP 1.x is a text-based protocol, where the request and response — including status code — are sent as structured text in a defined format. It is therefore very possible to send across alphanumeric characters where a standards-compliant server would send across a valid HTTP status code.

If a non-numeric value is sent, don't expect clients to do a sane thing with them. Clients quite reasonably expect a standards-compliant (numeric) value, and well-behaved clients would likely fail if they receive something not conforming to the standard.

Example HTTP response:

Take as a concrete example the following HTTP response message. The status code of 200 is found in the status line (HTTP/1.1 200 OK), along with the protocol version (HTTP/1.1) and reason phrase (OK).

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 35

This sentence is the response body.

There is nothing preventing a server from replacing the status code in the status line with literally any other text. For instance, if non-numeric values were allowed, the following might be considered a response with status code "ABC" and reason phrase "Test alphanumeric response".

HTTP/1.1 ABC Test alphanumeric response

IETF status code specification

IETF RFC 7230 requires the status code to be a three-digit integer, and RFC 7231 requires the first digit of the status code to be between 1 and 5.

3.1.2. Status Line

The first line of a response message is the status-line, consisting of the protocol version, a space (SP), the status code, another space, a possibly empty textual phrase describing the status code, and ending with CRLF.

status-line = HTTP-version SP status-code SP reason-phrase CRLF

The status-code element is a 3-digit integer code describing the result of the server's attempt to understand and satisfy the client's corresponding request.

6. Response Status Codes

[…]

The first digit of the status-code defines the class of response. The last two digits do not have any categorization role. There are five values for the first digit:

  • 1xx (Informational): The request was received, continuing process
  • 2xx (Successful): The request was successfully received, understood, and accepted
  • 3xx (Redirection): Further action needs to be taken in order to complete the request
  • 4xx (Client Error): The request contains bad syntax or cannot be fulfilled
  • 5xx (Server Error): The server failed to fulfill an apparently valid request

2 Comments

@vish4071 I expanded my answer with a concrete example, and quotes from the spec that require the status code to be a three digit number
This is great answer. Thanks for extending the post with example and documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.