Skip to content

Instantly share code, notes, and snippets.

@dtjm
Last active April 21, 2017 16:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtjm/3637cb711a3d4283f77180aaf4fa4903 to your computer and use it in GitHub Desktop.
Save dtjm/3637cb711a3d4283f77180aaf4fa4903 to your computer and use it in GitHub Desktop.
HTTP server closes connection under Go 1.4.3
package main
import (
"io/ioutil"
"log"
"net/http"
)
func main() {
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
log.Println("listening on 127.0.0.1:10000")
err := http.ListenAndServe("127.0.0.1:10000", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
log.Printf("reading body")
body, _ := ioutil.ReadAll(req.Body)
log.Printf("read body: %s", string(body))
// causes server to close connection on Go 1.4.3
req.Body.Close()
}))
if err != nil {
log.Fatal(err)
}
}
@dtjm
Copy link
Author

dtjm commented Apr 17, 2017

Send a post body like this to trigger the connection close:

curl localhost:10000 -i -X POST -d "SDFF"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment