├── .editorconfig ├── .github ├── dependabot.yml └── workflows │ ├── automerge.yml │ ├── lint.yml │ ├── release.yml │ └── test.yml ├── .gitignore ├── .golangci.yml ├── .goreleaser.yml ├── LICENSE ├── Makefile ├── README.md ├── cmd └── httpurr │ └── main.go ├── go.mod ├── httpurr.rb └── src ├── cli.go ├── cli_test.go ├── data.go └── data_test.go /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # 4 space indentation 12 | [*.go, *.md] 13 | indent_style = space 14 | indent_size = 4 15 | 16 | # Tab indentation 17 | [Makefile] 18 | indent_style = tab 19 | indent_size = 4 20 | 21 | # Matches the exact files either package.json or .travis.yml 22 | [{*.json,*.yml}] 23 | indent_style = space 24 | indent_size = 2 25 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: gomod 4 | directory: / 5 | schedule: 6 | interval: weekly 7 | 8 | - package-ecosystem: "github-actions" 9 | directory: "/" 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /.github/workflows/automerge.yml: -------------------------------------------------------------------------------- 1 | name: Dependabot auto-merge 2 | 3 | on: pull_request 4 | 5 | permissions: 6 | contents: write 7 | 8 | jobs: 9 | dependabot: 10 | runs-on: ubuntu-latest 11 | if: ${{ github.actor == 'dependabot[bot]' }} 12 | steps: 13 | - name: Enable auto-merge for Dependabot PRs 14 | run: gh pr merge --auto --merge "$PR_URL" 15 | env: 16 | PR_URL: ${{github.event.pull_request.html_url}} 17 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 18 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: golangci-lint 2 | 3 | on: 4 | pull_request: 5 | push: 6 | 7 | permissions: 8 | contents: read 9 | 10 | 11 | jobs: 12 | golangci: 13 | name: lint 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/setup-go@v5 17 | with: 18 | go-version: "1.21" 19 | cache: true 20 | 21 | - uses: actions/checkout@v4 22 | with: 23 | fetch-depth: 0 24 | 25 | - name: golangci-lint 26 | uses: golangci/golangci-lint-action@v8 27 | with: 28 | version: v1.54 29 | args: --verbose --timeout 10m --fix=false --new-from-rev=HEAD~ --config=.golangci.yml 30 | 31 | - name: check-is-dirty 32 | run: | 33 | if [[ -n $(git status --porcelain) ]]; then 34 | echo "Detected uncommitted changes." 35 | git status 36 | git diff 37 | exit 1 38 | fi 39 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: goreleaser 2 | 3 | on: 4 | release: 5 | types: [released, prereleased] 6 | 7 | permissions: 8 | contents: write 9 | 10 | jobs: 11 | goreleaser: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v4 16 | with: 17 | fetch-depth: 0 18 | 19 | - name: Set up Go 20 | uses: actions/setup-go@v5 21 | with: 22 | go-version: "1.21" 23 | cache: true 24 | 25 | - name: Run GoReleaser 26 | uses: goreleaser/goreleaser-action@v6 27 | with: 28 | distribution: goreleaser 29 | version: latest 30 | args: release --clean 31 | env: 32 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 33 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | on: 3 | push: 4 | pull_request: 5 | 6 | permissions: 7 | contents: read 8 | # Optional: allow read access to pull request. Use with `only-new-issues` option. 9 | # pull-requests: read 10 | 11 | jobs: 12 | test: 13 | strategy: 14 | matrix: 15 | os: [ubuntu-latest, macos-latest] 16 | runs-on: ${{ matrix.os }} 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - uses: actions/setup-go@v5 21 | with: 22 | go-version: "1.21" 23 | cache: true 24 | 25 | - name: Install dependencies 26 | run: go mod download 27 | 28 | - name: Run tests 29 | run: go test -v ./... 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # If you prefer the allow list template instead of the deny list, see community template: 2 | # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore 3 | # 4 | 5 | ./http-purr 6 | 7 | # Binaries for programs and plugins 8 | *.exe 9 | *.exe~ 10 | *.dll 11 | *.so 12 | *.dylib 13 | 14 | # Test binary, built with `go test -c` 15 | *.test 16 | 17 | # Output of the go coverage tool, specifically when used with LiteIDE 18 | *.out 19 | 20 | # Dependency directories (remove the comment below to include it) 21 | # vendor/ 22 | 23 | # Go workspace file 24 | go.work 25 | 26 | dist/ 27 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | linters: 2 | enable: 3 | - gofmt 4 | - nolintlint 5 | 6 | issues: 7 | max-issues-per-linter: 0 8 | max-same-issues: 0 9 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | # This is an example .goreleaser.yml file with some sensible defaults. 2 | # Make sure to check the documentation at https://goreleaser.com 3 | builds: 4 | - env: 5 | - CGO_ENABLED=0 6 | goos: 7 | - linux 8 | - windows 9 | - darwin 10 | goarch: 11 | - amd64 12 | - arm64 13 | - "386" 14 | main: ./cmd/httpurr 15 | 16 | archives: 17 | - format: tar.gz 18 | # this name template makes the OS and Arch compatible with the results of uname. 19 | name_template: >- 20 | {{ .ProjectName }}_ 21 | {{- title .Os }}_ 22 | {{- if eq .Arch "amd64" }}x86_64 23 | {{- else if eq .Arch "386" }}i386 24 | {{- else }}{{ .Arch }}{{ end }} 25 | {{- if .Arm }}v{{ .Arm }}_{{ .Version }}{{ end }} 26 | # use zip for windows archives 27 | format_overrides: 28 | - goos: windows 29 | format: zip 30 | 31 | checksum: 32 | name_template: 'checksums.txt' 33 | 34 | snapshot: 35 | name_template: "{{ incpatch .Version }}-next" 36 | 37 | changelog: 38 | sort: asc 39 | filters: 40 | exclude: 41 | - '^docs:' 42 | - '^test:' 43 | 44 | brews: 45 | - name: httpurr 46 | homepage: "https://github.com/rednafi/httpurr" 47 | description: HTTP status codes on speed dial 48 | repository: 49 | owner: rednafi 50 | name: httpurr 51 | commit_author: 52 | name: rednafi 53 | email: redowan.nafi@gmail.com 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [2023] [Redowan Delowar] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: lint 2 | lint: 3 | @echo "Running lint" 4 | @golangci-lint run --fix 5 | @go mod tidy 6 | 7 | 8 | .PHONY: lint-check 9 | lint-check: 10 | @echo "Checking lint" 11 | @golangci-lint run 12 | 13 | 14 | .PHONY: test 15 | test: 16 | @echo "Running tests" 17 | @go test -v ./... 18 | 19 | 20 | .PHONY: clean 21 | clean: 22 | @echo "Cleaning up" 23 | @go clean 24 | @rm -rf ./bin 25 | 26 | 27 | .PHONY: init 28 | init: 29 | @echo "Initializing project" 30 | @go mod download 31 | @go mod tidy 32 | @go test -v ./... 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

ᗢ httpurr

