-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler_garbage.go
48 lines (42 loc) · 1.1 KB
/
handler_garbage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"crypto/rand"
"log"
"net/http"
"strconv"
)
var (
garbageBytes [1048576]byte
)
func init() {
rand.Read(garbageBytes[:])
}
func garbageHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Description", "File Transfer")
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", "attachment; filename=random.dat")
w.Header().Set("Content-Transfer-Encoding", "binary")
w.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0")
w.Header().Add("Cache-Control", "post-check=0, pre-check=0")
w.Header().Set("Pragma", "no-cache")
w.WriteHeader(http.StatusOK)
chunks := 4
ckSize := r.FormValue("ckSize")
if ckSize != "" {
i, err := strconv.Atoi(ckSize)
if err != nil {
log.Printf("garbage.php: invalid ckSize: %s: %s", ckSize, err)
} else if i < 0 || i > 100 {
log.Printf("garbage.php: 0 > ckSize > 100: %d", chunks)
} else {
chunks = i
}
}
for i := 0; i < chunks; i++ {
_, err := w.Write(garbageBytes[:])
if err != nil {
log.Printf("garbage.php: %s", err)
return
}
}
}