diff options
| author | Marin Ivanov <[email protected]> | 2019-04-26 10:41:44 +0300 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2019-04-26 16:17:07 +0300 |
| commit | 174e6b2bbdd299b478ae00875d265c06459c5ad0 (patch) | |
| tree | 91a698f0d0d04e4817df71b737ba80965e7c856f /http.go | |
| parent | 71de5fe35cf826f700459c511ecfd89c6d9f789f (diff) | |
Add HTTP protocol tarpit
Diffstat (limited to 'http.go')
| -rw-r--r-- | http.go | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -0,0 +1,39 @@ +package main + +import ( + "bufio" + "fmt" + "io" + "io/ioutil" + "math/rand" + "net" + "time" +) + +func httpHandler(conn net.Conn, delay time.Duration) { + rd := bufio.NewReader(conn) + rd.ReadLine() + _, err := fmt.Fprintf(conn, "HTTP/1.1 200 OK\r\n") + if err != nil { + return + } + + eof := make(chan empty) + go func() { + io.Copy(ioutil.Discard, conn) + eof <- empty{} + }() + + tick := time.Tick(delay) + for { + select { + case <-eof: + return + case <-tick: + _, err := fmt.Fprintf(conn, "X-%x: %x\r\n", rand.Uint32(), rand.Uint32()) + if err != nil { + return + } + } + } +} |
