-
-
Save benburkert/76548cfac5aa6761fab2f88783b673aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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