mirror of https://github.com/perkeep/perkeep.git
httputil: make CloseBody more robust
Change-Id: If46c60a5088f57ada45b8aa91ae29c8f512604c7
This commit is contained in:
parent
7c3afd2711
commit
2fde1c3632
|
@ -318,7 +318,15 @@ func CloseBody(rc io.ReadCloser) {
|
||||||
// Content-Length. Or maybe Go 1.3's Close itself would look
|
// Content-Length. Or maybe Go 1.3's Close itself would look
|
||||||
// to see if we're at EOF even if it hasn't been Read.
|
// to see if we're at EOF even if it hasn't been Read.
|
||||||
|
|
||||||
// TODO: use a bytepool package somewhere for these two bytes.
|
// TODO: use a bytepool package somewhere for this byte?
|
||||||
rc.Read(make([]byte, 2))
|
// Justification for 3 byte reads: two for up to "\r\n" after
|
||||||
|
// a JSON/XML document, and then 1 to see EOF if we haven't yet.
|
||||||
|
buf := make([]byte, 1)
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
_, err := rc.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
rc.Close()
|
rc.Close()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue