Last active
March 24, 2024 12:21
-
-
Save garystafford/c7a81f75c88cd8d13b041aef4541a78c to your computer and use it in GitHub Desktop.
Simple HTTP server that returns random HTTP status code, written in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple HTTP server that returns random HTTP status code, written in Go. | |
// Author: Gary A. Stafford <garystafford@rochester.rr.com> | |
// Created: 11/04/2016 | |
package main | |
import ( | |
"io" | |
"math/rand" | |
"net/http" | |
) | |
var statusCodesAll = [60]int{ | |
100, 101, 102, 200, 201, 202, 203, 204, 205, 206, | |
207, 208, 226, 300, 301, 302, 303, 304, 305, 306, | |
307, 308, 400, 401, 402, 403, 404, 405, 406, 407, | |
408, 409, 410, 411, 412, 413, 414, 415, 416, 417, | |
418, 422, 423, 424, 426, 428, 429, 431, 451, 500, | |
501, 502, 503, 504, 505, 506, 507, 508, 510, 511} | |
var statusCodesCommonWeighted = [35]int{ | |
200, 200, 200, 200, 200, 200, 200, 200, 200, 200, | |
300, 301, 302, 304, 307, 400, 401, 403, 404, 404, | |
404, 404, 404, 410, 500, 500, 500, 500, 500, 501, | |
503, 503, 503, 503, 550} | |
func status(w http.ResponseWriter, r *http.Request) { | |
foo := statusCodesCommonWeighted[rand.Intn(len(statusCodesCommonWeighted))] | |
w.WriteHeader(foo) | |
io.WriteString(w, "Random HTTP Status Code Generator, written in Go") | |
} | |
func main() { | |
http.HandleFunc("/", status) | |
http.ListenAndServe(":8000", nil) | |
} |
This is brilliant
AWS source code leaked. Awesome
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run Server:
go run random-status.go
Example Output: