Last active
February 29, 2016 04:40
-
-
Save ejcx/f95f3191d183ea8717a3 to your computer and use it in GitHub Desktop.
Go program that makes a webserver with an infinitely large favicon.
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
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