Skip to content

Instantly share code, notes, and snippets.

@alicebob
Created June 2, 2015 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alicebob/6b286c4678790fa546f8 to your computer and use it in GitHub Desktop.
Save alicebob/6b286c4678790fa546f8 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net"
"net/http"
"time"
)
func main() {
http.HandleFunc("/", myHandler)
l, err := net.Listen("tcp", ":12345")
if err != nil {
log.Fatal(err)
}
go func() {
log.Fatal(http.Serve(l, nil))
}()
cl := http.Client{
Transport: &http.Transport{},
}
req, err := http.NewRequest("GET", "http://localhost:12345/", nil)
if err != nil {
log.Fatal(err)
}
go func() {
time.Sleep(100 * time.Millisecond)
cl.Transport.(*http.Transport).CancelRequest(req)
}()
if _, err := cl.Do(req); err != nil {
log.Fatal(err)
}
}
func myHandler(w http.ResponseWriter, r *http.Request) {
time.Sleep(1 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment