Skip to content

Commit

Permalink
net/http: close connection if Connection: close is set
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajunhuang committed Nov 24, 2018
1 parent 04105ef commit e956b9c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/net/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,10 @@ func (w *response) WriteHeader(code int) {
w.handlerHeader.Del("Content-Length")
}
}

if w.handlerHeader.get("Connection") == "close" {
w.closeAfterReply = true
}
}

// extraHeader is the set of headers sometimes added by chunkWriter.writeHeader.
Expand Down Expand Up @@ -1540,6 +1544,10 @@ func (w *response) bodyAllowed() bool {
// bufferBeforeChunkingSize smaller and having bufio's fast-paths deal
// with this instead.
func (w *response) Write(data []byte) (n int, err error) {
if w.closeAfterReply {
defer w.conn.Close()
}

return w.write(len(data), data, "")
}

Expand Down

0 comments on commit e956b9c

Please sign in to comment.