Skip to content

Commit

Permalink
added http status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
aceat64 committed Jul 13, 2023
1 parent a36e2e2 commit d7b1e53
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: sudo apt-get install pngquant

# The .cache directory is used for 3rd party assets, as part of the privacy plugin.
# It is also used to cache the generated social media cards.
# Persisting the cache across builds dramatically speeds up the process.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is my personal website, so all opinions are my own. I made it to better doc

Note: Since I use the Insiders version of Material for MkDocs, you will not able to run this locally unless you are also a sponsor of the project.

Requires [Poetry](https://python-poetry.org/), Python 3.10 or higher and a GitHub personal access token (`$GH_TOKEN`). I recommend using `pyenv` to install Python.
Requires [Poetry](https://python-poetry.org/), Python 3.11 or higher and a GitHub personal access token (`$GH_TOKEN`). I recommend using `pyenv` to install Python.

### Configure access to Insiders

Expand All @@ -29,7 +29,7 @@ poetry run mkdocs build

## Copyright

Copyright (c) 2022 Andrew LeCody
Copyright (c) 2023 Andrew LeCody

This work is licensed under a Creative Commons Attribution 4.0 International License.

Expand Down
178 changes: 178 additions & 0 deletions content/guides/http-status-codes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
---
status: new
description: A comical explanation of various HTTP status codes.
---

# HTTP Status Codes

Every HTTP response has a status code, which is a 3 digit number and sometimes actually conveys useful information about the status of the request. The first digit of the status code tells us the type of response. Often when talking about an entire type of status code people will replace the last two digits with `xx`, such as `5xx`. I like to do this when I don't actually care about the specific code or have forgotten what it was.

!!! info

Mozilla has a number of articles that explain HTTP response codes "properly".
You can find the full list of status codes here: <https://developer.mozilla.org/en-US/docs/Web/HTTP/Status>

The list here is not complete, it is the status codes I see on a regular basis or that I find interesting. Anything not on my list is likely not used very often. This page assumes you already have a basic understanding of what an HTTP request is and how it looks.

## 1xx - Informational

These are the least used status codes. In practice, you'll probably never see these so I won't cover them here.

## 2xx - Success

Congratulations! Your request worked, *probably*. Some applications will give you a `2xx` status code, and then in the body of the response have an error message. I've often seen this as json with something like this:

``` json
{
"success": false,
"message": "Hah, I bet you thought your request worked. Sucker."
}
```

If you encounter an API with this behavior, you have a moral obligation to shame the developer.

### 200 - OK

Your request succeeded, also maybe here's what you requested.

### 201 - Created

You probably sent a `POST` or `PUT`, and something got created.

### 202 - Accepted

The server got your request and might do something with it later.

### 203 - Non-Authoritative Information

I think maybe some CDNs use this, it's weird and you should probably avoid it if you are designing an API.

### 204 - No Content

Like a 200, but there's nothing in the body. If there is something in the body, you should scold the developer.

## 3xx - Redirection

The thing you wanted isn't here.

### 300 - Multiple Choices

The thing you wanted is in more than one place, maybe. There's no standardized way of telling you what your choices are, only that there are multiple choices available.

### 301 - Moved Permanently

That thing you wanted is now at this new URL, check the `Location` header for where to go. Also don't bother asking again, the answer won't change.

### 302 - Found

Just like a 301, except temporary. You should probably ask again in the future, because the answer may change. Why isn't this called "Moved Temporarily"? Because that would be too easy.

### 303 - See Other

The server isn't sending you to the thing you requested, but it is sending you to another URL where you can `GET` it. Which is... kind of like a `301`/`302` I guess? But different, because we use this one when your request was a `POST` or `PUT`.

### 304 - Not Modified

You aren't getting the thing you wanted, because it hasn't changed since you last requested it. This is "redirecting" you to your own cache of the resource.

### 307 - Temporary Redirect

Wait, haven't we seen this one already? Yes, but no. A `302` is a response to a `GET` request, while a `307` is a redirection response to a `POST` or `PUT`. In this case the server is telling you to `POST`/`PUT` that same request, but at this other URL ([Tell him exactly what you told me](https://www.youtube.com/watch?v=fN-VAdAnoZ4)). Also, the URL might change next time you make this request.

### 308 - Permanent Redirect

Exactly like a `307`, but permanent.

## 4xx - Client Error

When you (the client) did something wrong, the server will typically return a `4xx` status.

### 400 - Bad Request

Your request was bad. If you're lucky the body might tell you *why* it was bad.

### 401 - Unauthorized

This actually means *unauthenticated*, as in you didn't give the server any information about who you are.

### 403 - Forbidden

You are *unauthorized*. The server knows who you are, you just aren't allowed in. Yeah, this isn't confusing at all.

<!-- ### 404 - Not Found -->

### 405 - Method Not Allowed

You used the wrong verb. Maybe you sent a `POST` but the server wanted a `PUT`, communication is hard.

### 406 - Not Acceptable

Your request probably had an `Accept` header, but whatever `Content-Types` you listed are not ones the server finds acceptable. This is almost never used, because the reasonable thing for the server to do is just send you a response in some default `Content-Type`.

### 407 - Proxy Authentication Required

I've never seen this one before, but it's just a fancier `401`. At least they called it authentication this time.

### 408 - Request Timeout

You held the connection open so long without doing anything that the server got tired of you. What about when the server takes too long to respond and the connection times out? You don't get a status code, because you didn't get a response! Duh.

### 409 - Conflict

Usually you'll see this in response to a `POST` or `PUT`. It's a useful way for the server to tell you "that thing already exists".

### 410 - Gone

Like a `404`, but the server acknowledges that the thing you wanted used to be there and is now gone forever. Very sad.

### 411 - Length Required

You forgot to put a `Content-Length` header in your request. No, I'm not going to make that joke. Grow up.

### 412 - Precondition Failed

Pretty rare, sometimes used for caching.

### 413 - Payload Too Large

The data you sent, probably via `POST` or `PUT`, was too big for the server to handle. Ok, yes, I see how that sounds.

### 414 - URI Too Long

You requested a URI that was so long the server gave up on trying to read it. That's actually kind of impressive, good job.

### 415 - Unsupported Media Type

When the site said no `.zip` files, they meant it.

### 418 - I'm a teapot

Yes, this is an [official status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/418). It's got an [RFC](https://www.rfc-editor.org/rfc/rfc2324#section-2.3.2) and everything.

### 429 - Too Many Requests

Slow down, you hit a rate limit.

### 451 - Unavailable For Legal Reasons

You get it? Because in the book Fahrenheit 451 they burned books. It's *very* clever and funny, unlike `418`.

## 5xx - Server Error

Sometimes you can do everything right and still lose, such as when the server runs into a problem that's (probably) not your fault.

### 500 - Internal Server Error

Something went wrong on the server side. Typically this will provide you with no additional details. This is done for security reasons, because detailed error messages could leak potentially sensitive information about what is going on behind the scenes.

### 502 - Bad Gateway

Your request went through a reverse proxy (load balancer) and the proxy got a bad or invalid response from the server.

### 503 - Service Unavailable

The most common reason for this is that the reverse proxy (load balancer) is up, but it has no upstream servers available.

### 504 - Gateway Timeout

Your request went through a reverse proxy (load balancer) and the proxy sent it to an upstream server, but the connection timed out. This can happen if the request is taking a long time to process but the proxy has a shorter timeout setting than the upstream server does.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
status: new
description: Guide to deploy a static site using Material for MkDocs Insiders on GitHub Pages using Poetry and GitHub Actions
hide:
- toc
Expand Down
2 changes: 1 addition & 1 deletion content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ This is my personal website, so all opinions are my own. I made it to better doc

## Who Am I

Hi, I'm Andrew LeCody. I am a maker, nerd, and a bunch of other labels that all boil down to: I like to learn and to build stuff. Professionally I am a Senior DevOps Engineer with experience at every layer, all the way down to hardware since I started my career working in datacenters. Outside of work I'm either learning, making stuff, playing video games, or camping/hiking/offroading. I helped start the [Dallas Makerspace](https://dallasmakerspace.org), serving on the Board of Directors and as President for the first 5 years of the organization.
Hi, I'm Andrew LeCody. I am a maker, nerd, and a bunch of other labels that all boil down to: I like to learn and to build stuff. Professionally I am a Staff DevOps Engineer with experience at every layer, all the way down to hardware since I started my career working in datacenters. Outside of work I'm either learning, making stuff, playing video games, or camping/hiking/offroading. I helped start the [Dallas Makerspace](https://dallasmakerspace.org), serving on the Board of Directors and as President for the first 5 years of the organization.

I believe strongly in the power of collaboration, protection of human rights, and taking care of our environment.

Expand Down
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ nav:
- guides/nginx-proxy-manager-udmp.md
- guides/rpi-k8s-talos-terraform.md
- guides/mkdocs-material-insider-github-pages-action.md
- guides/http-status-codes.md
- Smart Home:
- smart-home/architecture.md
- smart-home/garage-door.md
Expand All @@ -33,6 +34,7 @@ plugins:
- blog
- search
- social
- optimize
- minify:
minify_html: true
- privacy
Expand Down
14 changes: 14 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mkdocs-material = {git = "https://github.com/squidfunk/mkdocs-material-insiders.
mkdocs-minify-plugin = "^0.6.4"
Pillow = "^10.0.0"
CairoSVG = "^2.7.0"
pngquant = "^1.0.7"


[build-system]
Expand Down

0 comments on commit d7b1e53

Please sign in to comment.