Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to close connection for serve-host #70714

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/images/serve-hostname/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1
1.2
15 changes: 11 additions & 4 deletions test/images/serve-hostname/serve_hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import (
)

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.")
port = flag.Int("port", 9376, "Port number.")
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.")
)

func main() {
Expand Down Expand Up @@ -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() {
Expand Down