Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

HTTP Status Codes Beyond 200: What They Mean for Web Testing

· 7 min read · Home Tech

In this article
  1. Background: Why Status Codes Matter in Web Testing
  2. How It Works: Reading and Interpreting Status Codes
  3. How to Choose the Right Status Code Tests
  4. Common Problems and Misconceptions
  5. Comparing Status Codes Across HTTP Versions
  6. Practical Testing Tools and Techniques
  7. Frequently Asked Questions

HTTP status codes beyond 200 OK are the server's way of telling you what happened to your request, and for web testing they are the first signal of whether a feature works, is misconfigured, or is completely broken. Every code in the 2xx, 3xx, 4xx, and 5xx ranges has a specific meaning, and knowing how to interpret and test them can save hours of debugging and prevent subtle issues from reaching production.

Background: Why Status Codes Matter in Web Testing

When a browser or API client sends a request to a server, the server responds with a three-digit status code plus a reason phrase (like "OK" or "Not Found"). These codes are standardized by the Internet Assigned Numbers Authority (IANA) and defined in RFC 9110. For testers, the status code is often the quickest way to verify that a request was handled correctly, but many tests only check for 200 and miss the richer information other codes provide.

Status codes are grouped into five classes:

  • 1xx (Informational) – the request was received and processing continues.
  • 2xx (Successful) – the request was understood and accepted.
  • 3xx (Redirection) – further action is needed to complete the request.
  • 4xx (Client Error) – the request contains bad syntax or cannot be fulfilled.
  • 5xx (Server Error) – the server failed to fulfill a valid request.

For web testing, the most important groups are 2xx, 3xx, 4xx, and 5xx. A test that only asserts "status is 200" will miss redirects, authentication failures, rate limiting, and server crashes.

How It Works: Reading and Interpreting Status Codes

Each status code has a specific meaning defined by the HTTP specification. Here are the ones you will encounter most often in web testing:

  • 200 OK – the request succeeded; the response body contains the requested resource.
  • 201 Created – a new resource was created (typically after a POST request).
  • 204 No Content – the request succeeded, but there is no content to return (common after DELETE).
  • 301 Moved Permanently – the resource has a new permanent URL; clients should update their bookmarks.
  • 302 Found – temporary redirect; the client should use the Location header for this request only.
  • 304 Not Modified – the cached version is still valid; the server sends no body.
  • 400 Bad Request – the server cannot understand the request due to malformed syntax.
  • 401 Unauthorized – authentication is required and has failed or not been provided.
  • 403 Forbidden – the server understood the request but refuses to authorize it.
  • 404 Not Found – the resource does not exist.
  • 429 Too Many Requests – the user has sent too many requests in a given time (rate limiting).
  • 500 Internal Server Error – a generic server-side error.
  • 502 Bad Gateway – an upstream server returned an invalid response.
  • 503 Service Unavailable – the server is not ready to handle the request (often due to maintenance or overload).
  • 504 Gateway Timeout – an upstream server did not respond in time.

In testing, you should verify not only the code but also the response headers (like Location for redirects) and the body (like error messages). For example, a 404 might be expected for a deleted resource, but an unexpected 404 on a page that should exist is a bug.

How to Choose the Right Status Code Tests

When writing test cases, map each user scenario to the expected status code. Here is a practical approach:

  1. List the critical user journeys: login, search, add to cart, checkout, profile update, etc.
  2. For each journey, define the expected success code (usually 200, 201, or 204).
  3. Define negative tests: wrong credentials (401), missing permissions (403), invalid input (400), nonexistent resource (404), too many requests (429).
  4. Test redirects: old URLs should return 301 or 302 with a valid Location header.
  5. Test caching: repeat requests should return 304 when the cache is fresh.
  6. Simulate server failures: shut down a backend service to check for 502 or 503.

Automated tests should assert the exact code, not just "not 500". For example, a login test should expect 200 on success and 401 on failure. A test that only checks for 200 will not catch a redirect that sends the user to the wrong page.

Common Problems and Misconceptions

One common mistake is treating 404 as the only "not found" code. In REST APIs, 404 can also mean the endpoint is wrong, while 405 Method Not Allowed means the URL is correct but the HTTP method (GET, POST, etc.) is not supported. Another misconception is that 401 and 403 are interchangeable: 401 means "you are not authenticated" (who are you?), while 403 means "you are authenticated but not allowed" (what can you do?).

Another issue is that some frameworks return 200 for errors by embedding an error object in the response body. This is a design choice, but it makes status code testing less reliable. If your API does this, you need to test the body content as well.

Also, be aware that proxies and CDNs can modify status codes. A 200 from a cache might be stale, and a 504 from a gateway might hide the real error from the origin server. In testing, use tools that show the full response chain.

Comparing Status Codes Across HTTP Versions

HTTP/1.1 and HTTP/2 use the same status codes, but HTTP/3 (QUIC) also uses the same codes. However, the way errors are reported can differ: HTTP/2 and HTTP/3 have a RST_STREAM frame that can carry an error code, but the HTTP status code is still the primary signal. For testing, this means you should not need to change your assertions based on the HTTP version, but you should be aware that some network-level errors (like connection reset) do not have a status code at all.

There is also a difference between "soft" 404s (a page returns 200 but displays a "not found" message) and real 404s. Search engines treat soft 404s differently, and they can harm SEO. Testing should catch soft 404s by checking the body content.

Practical Testing Tools and Techniques

You can test status codes with simple command-line tools like curl or with full-featured API testing platforms. Here is a basic curl example:

curl -I https://example.com/page

The -I flag sends a HEAD request and prints the status code. To see the body as well, use curl -i. For more complex scenarios, you can use browser developer tools: open the Network tab, reload a page, and click on any request to see its status code, headers, and response body.

Automated tests can be written in any programming language. In JavaScript with fetch, you can check response.status. In Python with requests, response.status_code. The key is to assert the expected value and fail the test if it differs.

Frequently Asked Questions

What is the difference between 401 and 403?

401 Unauthorized means the request lacks valid authentication credentials (you are not logged in or your token is invalid). 403 Forbidden means the server understood your credentials but you do not have permission to access the resource (you are logged in but not an admin). In practice, some APIs use 401 for both, but the spec distinguishes them.

Should I test for 200 or 201 after a POST request?

It depends on the API design. If the POST creates a new resource, the correct response is 201 Created, often with a Location header pointing to the new resource. If the POST is just an action (like login), 200 is fine. Test for the code the API documentation specifies.

Why am I getting a 304 Not Modified in my tests?

304 Not Modified is a caching response. It means the resource has not changed since your last request, and the server is telling you to use your cached copy. This is normal and efficient. In tests, you should verify that the response includes the correct ETag or Last-Modified headers and that the body is empty.

Can a 500 error be caused by the client?

Generally, no. A 500 Internal Server Error means the server encountered an unexpected condition. However, a malformed request can sometimes trigger a bug in the server code, resulting in a 500. So while the client did not cause the error directly, the client's input exposed a server-side bug. In testing, always report the request that caused the 500.

What is a soft 404 and why does it matter?

A soft 404 is when a server returns a 200 OK status but the page content says "Page Not Found". This is bad for SEO because search engines will index a useless page. In testing, you should check that truly missing pages return a 404 status, not just a 200 with an error message.

How do I test for rate limiting (429)?

To test 429 Too Many Requests, you need to send more requests than the server allows within a time window. This may require a test account or a special header to bypass rate limits in a test environment. Check the Retry-After header in the response to see how long to wait before retrying.