aboutsummaryrefslogtreecommitdiff
path: root/http.go
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2019-04-26 10:41:44 +0300
committerMarin Ivanov <[email protected]>2019-04-26 16:17:07 +0300
commit174e6b2bbdd299b478ae00875d265c06459c5ad0 (patch)
tree91a698f0d0d04e4817df71b737ba80965e7c856f /http.go
parent71de5fe35cf826f700459c511ecfd89c6d9f789f (diff)
Add HTTP protocol tarpit
Diffstat (limited to 'http.go')
-rw-r--r--http.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/http.go b/http.go
new file mode 100644
index 0000000..c8199a3
--- /dev/null
+++ b/http.go
@@ -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
+ }
+ }
+ }
+}