3 | >> HTTP status codes on speed dial << 4 |
5 |
6 | 7 | --- 8 | 9 | ![img][cover-img] 10 | 11 | ## Installation 12 | 13 | * On MacOS, brew install: 14 | 15 | ```sh 16 | brew tap rednafi/httpurr https://github.com/rednafi/httpurr \ 17 | && brew install httpurr 18 | ``` 19 | 20 | * Or elsewhere, go install: 21 | 22 | ```sh 23 | go install github.com/rednafi/httpurr/cmd/httpurr 24 | ``` 25 | 26 | * Else, download the appropriate [binary] for your CPU arch and add it to the `$PATH`. 27 | 28 | ## Quickstart 29 | 30 | * List the HTTP status codes: 31 | 32 | ```sh 33 | httpurr --list 34 | ``` 35 | 36 | ```txt 37 | ᗢ httpurr 38 | ========== 39 | 40 | Status Codes 41 | ------------ 42 | 43 | ------------------ 1xx ------------------ 44 | 45 | 100 Continue 46 | 101 Switching Protocols 47 | 102 Processing 48 | 103 Early Hints 49 | 50 | ------------------ 2xx ------------------ 51 | ... 52 | ``` 53 | 54 | * Filter the status codes by categories: 55 | 56 | ```sh 57 | httpurr --list --cat 2 58 | ``` 59 | 60 | ```txt 61 | ᗢ httpurr 62 | ========== 63 | 64 | Status Codes 65 | ------------ 66 | 67 | ------------------ 2xx ------------------ 68 | 69 | 200 OK 70 | 201 Created 71 | 202 Accepted 72 | 203 Non-Authoritative Information 73 | 204 No Content 74 | 205 Reset Content 75 | 206 Partial Content 76 | 207 Multi-Status 77 | 208 Already Reported 78 | 226 IM Used 79 | ``` 80 | 81 | * Display the description of a status code: 82 | 83 | ```sh 84 | httpurr --code 410 85 | ``` 86 | 87 | ```txt 88 | ᗢ httpurr 89 | ========== 90 | 91 | Description 92 | ----------- 93 | 94 | The HyperText Transfer Protocol (HTTP) 410 Gone client error response code 95 | indicates that access to the target resource is no longer available at the 96 | origin server and that this condition is likely to be permanent. 97 | 98 | If you don't know whether this condition is temporary or permanent, a 404 status 99 | code should be used instead. 100 | 101 | Status 102 | ------ 103 | 104 | 410 Gone 105 | 106 | Source 107 | ------ 108 | 109 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/410 110 | ``` 111 | * See all available options: 112 | 113 | ```sh 114 | httpurr --help 115 | ``` 116 | 117 | ```txt 118 | ᗢ httpurr 119 | ========== 120 | 121 | Usage of httpurr: 122 | --cat [category] 123 | Print HTTP status codes by category with --list; 124 | allowed categories are 1, 2, 3, 4, 5 125 | -c, --code [status code] 126 | Print the description of an HTTP status code 127 | -h, --help 128 | Print usage 129 | -l, --list 130 | Print HTTP status codes 131 | -v, --version 132 | Print version 133 | ``` 134 | 135 | ## Development 136 | 137 | * Clone the repo. 138 | * Go to the root directory and run: 139 | ```sh 140 | make init 141 | ``` 142 | * Run the linter: 143 | ```sh 144 | make lint 145 | ``` 146 | * Run the tests: 147 | ```sh 148 | make test 149 | ``` 150 | * To publish a new version, create a new [release] with a [tag], and the [CI] will take care 151 | of the rest. 152 | 153 | [cover-img]: https://github.com/rednafi/httpurr/assets/30027932/e7e8051b-ce83-4a2a-afd9-d6cba33cadac 154 | [binary]: https://github.com/rednafi/httpurr/releases/latest 155 | [tag]: https://github.com/rednafi/httpurr/tags 156 | [release]: https://github.com/rednafi/httpurr/releases/new 157 | [CI]: ./.github/workflows/release.yml 158 | -------------------------------------------------------------------------------- /cmd/httpurr/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/rednafi/httpurr/src" 5 | "os" 6 | "text/tabwriter" 7 | ) 8 | 9 | // Ldflags filled by goreleaser 10 | var version string 11 | 12 | func main() { 13 | w := tabwriter.NewWriter(os.Stdout, 0, 4, 4, ' ', 0) 14 | src.Cli(w, version, os.Exit) 15 | } 16 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/rednafi/httpurr 2 | 3 | go 1.21.0 4 | -------------------------------------------------------------------------------- /httpurr.rb: -------------------------------------------------------------------------------- 1 | # typed: false 2 | # frozen_string_literal: true 3 | 4 | # This file was generated by GoReleaser. DO NOT EDIT. 5 | class Httpurr < Formula 6 | desc "HTTP status codes on speed dial" 7 | homepage "https://github.com/rednafi/httpurr" 8 | version "0.1.1" 9 | 10 | on_macos do 11 | if Hardware::CPU.intel? 12 | url "https://github.com/rednafi/httpurr/releases/download/v0.1.1/httpurr_Darwin_x86_64.tar.gz" 13 | sha256 "b03f1b13a851e08b8742ab5fcfd500fcd850e605c38695a7e8ae125dfe212575" 14 | 15 | def install 16 | bin.install "httpurr" 17 | end 18 | end 19 | if Hardware::CPU.arm? 20 | url "https://github.com/rednafi/httpurr/releases/download/v0.1.1/httpurr_Darwin_arm64.tar.gz" 21 | sha256 "82acefd1222f6228636f2cda6518e0316f46624398adc722defb55c68ac3bb30" 22 | 23 | def install 24 | bin.install "httpurr" 25 | end 26 | end 27 | end 28 | 29 | on_linux do 30 | if Hardware::CPU.arm? && Hardware::CPU.is_64_bit? 31 | url "https://github.com/rednafi/httpurr/releases/download/v0.1.1/httpurr_Linux_arm64.tar.gz" 32 | sha256 "ad95e8a68b7c48ddbe2a19f7a45d91d954058748ddb47411e3e6efa57dfc8432" 33 | 34 | def install 35 | bin.install "httpurr" 36 | end 37 | end 38 | if Hardware::CPU.intel? 39 | url "https://github.com/rednafi/httpurr/releases/download/v0.1.1/httpurr_Linux_x86_64.tar.gz" 40 | sha256 "2bee752e7c93e8d0ff7564d6b39cf7780efdb07cfd395cc9c054a5148133c72c" 41 | 42 | def install 43 | bin.install "httpurr" 44 | end 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /src/cli.go: -------------------------------------------------------------------------------- 1 | package src 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "net/http" 7 | "os" 8 | "slices" 9 | "strconv" 10 | "strings" 11 | 12 | "text/tabwriter" 13 | ) 14 | 15 | // Trim prefix and suffix newlines from the http status text 16 | func formatStatusText(text string) string { 17 | return strings.TrimSuffix(strings.TrimPrefix(text, "\n"), "\n") 18 | } 19 | 20 | // Always print the header 21 | func printHeader(w *tabwriter.Writer) { 22 | defer w.Flush() 23 | 24 | fmt.Fprintf(w, "\nᗢ httpurr\n") 25 | fmt.Fprintf(w, "==========\n\n") 26 | } 27 | 28 | // Print all the status codes in a tabular format 29 | // 30 | // w: the tabwriter to print to 31 | // 32 | // category: the status code category to print, empty prints all 33 | // 34 | // returns: any error encountered 35 | func printStatusCodes(w *tabwriter.Writer, category string) error { 36 | defer w.Flush() 37 | 38 | fmt.Fprintf(w, "Status Codes\n") 39 | fmt.Fprintf(w, "------------\n\n") 40 | 41 | statusCodesSubset := statusCodes 42 | 43 | // Category header index 44 | if category != "" { 45 | catStart := slices.Index( 46 | statusCodes, 47 | fmt.Sprintf("------------------ %sxx ------------------", category), 48 | ) 49 | 50 | catInt, _ := strconv.Atoi(category) 51 | catStr := strconv.Itoa(catInt + 1) 52 | 53 | catEnd := slices.Index( 54 | statusCodes, 55 | fmt.Sprintf("------------------ %sxx ------------------", catStr), 56 | ) 57 | 58 | if catStart == -1 { 59 | return fmt.Errorf( 60 | "error: invalid category %s; allowed categories are 1, 2, 3, 4, 5", 61 | category, 62 | ) 63 | } 64 | if catEnd == -1 { 65 | catEnd = len(statusCodes) 66 | } 67 | 68 | statusCodesSubset = statusCodes[catStart:catEnd] 69 | } 70 | 71 | // Print category headers, e.g. '---- 1xx ----' 72 | for idx, code := range statusCodesSubset { 73 | if idx == 0 && strings.HasPrefix(code, "-") { 74 | fmt.Fprintf(w, "%s%s\n", code, "\n") 75 | continue 76 | } 77 | 78 | // Print a newline before and after the category header 79 | if idx != 0 && strings.HasPrefix(code, "-") { 80 | fmt.Fprintf(w, "\n%s%s\n", code, "\n") 81 | continue 82 | } 83 | 84 | // Print status text 85 | codeInt, _ := strconv.Atoi(code) 86 | statusText := http.StatusText(codeInt) 87 | 88 | // Print '-' when the status text is not available 89 | if statusText == "" { 90 | fmt.Fprintf(w, "%s\t%s\n", code, "-") 91 | continue 92 | } 93 | fmt.Fprintf(w, "%s\t%s\n", code, statusText) 94 | } 95 | return nil 96 | } 97 | 98 | // Print the status text for a given status code 99 | // 100 | // w: the tabwriter to print to 101 | // 102 | // code: the status code to lookup 103 | // 104 | // returns: any error encountered 105 | func printStatusText(w *tabwriter.Writer, code string) error { 106 | defer w.Flush() 107 | 108 | statusText, ok := statusCodeMap[code] 109 | if !ok { 110 | return fmt.Errorf("error: invalid status code %s", code) 111 | } 112 | fmt.Fprintln(w, formatStatusText(statusText)) 113 | return nil 114 | } 115 | 116 | // Assemble 117 | // 118 | // w: the tabwriter to print to 119 | // 120 | // version: the version string 121 | // 122 | // exitFunc: the function to call to exit 123 | func Cli(w *tabwriter.Writer, version string, exitFunc func(int)) { 124 | // Flush the writer at the end of the function 125 | defer w.Flush() 126 | 127 | fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) 128 | flag.CommandLine = fs 129 | 130 | // Set the default output to the passed tabwriter 131 | fs.SetOutput(w) 132 | 133 | // Define the flags 134 | code := flag.String("code", "", "Print the description of an HTTP status code") 135 | flag.StringVar(code, "c", "", "Print the description of an HTTP status code") 136 | 137 | help := flag.Bool("help", false, "Print usage") 138 | flag.BoolVar(help, "h", false, "Print usage") 139 | 140 | vers := flag.Bool("version", false, "Print version") 141 | flag.BoolVar(vers, "v", false, "Print version") 142 | 143 | list := flag.Bool("list", false, "Print HTTP status codes") 144 | flag.BoolVar(list, "l", false, "Print HTTP status codes") 145 | 146 | cat := flag.String("cat", "", 147 | "Print HTTP status codes by category with --list; \n"+ 148 | "allowed categories are 1, 2, 3, 4, 5", 149 | ) 150 | 151 | // Override the default usage to print the custom usage message 152 | flag.Usage = func() { 153 | fmt.Fprintf(w, "Usage of %s:\n", os.Args[0]) 154 | fmt.Fprint(w, ` --cat [category] 155 | Print HTTP status codes by category with --list; 156 | allowed categories are 1, 2, 3, 4, 5 157 | -c, --code [status code] 158 | Print the description of an HTTP status code 159 | -h, --help 160 | Print usage 161 | -l, --list 162 | Print HTTP status codes 163 | -v, --version 164 | Print version 165 | `) 166 | } 167 | 168 | // Print the header 169 | printHeader(w) 170 | 171 | // Override the default usage to flush the tabwriter 172 | flagUsageOld := flag.Usage 173 | fs.Usage = func() { 174 | flagUsageOld() 175 | w.Flush() 176 | } 177 | 178 | err := fs.Parse(os.Args[1:]) 179 | if err != nil { 180 | exitFunc(2) 181 | } 182 | 183 | // If no arguments are provided, print the help message 184 | if len(os.Args) < 2 || *help { 185 | flag.Usage() 186 | return 187 | } 188 | 189 | // If the version flag is provided, print the version 190 | if *vers { 191 | fmt.Fprintln(w, version) 192 | return 193 | } 194 | 195 | if *cat != "" && !*list { 196 | fmt.Fprintln(w, "error: cannot use --cat without --list") 197 | exitFunc(2) 198 | } 199 | 200 | // Cat must be provided with the list flag but cat is optional 201 | if *list { 202 | err := printStatusCodes(w, *cat) 203 | if err != nil { 204 | fmt.Fprintf(w, "%s\n", err) 205 | exitFunc(1) 206 | } 207 | return 208 | } 209 | 210 | // If the code flag is provided, print the status text 211 | if *code != "" { 212 | err := printStatusText(w, *code) 213 | if err != nil { 214 | fmt.Fprintf(w, "%s\n", err) 215 | exitFunc(1) 216 | } 217 | return 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /src/cli_test.go: -------------------------------------------------------------------------------- 1 | package src 2 | 3 | import ( 4 | "bytes" 5 | "flag" 6 | "os" 7 | "strings" 8 | "testing" 9 | 10 | "text/tabwriter" 11 | ) 12 | 13 | // ================== Cli helper tests start ================== 14 | 15 | func TestFormatStatusText(t *testing.T) { 16 | 17 | // Test trimming newlines from start 18 | in := "\nHello" 19 | want := "Hello" 20 | 21 | out := formatStatusText(in) 22 | if out != want { 23 | t.Errorf("formatStatusText(%q) = %q, want %q", in, out, want) 24 | } 25 | 26 | // Test trimming newlines from end 27 | in = "Hello\n" 28 | want = "Hello" 29 | 30 | out = formatStatusText(in) 31 | if out != want { 32 | t.Errorf("formatStatusText(%q) = %q, want %q", in, out, want) 33 | } 34 | 35 | // Test trimming newlines from both ends 36 | in = "\nHello\n" 37 | want = "Hello" 38 | 39 | out = formatStatusText(in) 40 | if out != want { 41 | t.Errorf("formatStatusText(%q) = %q, want %q", in, out, want) 42 | } 43 | 44 | // Test with no surrounding whitespaces 45 | in = "Hello" 46 | want = "Hello" 47 | 48 | out = formatStatusText(in) 49 | if out != want { 50 | t.Errorf("formatStatusText(%q) = %q, want %q", in, out, want) 51 | } 52 | } 53 | 54 | func TestPrintHeader(t *testing.T) { 55 | // Create a tabwriter with a buffer 56 | var buf bytes.Buffer 57 | w := tabwriter.NewWriter(&buf, 0, 4, 4, ' ', 0) 58 | 59 | // Call function 60 | printHeader(w) 61 | 62 | // Check output 63 | got := buf.String() 64 | want := "\nᗢ httpurr\n==========\n\n" 65 | 66 | if got != want { 67 | t.Errorf("printHeader() = %q, want %q", got, want) 68 | } 69 | } 70 | 71 | func TestPrintStatusCodes(t *testing.T) { 72 | // Create a tabwriter with a buffer 73 | var buf bytes.Buffer 74 | w := tabwriter.NewWriter(&buf, 0, 4, 4, ' ', 0) 75 | 76 | // Call function 77 | _ = printStatusCodes(w, "") 78 | 79 | // Check output 80 | got := buf.String() 81 | 82 | // Check for the first line 83 | want := "Status Codes\n------------\n\n" 84 | 85 | // Check want is in got 86 | if strings.Contains(got, want) == false { 87 | t.Errorf("printStatusCodes() = %q, want %q", got, want) 88 | } 89 | 90 | // Spot check a few lines 91 | wantLines := []string{ 92 | "100 Continue", 93 | "101 Switching Protocols", 94 | "102 Processing", 95 | "103 Early Hints", 96 | "200 OK", 97 | "201 Created", 98 | "202 Accepted", 99 | "203 Non-Authoritative Information", 100 | "204 No Content", 101 | "205 Reset Content", 102 | "206 Partial Content", 103 | "207 Multi-Status", 104 | "208 Already Reported", 105 | "226 IM Used", 106 | "300 Multiple Choices", 107 | "301 Moved Permanently", 108 | "302 Found", 109 | "303 See Other", 110 | "304 Not Modified", 111 | "305 Use Proxy", 112 | "-", 113 | "307 Temporary Redirect", 114 | "308 Permanent Redirect", 115 | "400 Bad Request", 116 | "401 Unauthorized", 117 | "402 Payment Required", 118 | "403 Forbidden", 119 | "404 Not Found", 120 | "405 Method Not Allowed", 121 | "406 Not Acceptable", 122 | "407 Proxy Authentication Required", 123 | "408 Request Timeout", 124 | "409 Conflict", 125 | "410 Gone", 126 | "411 Length Required", 127 | "412 Precondition Failed", 128 | "413 Request Entity Too Large", 129 | "414 Request URI Too Long", 130 | "415 Unsupported Media Type", 131 | "416 Requested Range Not Satisfiable", 132 | "417 Expectation Failed", 133 | "418 I'm a teapot", 134 | "421 Misdirected Request", 135 | "422 Unprocessable Entity", 136 | "423 Locked", 137 | "424 Failed Dependency", 138 | "425 Too Early", 139 | "426 Upgrade Required", 140 | "428 Precondition Required", 141 | "429 Too Many Requests", 142 | "431 Request Header Fields Too Large", 143 | "451 Unavailable For Legal Reasons", 144 | "500 Internal Server Error", 145 | "501 Not Implemented", 146 | "502 Bad Gateway", 147 | "503 Service Unavailable", 148 | "504 Gateway Timeout", 149 | "505 HTTP Version Not Supported", 150 | "506 Variant Also Negotiates", 151 | "507 Insufficient Storage", 152 | "508 Loop Detected", 153 | "510 Not Extended", 154 | "511 Network Authentication Required", 155 | } 156 | 157 | for _, want := range wantLines { 158 | 159 | t.Run(want, func(t *testing.T) { 160 | if !strings.Contains(got, want) { 161 | t.Errorf("printStatusCodes() = %q, want %q", got, want) 162 | } 163 | }) 164 | } 165 | 166 | } 167 | 168 | func TestPrintStatusText(t *testing.T) { 169 | // Create a tabwriter with a buffer 170 | var buf bytes.Buffer 171 | w := tabwriter.NewWriter(&buf, 0, 4, 4, ' ', 0) 172 | 173 | code := "100" 174 | _ = printStatusText(w, code) 175 | 176 | wantLines := []string{ 177 | "Description", 178 | "-----------", 179 | "The HTTP 100 Continue informational status response", 180 | "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/100", 181 | } 182 | 183 | got := buf.String() 184 | 185 | for _, want := range wantLines { 186 | if !strings.Contains(got, want) { 187 | t.Errorf("printStatusText(%q) = %q, want %q", code, got, want) 188 | } 189 | } 190 | 191 | } 192 | 193 | // ================== Cli helper tests end ================== 194 | 195 | // ================== Cli tests start ================== 196 | 197 | func TestCliHelp(t *testing.T) { 198 | // Must reset flag.CommandLine to avoid "flag redefined" error 199 | flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) 200 | 201 | var buf bytes.Buffer 202 | w := tabwriter.NewWriter(&buf, 0, 4, 4, ' ', 0) 203 | flag.CommandLine.SetOutput(w) 204 | 205 | // Test -- 206 | os.Args = []string{"cli", "--help"} 207 | 208 | Cli(w, "v1.0", func(int) {}) 209 | 210 | if !strings.Contains(buf.String(), "Usage") { 211 | t.Errorf("Expected help text to be printed") 212 | } 213 | 214 | // Test - 215 | buf.Reset() 216 | os.Args = []string{"cli", "-h"} 217 | 218 | Cli(w, "v1.0", func(int) {}) 219 | 220 | if !strings.Contains(buf.String(), "Usage") { 221 | t.Errorf("Expected help text to be printed") 222 | } 223 | } 224 | 225 | func TestCliVersion(t *testing.T) { 226 | // Must reset flag.CommandLine to avoid "flag redefined" error 227 | flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) 228 | 229 | var buf bytes.Buffer 230 | w := tabwriter.NewWriter(&buf, 0, 4, 4, ' ', 0) 231 | flag.CommandLine.SetOutput(w) 232 | 233 | // Test -- 234 | os.Args = []string{"cli", "--version"} 235 | 236 | Cli(w, "v1.0", func(int) {}) 237 | 238 | if !strings.Contains(buf.String(), "v1.0") { 239 | t.Errorf("Expected version to be printed") 240 | } 241 | 242 | // Test - 243 | buf.Reset() 244 | os.Args = []string{"cli", "-v"} 245 | 246 | Cli(w, "v1.0", func(int) {}) 247 | 248 | if !strings.Contains(buf.String(), "v1.0") { 249 | t.Errorf("Expected version to be printed") 250 | } 251 | } 252 | 253 | func TestCliList(t *testing.T) { 254 | // Must reset flag.CommandLine to avoid "flag redefined" error 255 | flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) 256 | 257 | var buf bytes.Buffer 258 | w := tabwriter.NewWriter(&buf, 0, 4, 4, ' ', 0) 259 | flag.CommandLine.SetOutput(w) 260 | 261 | // Test -- 262 | os.Args = []string{"cli", "--list"} 263 | 264 | Cli(w, "v1.0", func(int) {}) 265 | 266 | if !strings.Contains(buf.String(), "418") { 267 | t.Errorf("Expected status codes to be printed") 268 | } 269 | 270 | // Test - 271 | buf.Reset() 272 | os.Args = []string{"cli", "-l"} 273 | 274 | Cli(w, "v1.0", func(int) {}) 275 | 276 | if !strings.Contains(buf.String(), "418") { 277 | t.Errorf("Expected status codes to be printed") 278 | } 279 | 280 | } 281 | 282 | func TestCliCode(t *testing.T) { 283 | // Must reset flag.CommandLine to avoid "flag redefined" error 284 | flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) 285 | 286 | var buf bytes.Buffer 287 | w := tabwriter.NewWriter(&buf, 0, 4, 4, ' ', 0) 288 | flag.CommandLine.SetOutput(w) 289 | 290 | // Test -- 291 | os.Args = []string{"cli", "-code", "404"} 292 | 293 | Cli(w, "v1.0", func(int) {}) 294 | 295 | if !strings.Contains(buf.String(), "404 Not Found") { 296 | t.Errorf("Expected 404 status text to be printed") 297 | } 298 | 299 | // Test - 300 | buf.Reset() 301 | os.Args = []string{"cli", "-c", "404"} 302 | 303 | Cli(w, "v1.0", func(int) {}) 304 | 305 | if !strings.Contains(buf.String(), "404 Not Found") { 306 | t.Errorf("Expected 404 status text to be printed") 307 | } 308 | } 309 | 310 | func TestCliCat(t *testing.T) { 311 | // Must reset flag.CommandLine to avoid "flag redefined" error 312 | flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) 313 | 314 | var buf bytes.Buffer 315 | w := tabwriter.NewWriter(&buf, 0, 4, 4, ' ', 0) 316 | flag.CommandLine.SetOutput(w) 317 | 318 | os.Args = []string{"cli", "-list", "-cat", "1"} 319 | 320 | Cli(w, "v1.0", func(int) {}) 321 | 322 | wantLines := []string{ 323 | "100 Continue", 324 | "101 Switching Protocols", 325 | "102 Processing", 326 | "103 Early Hints", 327 | } 328 | 329 | for _, want := range wantLines { 330 | if !strings.Contains(buf.String(), want) { 331 | t.Errorf("expected 1xx status codes to be printed; want %q", want) 332 | } 333 | } 334 | } 335 | 336 | func TestCliError(t *testing.T) { 337 | // Must reset flag.CommandLine to avoid "flag redefined" error 338 | flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) 339 | 340 | var buf bytes.Buffer 341 | w := tabwriter.NewWriter(&buf, 0, 4, 4, ' ', 0) 342 | flag.CommandLine.SetOutput(w) 343 | 344 | // Invalid flag 345 | os.Args = []string{"cli", "--invalid"} 346 | Cli(w, "v1.0", func(int) {}) 347 | if !strings.Contains(buf.String(), "flag provided but not defined: -invalid") { 348 | t.Errorf("Expected error message to be printed, got %s\n", buf.String()) 349 | } 350 | 351 | // Missing code 352 | os.Args = []string{"cli", "--code"} 353 | Cli(w, "v1.0", func(int) {}) 354 | if !strings.Contains(buf.String(), "flag needs an argument: -code") { 355 | t.Errorf("Expected error message to be printed, got %s\n", buf.String()) 356 | } 357 | buf.Reset() 358 | 359 | // Invalid code 360 | os.Args = []string{"cli", "--code", "999"} 361 | Cli(w, "v1.0", func(int) {}) 362 | if !strings.Contains(buf.String(), "error: invalid status code 999") { 363 | t.Errorf("Expected error message to be printed, got %s\n", buf.String()) 364 | } 365 | buf.Reset() 366 | 367 | // Using --cat without --list 368 | os.Args = []string{"cli", "--cat", "6"} 369 | Cli(w, "v1.0", func(int) {}) 370 | if !strings.Contains(buf.String(), "error: cannot use --cat without --list") { 371 | t.Errorf("Expected error message to be printed, got %s\n", buf.String()) 372 | } 373 | buf.Reset() 374 | 375 | // Using --cat with --list but invalid category 376 | os.Args = []string{"cli", "--list", "--cat", "6"} 377 | Cli(w, "v1.0", func(int) {}) 378 | 379 | if !strings.Contains(buf.String(), 380 | "error: invalid category 6; allowed categories are 1, 2, 3, 4, 5") { 381 | t.Errorf("Expected error message to be printed, got %s\n", buf.String()) 382 | } 383 | buf.Reset() 384 | 385 | // Using --list after --cat but without category value 386 | os.Args = []string{"cli", "--cat", "-list"} 387 | Cli(w, "v1.0", func(int) {}) 388 | 389 | if !strings.Contains(buf.String(), "error: cannot use --cat without --list") { 390 | t.Errorf("Expected error message to be printed, got %s\n", buf.String()) 391 | } 392 | buf.Reset() 393 | } 394 | 395 | // ================== Cli tests end ================== 396 | -------------------------------------------------------------------------------- /src/data.go: -------------------------------------------------------------------------------- 1 | package src 2 | 3 | const ( 4 | statusContinue100 = ` 5 | Description 6 | ----------- 7 | 8 | The HTTP 100 Continue informational status response code indicates that 9 | everything so far is OK and that the client should continue with the request or 10 | ignore it if it is already finished. 11 | 12 | To have a server check the request's headers, a client must send Expect: 13 | 100-continue as a header in its initial request and receive a 100 Continue 14 | status code in response before sending the body. 15 | 16 | Status 17 | ------ 18 | 19 | 100 Continue 20 | 21 | Source 22 | ------ 23 | 24 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/100 25 | ` 26 | 27 | statusSwitchingProtocols101 = ` 28 | Description 29 | ----------- 30 | 31 | The HTTP 101 Switching Protocols response code indicates a protocol to which the 32 | server switches. The protocol is specified in the Upgrade request header 33 | received from a client. 34 | 35 | The server includes in this response an Upgrade response header to indicate the 36 | protocol it switched to. 37 | 38 | Status 39 | ------ 40 | 41 | 101 Switching Protocols 42 | 43 | Source 44 | ------ 45 | 46 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/101 47 | ` 48 | 49 | statusProcessing102 = ` 50 | Description 51 | ----------- 52 | 53 | Deprecated: This status code is deprecated. When used, clients may still accept 54 | it, but simply ignore them. 55 | 56 | The HTTP 102 Processing informational status response code indicates to client 57 | that a full request has been received and the server is working on it. 58 | 59 | This status code is only sent if the server expects the request to take 60 | significant time. It tells the client that your request is not dead yet. 61 | 62 | Status 63 | ------ 64 | 102 Processing 65 | 66 | Source 67 | ------ 68 | 69 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/102 70 | ` 71 | 72 | statusEarlyHints103 = ` 73 | Description 74 | ----------- 75 | 76 | Experimental: This is an experimental technology. Check the Browser 77 | compatibility table carefully before using this in production. 78 | 79 | The HTTP 103 Early Hints information response may be sent by a server while it 80 | is still preparing a response, with hints about the resources that the server is 81 | expecting the final response will link. 82 | 83 | This allows a browser to start preloading resources even before the server has 84 | prepared and sent that final response. 85 | 86 | The early hint response is primarily intended for use with the Link header, 87 | which indicates the resources to be loaded. 88 | 89 | It may also contain a Content-Security-Policy header that is enforced while 90 | processing the early hint. 91 | 92 | A server might send multiple 103 responses, for example, following a redirect. 93 | Browsers only process the first early hint response, and this response must be 94 | discarded if the request results in a cross-origin redirect. Preloaded resources 95 | from the early hint are effectively pre-pended to the Document's head element, 96 | and then followed by the resources loaded in the final response. 97 | 98 | Status 99 | ------ 100 | 101 | 103 Early Hints 102 | 103 | Source 104 | ------ 105 | 106 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/103 107 | ` 108 | statusOK200 = ` 109 | Description 110 | ----------- 111 | 112 | The HTTP 200 OK success status response code indicates that the request has 113 | succeeded. A 200 response is cacheable by default. 114 | 115 | The meaning of a success depends on the HTTP request method: 116 | 117 | * GET : The resource has been fetched and is transmitted in the message body. 118 | * HEAD : The representation headers are included in the response without any 119 | message body 120 | * POST : The resource describing the result of the action is transmitted in the 121 | message body 122 | * TRACE : The message body contains the request message as received by the 123 | server. The successful result of a PUT or a DELETE is often not a 200 124 | OK but a 204 No Content (or a 201 Created when the resource is 125 | uploaded for the first time). 126 | 127 | Status 128 | ------ 129 | 130 | 200 OK 131 | 132 | Source 133 | ------ 134 | 135 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200 136 | ` 137 | statusCreated201 = ` 138 | Description 139 | ----------- 140 | 141 | The HTTP 201 Created success status response code indicates that the request has 142 | succeeded and has led to the creation of a resource. 143 | 144 | The new resource, or a description and link to the new resource, is effectively 145 | created before the response is sent back and the newly created items are 146 | returned in the body of the message, located at either the URL of the request, 147 | or at the URL in the value of the Location header. 148 | 149 | The common use case of this status code is as the result of a POST request. 150 | 151 | Status 152 | ------ 153 | 154 | 201 Created 155 | 156 | Source 157 | ------ 158 | 159 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201 160 | ` 161 | statusAccepted202 = ` 162 | Description 163 | ----------- 164 | 165 | The HTTP 202 Accepted response status code indicates that the request has been 166 | accepted for processing, but the processing has not been completed; in fact, 167 | processing may not have started yet. 168 | 169 | The request might or might not eventually be acted upon, as it might be 170 | disallowed when processing actually takes place. 171 | 172 | 202 is non-committal, meaning that there is no way for the HTTP to later send an 173 | asynchronous response indicating the outcome of processing the request. It is 174 | intended for cases where another process or server handles the request, or for 175 | batch processing. 176 | 177 | Status 178 | ------ 179 | 180 | 202 Accepted 181 | 182 | Source 183 | ------ 184 | 185 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/202 186 | ` 187 | statusNonAuthoritativeInfo203 = ` 188 | Description 189 | ----------- 190 | 191 | The HTTP 203 Non-Authoritative Information response status indicates that the 192 | request was successful but the enclosed payload has been modified by a 193 | transforming proxy from that of the origin server's 200 OK response. 194 | 195 | The 203 response is similar to the value 214, meaning Transformation Applied, of 196 | the Warning header code, which has the additional advantage of being applicable 197 | to responses with any status code. 198 | 199 | Status 200 | ------ 201 | 202 | 203 Non-Authoritative Information 203 | 204 | Source 205 | ------ 206 | 207 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/203 208 | ` 209 | statusNoContent204 = ` 210 | Description 211 | ----------- 212 | 213 | The HTTP 204 No Content success status response code indicates that a request 214 | has succeeded, but that the client doesn't need to navigate away from its 215 | current page. 216 | 217 | This might be used, for example, when implementing "save and continue editing" 218 | functionality for a wiki site. In this case a PUT request would be used to save 219 | the page, and the 204 No Content response would be sent to indicate that the 220 | editor should not be replaced by some other page. 221 | 222 | A 204 response is cacheable by default (an ETag header is included in such a 223 | response). 224 | 225 | Status 226 | ------ 227 | 228 | 204 No Content 229 | 230 | Source 231 | ------ 232 | 233 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204 234 | ` 235 | statusResetContent205 = ` 236 | Description 237 | ----------- 238 | 239 | The HTTP 205 Reset Content response status tells the client to reset the 240 | document view, so for example to clear the content of a form, reset a canvas 241 | state, or to refresh the UI. 242 | 243 | Status 244 | ------ 245 | 246 | 205 Reset Content 247 | 248 | Source 249 | ------ 250 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/205 251 | ` 252 | statusPartialContent206 = ` 253 | Description 254 | ----------- 255 | 256 | The HTTP 206 Partial Content success status response code indicates that the 257 | request has succeeded and the body contains the requested ranges of data, as 258 | described in the Range header of the request. 259 | 260 | If there is only one range, the Content-Type of the whole response is set to the 261 | type of the document, and a Content-Range is provided. 262 | 263 | If several ranges are sent back, the Content-Type is set to multipart/ 264 | byteranges and each fragment covers one range, with Content-Range and 265 | Content-Type describing it. 266 | 267 | Status 268 | ------ 269 | 270 | 206 Partial Content 271 | 272 | Source 273 | ------ 274 | 275 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/206 276 | ` 277 | statusMultiStatus207 = ` 278 | Description 279 | ----------- 280 | 281 | Note: The ability to return a collection of resources is part of the WebDAV 282 | protocol (it may be received by web applications accessing a WebDAV server). 283 | Browsers accessing web pages will never encounter this status code. 284 | 285 | The HTTP 207 Multi-Status response code indicates that there might be a mixture 286 | of responses. 287 | 288 | The response body is a text/xml or application/xml HTTP entity with a 289 | multistatus root element. The XML body will list all individual response codes. 290 | 291 | Status 292 | ------ 293 | 294 | 207 Multi-Status 295 | 296 | Source 297 | ------ 298 | 299 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/207 300 | ` 301 | statusAlreadyReported208 = ` 302 | Description 303 | ----------- 304 | 305 | The HTTP 208 Already Reported response code is used in a 207 (207 Multi-Status) 306 | response to save space and avoid conflicts. If the same resource is requested 307 | several times (for example as part of a collection), with different paths, only 308 | the first one is reported with 200. Responses for all other bindings will report 309 | with this 208 status code, so no conflicts are created and the response stays 310 | shorter. 311 | 312 | Status 313 | ------ 314 | 315 | 208 Already Reported 316 | 317 | Source 318 | ------ 319 | 320 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/208 321 | ` 322 | statusIMUsed226 = ` 323 | Description 324 | ----------- 325 | 326 | Note: Browsers don't support delta encoding with HTTP. This status code is sent 327 | back by custom servers used by specific clients. 328 | 329 | In the context of delta encodings, the HTTP 226 IM Used status code is set by 330 | the server to indicate that it is returning a delta to the GET request that it 331 | received. 332 | 333 | With delta encoding a server responds to GET requests with differences (called 334 | deltas) relative to a given base document (rather than the current document). 335 | The client uses the A-IM: HTTP header to indicate which differencing algorithm 336 | to use and the If-None-Match: header to hint the server about the last version 337 | it got. The server generates a delta, sending it back in an HTTP response with 338 | the 226 status code and containing the IM: (with the name of the algorithm 339 | used) and Delta-Base: (with the ETag matching the base document associated to 340 | the delta) HTTP headers. 341 | 342 | IM stands for instance manipulations the term used to describe an algorithm 343 | generating a delta. 344 | 345 | Status 346 | ------ 347 | 348 | 226 IM Used 349 | 350 | Source 351 | ------ 352 | 353 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/226 354 | ` 355 | statusMultipleChoices300 = ` 356 | Description 357 | ----------- 358 | 359 | The HTTP 300 Multiple Choices redirect status response code indicates that the 360 | request has more than one possible response. The user-agent or the user should 361 | choose one of them. As there is no standardized way of choosing one of the 362 | responses, this response code is very rarely used. 363 | 364 | If the server has a preferred choice, it should generate a Location header. 365 | 366 | Status 367 | ------ 368 | 369 | 300 Multiple Choices 370 | 371 | Source 372 | ------ 373 | 374 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/300 375 | ` 376 | statusMovedPermanently301 = ` 377 | Description 378 | ----------- 379 | 380 | The HyperText Transfer Protocol (HTTP) 301 Moved Permanently redirect status 381 | response code indicates that the requested resource has been definitively moved 382 | to the URL given by the Location headers. A browser redirects to the new URL 383 | and search engines update their links to the resource. 384 | 385 | Note: Although the specification requires the method and the body to remain 386 | unchanged when the redirection is performed, not all user-agents meet this 387 | requirement. Use the 301 code only as a response for GET or HEAD methods and use 388 | the 308 Permanent Redirect for POST methods instead, as the method change is 389 | explicitly prohibited with this status. 390 | 391 | Status 392 | ------ 393 | 394 | 301 Moved Permanently 395 | 396 | Source 397 | ------ 398 | 399 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301 400 | ` 401 | statusFound302 = ` 402 | Description 403 | ----------- 404 | 405 | The HyperText Transfer Protocol (HTTP) 302 Found redirect status response code 406 | indicates that the resource requested has been temporarily moved to the URL 407 | given by the Location header. A browser redirects to this page but search 408 | engines don't update their links to the resource (in 'SEO-speak', it is said 409 | that the 'link-juice' is not sent to the new URL). 410 | 411 | Even if the specification requires the method (and the body) not to be altered 412 | when the redirection is performed, not all user-agents conform here - you can 413 | still find this type of bugged software out there. It is therefore recommended 414 | to set the 302 code only as a response for GET or HEAD methods and to use 307 415 | Temporary Redirect instead, as the method change is explicitly prohibited in 416 | that case. 417 | 418 | In the cases where you want the method used to be changed to GET, use 303 See 419 | Other instead. This is useful when you want to give a response to a PUT method 420 | that is not the uploaded resource but a confirmation message such as: 421 | 'you successfully uploaded XYZ'. 422 | 423 | Status 424 | ------ 425 | 426 | 302 Found 427 | 428 | Source 429 | ------ 430 | 431 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302 432 | ` 433 | statusSeeOther303 = ` 434 | Description 435 | ----------- 436 | 437 | The HyperText Transfer Protocol (HTTP) 303 See Other redirect status response 438 | code indicates that the redirects don't link to the requested resource itself, 439 | but to another page (such as a confirmation page, a representation of a 440 | real-world object — see HTTP range-14 — or an upload-progress page). This 441 | response code is often sent back as a result of PUT or POST. The method used to 442 | display this redirected page is always GET. 443 | 444 | Status 445 | ------ 446 | 447 | 303 See Other 448 | 449 | Source 450 | ------ 451 | 452 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303 453 | ` 454 | statusNotModified304 = ` 455 | Description 456 | ----------- 457 | 458 | The HTTP 304 Not Modified client redirection response code indicates that there 459 | is no need to retransmit the requested resources. It is an implicit redirection 460 | to a cached resource. This happens when the request method is a safe method, 461 | such as GET or HEAD, or when the request is conditional and uses an 462 | If-None-Match or an If-Modified-Since header. 463 | 464 | The response must not contain a body and must include the headers that would 465 | have been sent in an equivalent 200 OK response: Cache-Control, 466 | Content-Location, Date, ETag, Expires, and Vary. 467 | 468 | Status 469 | ------ 470 | 471 | 304 Not Modified 472 | 473 | Source 474 | ------ 475 | 476 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304 477 | ` 478 | statusUseProxy305 = `` 479 | _306 = `-` 480 | statusTemporaryRedirect307 = ` 481 | Description 482 | ----------- 483 | 484 | HTTP 307 Temporary Redirect redirect status response code indicates that the 485 | resource requested has been temporarily moved to the URL given by the Location 486 | headers. 487 | 488 | The method and the body of the original request are reused to perform the 489 | redirected request. In the cases where you want the method used to be changed to 490 | GET, use 303 See Other instead. This is useful when you want to give an answer 491 | to a PUT method that is not the uploaded resources, but a confirmation message 492 | (like "You successfully uploaded XYZ"). 493 | 494 | The only difference between 307 and 302 is that 307 guarantees that the method 495 | and the body will not be changed when the redirected request is made. With 302, 496 | some old clients were incorrectly changing the method to GET: the behavior with 497 | non-GET methods and 302 is then unpredictable on the Web, whereas the behavior 498 | with 307 is predictable. For GET requests, their behavior is identical. 499 | 500 | Status 501 | ------ 502 | 503 | 307 Temporary Redirect 504 | 505 | Source 506 | ------ 507 | 508 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307 509 | ` 510 | statusPermanentRedirect308 = ` 511 | Description 512 | ----------- 513 | 514 | The HyperText Transfer Protocol (HTTP) 308 Permanent Redirect redirect status 515 | response code indicates that the resource requested has been definitively moved 516 | to the URL given by the Location headers. A browser redirects to this page and 517 | search engines update their links to the resource (in 'SEO-speak', it is said 518 | that the 'link-juice' is sent to the new URL). 519 | 520 | The request method and the body will not be altered, whereas 301 may incorrectly 521 | sometimes be changed to a GET method. 522 | 523 | Note: Some Web applications may use the 308 Permanent Redirect in a non-standard 524 | way and for other purposes. For example, Google Drive uses a 308 Resume 525 | Incomplete response to indicate to the client when an incomplete upload stalled. 526 | 527 | Status 528 | ------ 529 | 530 | 308 Permanent Redirect 531 | 532 | Source 533 | ------ 534 | 535 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308 536 | ` 537 | 538 | statusBadRequest400 = ` 539 | Description 540 | ----------- 541 | 542 | The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code 543 | indicates that the server cannot or will not process the request due to 544 | something that is perceived to be a client error (for example, malformed request 545 | syntax, invalid request message framing, or deceptive request routing). 546 | 547 | Warning: The client should not repeat this request without modification. 548 | 549 | Status 550 | ------ 551 | 552 | 400 Bad Request 553 | 554 | Source 555 | ------ 556 | 557 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400 558 | ` 559 | statusUnauthorized401 = ` 560 | Description 561 | ----------- 562 | 563 | The HyperText Transfer Protocol (HTTP) 401 Unauthorized response status code 564 | indicates that the client request has not been completed because it lacks valid 565 | authentication credentials for the requested resource. 566 | 567 | This status code is sent with an HTTP WWW-Authenticate response header that 568 | contains information on how the client can request for the resource again after 569 | prompting the user for authentication credentials. 570 | 571 | This status code is similar to the 403 Forbidden status code, except that in 572 | situations resulting in this status code, user authentication can allow access 573 | to the resource. 574 | 575 | Status 576 | ------ 577 | 578 | 401 Unauthorized 579 | 580 | Source 581 | ------ 582 | 583 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 584 | ` 585 | statusPaymentRequired402 = ` 586 | Description 587 | ----------- 588 | 589 | Experimental: This is an experimental technology 590 | Check the Browser compatibility table carefully before using this in production. 591 | 592 | The HTTP 402 Payment Required is a nonstandard response status code that is 593 | reserved for future use. This status code was created to enable digital cash or 594 | (micro) payment systems and would indicate that the requested content is not 595 | available until the client makes a payment. 596 | 597 | Sometimes, this status code indicates that the request cannot be processed until 598 | the client makes a payment. However, no standard use convention exists and 599 | different entities use it in different contexts. 600 | 601 | Status 602 | ------ 603 | 604 | 402 Payment Required 605 | 606 | Source 607 | ------ 608 | 609 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/402 610 | ` 611 | statusForbidden403 = ` 612 | Description 613 | ----------- 614 | 615 | The HTTP 403 Forbidden response status code indicates that the server 616 | understands the request but refuses to authorize it. 617 | 618 | This status is similar to 401, but for the 403 Forbidden status code, 619 | re-authenticating makes no difference. The access is tied to the application 620 | logic, such as insufficient rights to a resource. 621 | 622 | Status 623 | ------ 624 | 625 | 403 Forbidden 626 | 627 | Source 628 | ------ 629 | 630 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403 631 | ` 632 | statusNotFound404 = ` 633 | Description 634 | ----------- 635 | 636 | The HTTP 404 Not Found response status code indicates that the server cannot 637 | find the requested resource. Links that lead to a 404 page are often called 638 | broken or dead links and can be subject to link rot. 639 | 640 | A 404 status code only indicates that the resource is missing: not whether the 641 | absence is temporary or permanent. If a resource is permanently removed, use 642 | the 410 (Gone) status instead. 643 | 644 | Status 645 | ------ 646 | 647 | 404 Not Found 648 | 649 | Source 650 | ------ 651 | 652 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404 653 | ` 654 | statusMethodNotAllowed405 = ` 655 | Description 656 | ----------- 657 | 658 | The HyperText Transfer Protocol (HTTP) 405 Method Not Allowed response status 659 | code indicates that the server knows the request method, but the target resource 660 | doesn't support this method. 661 | 662 | The server must generate an Allow header field in a 405 status code response. 663 | The field must contain a list of methods that the target resource currently 664 | supports. 665 | 666 | Status 667 | ------ 668 | 669 | 405 Method Not Allowed 670 | 671 | Source 672 | ------ 673 | 674 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405 675 | ` 676 | statusNotAcceptable406 = ` 677 | Description 678 | ----------- 679 | 680 | The HyperText Transfer Protocol (HTTP) 406 Not Acceptable client error response 681 | code indicates that the server cannot produce a response matching the list of 682 | acceptable values defined in the request's proactive content negotiation 683 | headers, and that the server is unwilling to supply a default representation. 684 | 685 | Proactive content negotiation headers include: 686 | 687 | * Accept 688 | * Accept-Encoding 689 | * Accept-Language 690 | 691 | In practice, this error is very rarely used. Instead of responding using this 692 | error code, which would be cryptic for the end user and difficult to fix, 693 | servers ignore the relevant header and serve an actual page to the user. It is 694 | assumed that even if the user won't be completely happy, they will prefer this 695 | to an error code. 696 | 697 | If a server returns such an error status, the body of the message should contain 698 | the list of the available representations of the resources, allowing the user to 699 | choose among them. 700 | 701 | Status 702 | ------ 703 | 704 | 406 Not Acceptable 705 | 706 | Source 707 | ------ 708 | 709 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/406 710 | ` 711 | statusProxyAuthRequired407 = ` 712 | Description 713 | ----------- 714 | 715 | The HTTP 407 Proxy Authentication Required client error status response code 716 | indicates that the request has not been applied because it lacks valid 717 | authentication credentials for a proxy server that is between the browser and 718 | the server that can access the requested resource. 719 | 720 | This status is sent with a Proxy-Authenticate header that contains information 721 | on how to authorize correctly. 722 | 723 | Status 724 | ------ 725 | 726 | 407 Proxy Authentication Required 727 | 728 | Source 729 | ------ 730 | 731 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/407 732 | ` 733 | statusRequestTimeout408 = ` 734 | Description 735 | ----------- 736 | 737 | The HyperText Transfer Protocol (HTTP) 408 Request Timeout response status code 738 | means that the server would like to shut down this unused connection. It is sent 739 | on an idle connection by some servers, even without any previous request by the 740 | client. 741 | 742 | A server should send the "close" Connection header field in the response, since 743 | 408 implies that the server has decided to close the connection rather than 744 | continue waiting. 745 | 746 | This response is used much more since some browsers, like Chrome, Firefox 27+, 747 | and IE9, use HTTP pre-connection mechanisms to speed up surfing. 748 | 749 | Status 750 | ------ 751 | 752 | 408 Request Timeout 753 | 754 | Source 755 | ------ 756 | 757 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408 758 | ` 759 | statusConflict409 = ` 760 | Description 761 | ----------- 762 | 763 | The HTTP 409 Conflict response status code indicates a request conflict with 764 | the current state of the target resource. 765 | 766 | Conflicts are most likely to occur in response to a PUT request. For example, 767 | you may get a 409 response when uploading a file that is older than the existing 768 | one on the server, resulting in a version control conflict. 769 | 770 | Status 771 | ------ 772 | 773 | 409 Conflict 774 | 775 | Source 776 | ------ 777 | 778 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409 779 | ` 780 | statusGone410 = ` 781 | Description 782 | ----------- 783 | 784 | The HyperText Transfer Protocol (HTTP) 410 Gone client error response code 785 | indicates that access to the target resource is no longer available at the 786 | origin server and that this condition is likely to be permanent. 787 | 788 | If you don't know whether this condition is temporary or permanent, a 404 status 789 | code should be used instead. 790 | 791 | Status 792 | ------ 793 | 794 | 410 Gone 795 | 796 | Source 797 | ------ 798 | 799 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/410 800 | ` 801 | statusLengthRequired411 = ` 802 | Description 803 | ----------- 804 | 805 | The HyperText Transfer Protocol (HTTP) 411 Length Required client error response 806 | code indicates that the server refuses to accept the request without a defined 807 | Content-Length header. 808 | 809 | Note: by specification, when sending data in a series of chunks, the 810 | Content-Length header is omitted and at the beginning of each chunk you need to 811 | add the length of the current chunk in hexadecimal format. See Transfer-Encoding 812 | for more details. 813 | 814 | Status 815 | ------ 816 | 817 | 411 Length Required 818 | 819 | Source 820 | ------ 821 | 822 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/411 823 | ` 824 | statusPreconditionFailed412 = ` 825 | Description 826 | ----------- 827 | 828 | The HyperText Transfer Protocol (HTTP) 412 Precondition Failed client error 829 | response code indicates that access to the target resource has been denied. This 830 | happens with conditional requests on methods other than GET or HEAD when the 831 | condition defined by the If-Unmodified-Since or If-None-Match headers is not 832 | fulfilled. In that case, the request, usually an upload or a modification of a 833 | resource, cannot be made and this error response is sent back. 834 | 835 | Status 836 | ------ 837 | 838 | 412 Precondition Failed 839 | 840 | Source 841 | ------ 842 | 843 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/412 844 | ` 845 | statusRequestEntityTooLarge413 = ` 846 | The HTTP 413 Content Too Large response status code indicates that the request 847 | entity is larger than limits defined by server; the server might close the 848 | connection or return a Retry-After header field. 849 | 850 | Prior to RFC 9110 the response phrase for the status was Payload Too Large. That 851 | name is still widely used. 852 | 853 | Status 854 | ------ 855 | 856 | 413 Payload Too Large 857 | 858 | Source 859 | ------ 860 | 861 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/413 862 | ` 863 | statusRequestURITooLong414 = ` 864 | Description 865 | ----------- 866 | 867 | The HTTP 414 URI Too Long response status code indicates that the URI requested 868 | by the client is longer than the server is willing to interpret. 869 | 870 | There are a few rare conditions when this might occur: 871 | 872 | * when a client has improperly converted a POST request to a GET request with 873 | long query information, 874 | 875 | * when the client has descended into a loop of redirection (for example, a 876 | redirected URI prefix that points to a suffix of itself), 877 | 878 | * or when the server is under attack by a client attempting to exploit 879 | potential security holes. 880 | 881 | Status 882 | ------ 883 | 884 | 414 URI Too Long 885 | 886 | Source 887 | ------ 888 | 889 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/414 890 | ` 891 | statusUnsupportedMediaType415 = ` 892 | Description 893 | ----------- 894 | 895 | The HTTP 415 Unsupported Media Type client error response code indicates that 896 | the server refuses to accept the request because the payload format is in an 897 | unsupported format. 898 | 899 | The format problem might be due to the request's indicated Content-Type or 900 | Content-Encoding, or as a result of inspecting the data directly. 901 | 902 | Status 903 | ------ 904 | 905 | 415 Unsupported Media Type 906 | 907 | Source 908 | ------ 909 | 910 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/415 911 | ` 912 | statusRequestedRangeNotSatisfiable416 = ` 913 | Description 914 | ----------- 915 | 916 | The HyperText Transfer Protocol (HTTP) 416 Range Not Satisfiable error response 917 | code indicates that a server cannot serve the requested ranges. The most likely 918 | reason is that the document doesn't contain such ranges, or that the Range 919 | header value, though syntactically correct, doesn't make sense. 920 | 921 | The 416 response message contains a Content-Range indicating an unsatisfied 922 | range (that is a '*') followed by a '/' and the current length of the resource. 923 | E.g. Content-Range: bytes */12777 924 | 925 | Faced with this error, browsers usually either abort the operation (for example, 926 | a download will be considered as non-resumable) or ask for the whole document 927 | again. 928 | 929 | Status 930 | ------ 931 | 932 | 416 Range Not Satisfiable 933 | 934 | Source 935 | ------ 936 | 937 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/416 938 | ` 939 | statusExpectationFailed417 = ` 940 | Description 941 | ----------- 942 | 943 | The HTTP 417 Expectation Failed client error response code indicates that the 944 | expectation given in the request's Expect header could not be met. 945 | 946 | See the Expect header for more details. 947 | 948 | Status 949 | ------ 950 | 951 | 417 Expectation Failed 952 | 953 | Source 954 | ------ 955 | 956 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/417 957 | ` 958 | statusTeapot418 = ` 959 | Description 960 | ----------- 961 | 962 | The HTTP 418 I'm a teapot client error response code indicates that the server 963 | refuses to brew coffee because it is, permanently, a teapot. A combined 964 | coffee/tea pot that is temporarily out of coffee should instead return 503. This 965 | error is a reference to Hyper Text Coffee Pot Control Protocol defined in April 966 | Fools' jokes in 1998 and 2014. 967 | 968 | Some websites use this response for requests they do not wish to handle, such as 969 | automated queries. 970 | 971 | Status 972 | ------ 973 | 974 | 418 I'm a teapot 975 | 976 | Source 977 | ------ 978 | 979 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/418 980 | ` 981 | statusMisdirectedRequest421 = ` 982 | Description 983 | ----------- 984 | 985 | The HTTP 421 Misdirected Request client error response code indicates that the 986 | request was directed to a server that is not able to produce a response. This 987 | might be possible if a connection is reused or if an alternative service is 988 | selected. 989 | 990 | Status 991 | ------ 992 | 993 | 421 Misdirected Request 994 | 995 | Source 996 | ------ 997 | 998 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/421 999 | ` 1000 | statusUnprocessableEntity422 = ` 1001 | Description 1002 | ----------- 1003 | 1004 | The HyperText Transfer Protocol (HTTP) 422 Unprocessable Content response status 1005 | code indicates that the server understands the content type of the request 1006 | entity, and the syntax of the request entity is correct, but it was unable to 1007 | process the contained instructions. 1008 | 1009 | Warning: The client should not repeat this request without modification. 1010 | 1011 | Status 1012 | ------ 1013 | 1014 | 422 Unprocessable Entity 1015 | 1016 | Source 1017 | ------ 1018 | 1019 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422 1020 | ` 1021 | statusLocked423 = ` 1022 | Description 1023 | ----------- 1024 | 1025 | Note: The ability to lock a resource is specific to some WebDAV servers. 1026 | Browsers accessing web pages will never encounter this status code; in the 1027 | erroneous cases it happens, they will handle it as a generic 400 status code. 1028 | 1029 | The HTTP 423 Locked error response code indicates that either the resources 1030 | tentatively targeted by is locked, meaning it can't be accessed. Its content 1031 | should contain some information in WebDAV's XML format. 1032 | 1033 | Status 1034 | ------ 1035 | 1036 | 423 Locked 1037 | 1038 | Source 1039 | ------ 1040 | 1041 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/423 1042 | ` 1043 | statusFailedDependency424 = ` 1044 | Description 1045 | ----------- 1046 | 1047 | The HTTP 424 Failed Dependency client error response code indicates that the 1048 | method could not be performed on the resource because the requested action 1049 | depended on another action, and that action failed. 1050 | 1051 | Regular web servers will normally not return this status code. But some other 1052 | protocols, like WebDAV, can return it. For example, in WebDAV, if a PROPPATCH 1053 | request was issued, and one command fails then automatically every other command 1054 | will also fail with 424 Failed Dependency. 1055 | 1056 | Status 1057 | ------ 1058 | 1059 | 424 Failed Dependency 1060 | 1061 | Source 1062 | ------ 1063 | 1064 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/424 1065 | ` 1066 | statusTooEarly425 = ` 1067 | Description 1068 | ----------- 1069 | 1070 | The HyperText Transfer Protocol (HTTP) 425 Too Early response status code 1071 | indicates that the server is unwilling to risk processing a request that might 1072 | be replayed, which creates the potential for a replay attack. 1073 | 1074 | Status 1075 | ------ 1076 | 1077 | 425 Too Early 1078 | 1079 | Source 1080 | ------ 1081 | 1082 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/425 1083 | ` 1084 | statusUpgradeRequired426 = ` 1085 | Description 1086 | ----------- 1087 | 1088 | The HTTP 426 Upgrade Required client error response code indicates that the 1089 | server refuses to perform the request using the current protocol but might be 1090 | willing to do so after the client upgrades to a different protocol. 1091 | 1092 | The server sends an Upgrade header with this response to indicate the required 1093 | protocol(s). 1094 | 1095 | Status 1096 | ------ 1097 | 1098 | 426 Upgrade Required 1099 | 1100 | Source 1101 | ------ 1102 | 1103 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/426 1104 | ` 1105 | statusPreconditionRequired428 = ` 1106 | Description 1107 | ----------- 1108 | 1109 | The HTTP 428 Precondition Required response status code indicates that the 1110 | server requires the request to be conditional. 1111 | 1112 | Typically, this means that a required precondition header, such as If-Match, is 1113 | missing. 1114 | 1115 | When a precondition header is not matching the server side state, the response 1116 | should be 412 Precondition Failed. 1117 | 1118 | Status 1119 | ------ 1120 | 1121 | 428 Precondition Required 1122 | 1123 | Source 1124 | ------ 1125 | 1126 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/428 1127 | ` 1128 | statusTooManyRequests429 = ` 1129 | Description 1130 | ----------- 1131 | 1132 | The HTTP 429 Too Many Requests response status code indicates the user has sent 1133 | too many requests in a given amount of time ("rate limiting"). 1134 | 1135 | A Retry-After header might be included to this response indicating how long to 1136 | wait before making a new request. 1137 | 1138 | Status 1139 | ------ 1140 | 1141 | 429 Too Many Requests 1142 | 1143 | Source 1144 | ------ 1145 | 1146 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429 1147 | ` 1148 | statusRequestHeaderFieldsTooLarge431 = ` 1149 | Description 1150 | ----------- 1151 | 1152 | The HTTP 431 Request Header Fields Too Large response status code indicates that 1153 | the server refuses to process the request because the request's HTTP headers are 1154 | too long. The request may be resubmitted after reducing the size of the request 1155 | headers. 1156 | 1157 | 431 can be used when the total size of request headers is too large, or when a 1158 | single header field is too large. To help those running into this error, 1159 | indicate which of the two is the problem in the response body — ideally, also 1160 | include which headers are too large. This lets users attempt to fix the problem, 1161 | such as by clearing their cookies. 1162 | 1163 | Servers will often produce this status if: 1164 | 1165 | * The Referer URL is too long 1166 | * There are too many Cookies sent in the request 1167 | 1168 | Status 1169 | ------ 1170 | 1171 | 431 Request Header Fields Too Large 1172 | 1173 | Source 1174 | ------ 1175 | 1176 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/431 1177 | ` 1178 | statusUnavailableForLegalReasons451 = ` 1179 | Description 1180 | ----------- 1181 | 1182 | The HyperText Transfer Protocol (HTTP) 451 Unavailable For Legal Reasons client 1183 | error response code indicates that the user requested a resource that is not 1184 | available due to legal reasons, such as a web page for which a legal action has 1185 | been issued. 1186 | 1187 | Status 1188 | ------ 1189 | 1190 | 451 Unavailable For Legal Reasons 1191 | 1192 | Source 1193 | ------ 1194 | 1195 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/451 1196 | ` 1197 | 1198 | statusInternalServerError500 = ` 1199 | Description 1200 | ----------- 1201 | 1202 | The HyperText Transfer Protocol (HTTP) 500 Internal Server Error server error 1203 | response code indicates that the server encountered an unexpected condition that 1204 | prevented it from fulfilling the request. 1205 | 1206 | This error response is a generic "catch-all" response. Usually, this indicates 1207 | the server cannot find a better 5xx error code to response. Sometimes, server 1208 | administrators log error responses like the 500 status code with more details 1209 | about the request to prevent the error from happening again in the future. 1210 | 1211 | Status 1212 | ------ 1213 | 1214 | 500 Internal Server Error 1215 | 1216 | Source 1217 | ------ 1218 | 1219 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500 1220 | ` 1221 | statusNotImplemented501 = ` 1222 | Description 1223 | ----------- 1224 | 1225 | The HyperText Transfer Protocol (HTTP) 501 Not Implemented server error response 1226 | code means that the server does not support the functionality required to 1227 | fulfill the request. 1228 | 1229 | This status can also send a Retry-After header, telling the requester when to 1230 | check back to see if the functionality is supported by then. 1231 | 1232 | 501 is the appropriate response when the server does not recognize the request 1233 | method and is incapable of supporting it for any resource. The only methods that 1234 | servers are required to support (and therefore that must not return 501) are GET 1235 | and HEAD. 1236 | 1237 | If the server does recognize the method, but intentionally does not support it, 1238 | the appropriate response is 405 Method Not Allowed. 1239 | 1240 | Status 1241 | ------ 1242 | 1243 | 501 Not Implemented 1244 | 1245 | Source 1246 | ------ 1247 | 1248 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/501 1249 | ` 1250 | statusBadGateway502 = ` 1251 | Description 1252 | ----------- 1253 | 1254 | The HyperText Transfer Protocol (HTTP) 502 Bad Gateway server error response 1255 | code indicates that the server, while acting as a gateway or proxy, received an 1256 | invalid response from the upstream server. 1257 | 1258 | Note: A Gateway might refer to different things in networking and a 502 error is 1259 | usually not something you can fix, but requires a fix by the web server or the 1260 | proxies you are trying to get access through. 1261 | 1262 | Status 1263 | ------ 1264 | 1265 | 502 Bad Gateway 1266 | 1267 | Source 1268 | ------ 1269 | 1270 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502 1271 | ` 1272 | statusServiceUnavailable503 = ` 1273 | Description 1274 | ----------- 1275 | 1276 | The HyperText Transfer Protocol (HTTP) 503 Service Unavailable server error 1277 | response code indicates that the server is not ready to handle the request. 1278 | 1279 | Common causes are a server that is down for maintenance or that is overloaded. 1280 | This response should be used for temporary conditions and the Retry-After HTTP 1281 | header should, if possible, contain the estimated time for the recovery of the 1282 | service. 1283 | 1284 | Note: together with this response, a user-friendly page explaining the problem 1285 | should be sent. 1286 | 1287 | Caching-related headers that are sent along with this response should be taken 1288 | care of, as a 503 status is often a temporary condition and responses shouldn't 1289 | usually be cached. 1290 | 1291 | Status 1292 | ------ 1293 | 1294 | 503 Service Unavailable 1295 | 1296 | Source 1297 | ------ 1298 | 1299 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503 1300 | ` 1301 | statusGatewayTimeout504 = ` 1302 | Description 1303 | ----------- 1304 | 1305 | The HyperText Transfer Protocol (HTTP) 504 Gateway Timeout server error response 1306 | code indicates that the server, while acting as a gateway or proxy, did not get 1307 | a response in time from the upstream server that it needed in order to complete 1308 | the request. 1309 | 1310 | Note: A Gateway might refer to different things in networking and a 504 error is 1311 | usually not something you can fix, but requires a fix by the web server or the 1312 | proxies you are trying to get access through. 1313 | 1314 | Status 1315 | ------ 1316 | 1317 | 504 Gateway Timeout 1318 | 1319 | Source 1320 | ------ 1321 | 1322 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504 1323 | ` 1324 | statusHTTPVersionNotSupported505 = ` 1325 | Description 1326 | ----------- 1327 | 1328 | The HyperText Transfer Protocol (HTTP) 505 HTTP Version Not Supported response 1329 | status code indicates that the HTTP version used in the request is not supported 1330 | by the server. 1331 | 1332 | Status 1333 | ------ 1334 | 1335 | 505 HTTP Version Not Supported 1336 | 1337 | Source 1338 | ------ 1339 | 1340 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/505 1341 | ` 1342 | statusVariantAlsoNegotiates506 = ` 1343 | Description 1344 | ----------- 1345 | 1346 | The HyperText Transfer Protocol (HTTP) 506 Variant Also Negotiates response 1347 | status code may be given in the context of Transparent Content Negotiation 1348 | (see RFC 2295). This protocol enables a client to retrieve the best variant of 1349 | a given resource, where the server supports multiple variants. 1350 | 1351 | The Variant Also Negotiates status code indicates an internal server 1352 | configuration error in which the chosen variant is itself configured to engage 1353 | in content negotiation, so is not a proper negotiation endpoint. 1354 | 1355 | Status 1356 | ------ 1357 | 1358 | 506 Variant Also Negotiates 1359 | 1360 | Source 1361 | ------ 1362 | 1363 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/506 1364 | ` 1365 | statusInsufficientStorage507 = ` 1366 | Description 1367 | ----------- 1368 | 1369 | The HyperText Transfer Protocol (HTTP) 507 Insufficient Storage response status 1370 | code may be given in the context of the Web Distributed Authoring and Versioning 1371 | (WebDAV) protocol (see RFC 4918). 1372 | 1373 | It indicates that a method could not be performed because the server cannot 1374 | store the representation needed to successfully complete the request. 1375 | 1376 | Status 1377 | ------ 1378 | 1379 | 507 Insufficient Storage 1380 | 1381 | Source 1382 | ------ 1383 | 1384 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/507 1385 | ` 1386 | statusLoopDetected508 = ` 1387 | Description 1388 | ----------- 1389 | 1390 | The HyperText Transfer Protocol (HTTP) 508 Loop Detected response status code 1391 | may be given in the context of the Web Distributed Authoring and Versioning 1392 | (WebDAV) protocol. 1393 | 1394 | It indicates that the server terminated an operation because it encountered an 1395 | infinite loop while processing a request with "Depth: infinity". This status 1396 | indicates that the entire operation failed. 1397 | 1398 | Status 1399 | ------ 1400 | 1401 | 508 Loop Detected 1402 | 1403 | Source 1404 | ------ 1405 | 1406 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/508 1407 | ` 1408 | statusNotExtended510 = ` 1409 | Description 1410 | ----------- 1411 | 1412 | The HyperText Transfer Protocol (HTTP) 510 Not Extended response status code is 1413 | sent in the context of the HTTP Extension Framework, defined in RFC 2774. 1414 | 1415 | In that specification a client may send a request that contains an extension 1416 | declaration, that describes the extension to be used. If the server receives 1417 | such a request, but any described extensions are not supported for the request, 1418 | then the server responds with the 510 status code. 1419 | 1420 | Status 1421 | ------ 1422 | 1423 | 510 Not Extended 1424 | 1425 | Source 1426 | ------ 1427 | 1428 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/510 1429 | ` 1430 | statusNetworkAuthenticationRequired511 = ` 1431 | Description 1432 | ----------- 1433 | 1434 | The HTTP 511 Network Authentication Required response status code indicates that 1435 | the client needs to authenticate to gain network access. 1436 | 1437 | This status is not generated by origin servers, but by intercepting proxies that 1438 | control access to the network. 1439 | 1440 | Network operators sometimes require some authentication, acceptance of terms, or 1441 | other user interaction before granting access (for example in an internet café 1442 | or at an airport). They often identify clients who have not done so using 1443 | their Media Access Control (MAC) addresses. 1444 | 1445 | Status 1446 | ------ 1447 | 1448 | 511 Network Authentication Required 1449 | 1450 | Source 1451 | ------ 1452 | 1453 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/511 1454 | ` 1455 | ) 1456 | 1457 | var statusCodes = []string{ 1458 | "------------------ 1xx ------------------", // category header 1459 | "100", 1460 | "101", 1461 | "102", 1462 | "103", 1463 | 1464 | "------------------ 2xx ------------------", 1465 | "200", 1466 | "201", 1467 | "202", 1468 | "203", 1469 | "204", 1470 | "205", 1471 | "206", 1472 | "207", 1473 | "208", 1474 | "226", 1475 | 1476 | "------------------ 3xx ------------------", 1477 | "300", 1478 | "301", 1479 | "302", 1480 | "303", 1481 | "304", 1482 | "305", 1483 | "306", 1484 | "307", 1485 | "308", 1486 | 1487 | "------------------ 4xx ------------------", 1488 | "400", 1489 | "401", 1490 | "402", 1491 | "403", 1492 | "404", 1493 | "405", 1494 | "406", 1495 | "407", 1496 | "408", 1497 | "409", 1498 | "410", 1499 | "411", 1500 | "412", 1501 | "413", 1502 | "414", 1503 | "415", 1504 | "416", 1505 | "417", 1506 | "418", 1507 | "421", 1508 | "422", 1509 | "423", 1510 | "424", 1511 | "425", 1512 | "426", 1513 | "428", 1514 | "429", 1515 | "431", 1516 | "451", 1517 | 1518 | "------------------ 5xx ------------------", 1519 | "500", 1520 | "501", 1521 | "502", 1522 | "503", 1523 | "504", 1524 | "505", 1525 | "506", 1526 | "507", 1527 | "508", 1528 | "510", 1529 | "511", 1530 | } 1531 | 1532 | var statusCodeMap = map[string]string{ 1533 | // "------------------ 1xx ------------------" 1534 | "100": statusContinue100, 1535 | "101": statusSwitchingProtocols101, 1536 | "102": statusProcessing102, 1537 | "103": statusEarlyHints103, 1538 | 1539 | // "------------------ 2xx ------------------" 1540 | "200": statusOK200, 1541 | "201": statusCreated201, 1542 | "202": statusAccepted202, 1543 | "203": statusNonAuthoritativeInfo203, 1544 | "204": statusNoContent204, 1545 | "205": statusResetContent205, 1546 | "206": statusPartialContent206, 1547 | "207": statusMultiStatus207, 1548 | "208": statusAlreadyReported208, 1549 | "226": statusIMUsed226, 1550 | 1551 | // "------------------ 3xx ------------------" 1552 | "300": statusMultipleChoices300, 1553 | "301": statusMovedPermanently301, 1554 | "302": statusFound302, 1555 | "303": statusSeeOther303, 1556 | "304": statusNotModified304, 1557 | "305": statusUseProxy305, 1558 | "306": _306, 1559 | "307": statusTemporaryRedirect307, 1560 | "308": statusPermanentRedirect308, 1561 | 1562 | // "------------------ 4xx ------------------" 1563 | "400": statusBadRequest400, 1564 | "401": statusUnauthorized401, 1565 | "402": statusPaymentRequired402, 1566 | "403": statusForbidden403, 1567 | "404": statusNotFound404, 1568 | "405": statusMethodNotAllowed405, 1569 | "406": statusNotAcceptable406, 1570 | "407": statusProxyAuthRequired407, 1571 | "408": statusRequestTimeout408, 1572 | "409": statusConflict409, 1573 | "410": statusGone410, 1574 | "411": statusLengthRequired411, 1575 | "412": statusPreconditionFailed412, 1576 | "413": statusRequestEntityTooLarge413, 1577 | "414": statusRequestURITooLong414, 1578 | "415": statusUnsupportedMediaType415, 1579 | "416": statusRequestedRangeNotSatisfiable416, 1580 | "417": statusExpectationFailed417, 1581 | "418": statusTeapot418, 1582 | "421": statusMisdirectedRequest421, 1583 | "422": statusUnprocessableEntity422, 1584 | "423": statusLocked423, 1585 | "424": statusFailedDependency424, 1586 | "425": statusTooEarly425, 1587 | "426": statusUpgradeRequired426, 1588 | "428": statusPreconditionRequired428, 1589 | "429": statusTooManyRequests429, 1590 | "431": statusRequestHeaderFieldsTooLarge431, 1591 | "451": statusUnavailableForLegalReasons451, 1592 | 1593 | // "------------------ 5xx ------------------" 1594 | "500": statusInternalServerError500, 1595 | "501": statusNotImplemented501, 1596 | "502": statusBadGateway502, 1597 | "503": statusServiceUnavailable503, 1598 | "504": statusGatewayTimeout504, 1599 | "505": statusHTTPVersionNotSupported505, 1600 | "506": statusVariantAlsoNegotiates506, 1601 | "507": statusInsufficientStorage507, 1602 | "508": statusLoopDetected508, 1603 | "510": statusNotExtended510, 1604 | "511": statusNetworkAuthenticationRequired511, 1605 | } 1606 | -------------------------------------------------------------------------------- /src/data_test.go: -------------------------------------------------------------------------------- 1 | package src 2 | 3 | import ( 4 | "slices" 5 | "testing" 6 | ) 7 | 8 | // Test statusCodes slice 9 | func TestStatusCodes(t *testing.T) { 10 | // Check length 11 | want := 68 12 | got := len(statusCodes) 13 | 14 | if got != want { 15 | t.Errorf("len(statusCodes) = %d, want %d", got, want) 16 | } 17 | 18 | var wantStatusCodes = []string{ 19 | "------------------ 1xx ------------------", 20 | "100", 21 | "101", 22 | "102", 23 | "103", 24 | 25 | "------------------ 2xx ------------------", 26 | "200", 27 | "201", 28 | "202", 29 | "203", 30 | "204", 31 | "205", 32 | "206", 33 | "207", 34 | "208", 35 | "226", 36 | 37 | "------------------ 3xx ------------------", 38 | "300", 39 | "301", 40 | "302", 41 | "303", 42 | "304", 43 | "305", 44 | "306", 45 | "307", 46 | "308", 47 | 48 | "------------------ 4xx ------------------", 49 | "400", 50 | "401", 51 | "402", 52 | "403", 53 | "404", 54 | "405", 55 | "406", 56 | "407", 57 | "408", 58 | "409", 59 | "410", 60 | "411", 61 | "412", 62 | "413", 63 | "414", 64 | "415", 65 | "416", 66 | "417", 67 | "418", 68 | "421", 69 | "422", 70 | "423", 71 | "424", 72 | "425", 73 | "426", 74 | "428", 75 | "429", 76 | "431", 77 | "451", 78 | 79 | "------------------ 5xx ------------------", 80 | "500", 81 | "501", 82 | "502", 83 | "503", 84 | "504", 85 | "505", 86 | "506", 87 | "507", 88 | "508", 89 | "510", 90 | "511", 91 | } 92 | 93 | if !slices.Equal(statusCodes, wantStatusCodes) { 94 | t.Errorf("statusCodes = %v, want %v", statusCodes, wantStatusCodes) 95 | } 96 | } 97 | 98 | // Test statusCodeMap 99 | func TestStatusCodeMap(t *testing.T) { 100 | 101 | // Check length 102 | want := 68 - 5 // 5 is the number section headers 103 | got := len(statusCodeMap) 104 | 105 | if got != want { 106 | t.Errorf("len(statusCodeMap) = %d, want %d", got, want) 107 | } 108 | } 109 | --------------------------------------------------------------------------------