Skip to content

Instantly share code, notes, and snippets.

@ejcx
Last active February 29, 2016 04:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejcx/f95f3191d183ea8717a3 to your computer and use it in GitHub Desktop.
Save ejcx/f95f3191d183ea8717a3 to your computer and use it in GitHub Desktop.
Go program that makes a webserver with an infinitely large favicon.
package main
import (
"crypto/rand"
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("You are downloading an infinitely large favicon. If you want to stop, close the window"))
})
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
b := make([]byte, 4096)
for {
rand.Read(b)
if b[0] == 0 {
fmt.Printf("Writing to %s\n", r.RemoteAddr)
}
// If they close the connection stop writing.
_, err := w.Write([]byte(b))
if err != nil {
return
}
}
})
log.Println(http.ListenAndServe(":8080", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment