aboutsummaryrefslogtreecommitdiff
path: root/http.go
diff options
context:
space:
mode:
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
+ }
+ }
+ }
+}