Skip to content

Instantly share code, notes, and snippets.

Last active April 8, 2020 13:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Tiny HTTP Server to test MaxUploadSize behind a Loadbalancer
package main
import (
func post(w http.ResponseWriter, r *http.Request) {
// fetch header size
size, err := strconv.Atoi(r.Header["Content-Length"][0])
if err != nil {
// fetch body size
buf := new(bytes.Buffer)
body := len(buf.String())
// bytes to mb
mbh := float64(size)/1000000
mbb := float64(body)/1000000
fmt.Fprintf(w, "Header: %.2f MB, Body: %.2f MB!\n", mbh, mbb)
fmt.Printf("Header: %.2f, Body: %.2f MB!\n", mbh, mbb)
func get(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Try:\n curl -X POST --data-binary @<file> <host>:<port>\n" )
func handler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
get(w, r)
case "POST":
post(w, r)
func main() {
port := ":" + os.Args[1]
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(port, nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment