Skip to content

Commit d44088f

Browse files
odeke-embradfitz
authored andcommitted
net/http: refactored internal shouldClose for readability
Change-Id: Ie89c0945a4cc3aebfa9f7ad7f107bc7ab59ab61c Reviewed-on: https://go-review.googlesource.com/19685 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent db44223 commit d44088f

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/net/http/transfer.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -558,21 +558,19 @@ func fixLength(isResponse bool, status int, requestMethod string, header Header,
558558
func shouldClose(major, minor int, header Header, removeCloseHeader bool) bool {
559559
if major < 1 {
560560
return true
561-
} else if major == 1 && minor == 0 {
562-
vv := header["Connection"]
563-
if headerValuesContainsToken(vv, "close") || !headerValuesContainsToken(vv, "keep-alive") {
564-
return true
565-
}
566-
return false
567-
} else {
568-
if headerValuesContainsToken(header["Connection"], "close") {
569-
if removeCloseHeader {
570-
header.Del("Connection")
571-
}
572-
return true
573-
}
574561
}
575-
return false
562+
563+
conv := header["Connection"]
564+
hasClose := headerValuesContainsToken(conv, "close")
565+
if major == 1 && minor == 0 {
566+
return hasClose || !headerValuesContainsToken(conv, "keep-alive")
567+
}
568+
569+
if hasClose && removeCloseHeader {
570+
header.Del("Connection")
571+
}
572+
573+
return hasClose
576574
}
577575

578576
// Parse the trailer header

0 commit comments

Comments
 (0)