Created
June 19, 2015 20:27
-
-
Save ejcx/ddbc91088243c96718da to your computer and use it in GitHub Desktop.
bigimg
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" | |
"os" | |
) | |
func main() { | |
fmt.Println("Started:") | |
webpage := ` | |
<html> | |
<head> | |
<link id="fav" rel="shortcut icon" href="/empty"/> | |
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'> | |
</head> | |
<body> | |
<h1> Hey. Welcome to my 1gb image</h1> | |
<img src="/test.jpg"/> | |
</body> | |
</html> | |
` | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
w.Write([]byte(webpage)) | |
}) | |
http.HandleFunc("/test.jpg", func(w http.ResponseWriter, r *http.Request) { | |
for i := 0; i < 10000000; i++ { | |
b := make([]byte, 4096) | |
rand.Read(b) | |
if b[0] == 0 { | |
fmt.Printf("Writing to %s\n", r.RemoteAddr) | |
} | |
_, err := w.Write([]byte(b)) | |
if err != nil { | |
return | |
} | |
} | |
}) | |
err := http.ListenAndServe(":80", nil) | |
if err != nil { | |
fmt.Println("Server did not start") | |
log.Println(err) | |
os.Exit(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment