Skip to content

Instantly share code, notes, and snippets.

@benburkert
Created March 4, 2019 20:02
Show Gist options
  • Save benburkert/76548cfac5aa6761fab2f88783b673aa to your computer and use it in GitHub Desktop.
Save benburkert/76548cfac5aa6761fab2f88783b673aa to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"bytes"
"net"
"net/http"
"net/http/httptest"
"net/url"
)
func main() {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
go r.Body.Read(make([]byte, 1024))
go r.Body.Close()
}))
u, err := url.Parse(srv.URL)
if err != nil {
panic(err)
}
for {
conn, err := net.Dial("tcp", u.Host)
if err != nil {
panic(err)
}
req, err := http.NewRequest("POST", srv.URL, bytes.NewBufferString("test body"))
if err != nil {
panic(err)
}
req.Header.Set("Expect", "100-continue") // commenting this out avoids the race
if err := req.Write(conn); err != nil {
continue
}
_, err = http.ReadResponse(bufio.NewReader(conn), req)
if err != nil {
continue
}
conn.Close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment