add ability to close connection for serve-host

pull/564/head
Minhan Xia 2018-11-06 13:27:22 -08:00
parent e26f5d19d4
commit 0fb2da902b
2 changed files with 12 additions and 5 deletions

View File

@ -1 +1 @@
1.1
1.2

View File

@ -33,6 +33,7 @@ var (
doTCP = flag.Bool("tcp", false, "Serve raw over TCP.")
doUDP = flag.Bool("udp", false, "Serve raw over UDP.")
doHTTP = flag.Bool("http", true, "Serve HTTP.")
doClose = flag.Bool("close", false, "Close connection per each HTTP request")
port = flag.Int("port", 9376, "Port number.")
)
@ -88,6 +89,12 @@ func main() {
if *doHTTP {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Printf("HTTP request from %s", r.RemoteAddr)
if *doClose {
// Add this header to force to close the connection after serving the request.
w.Header().Add("Connection", "close")
}
fmt.Fprintf(w, "%s", hostname)
})
go func() {