goproxy icon indicating copy to clipboard operation
goproxy copied to clipboard

/Mea culpa/ Bug in https.go, you treat err == "EOF" as error

Open stiray opened this issue 4 years ago • 2 comments

https://github.com/elazarl/goproxy/blob/0581fc3aee2d07555835bed1a876aca196a4a511/https.go#L267

This line here has inadequate checking, should be: if _, err := io.Copy(chunked, resp.Body); err != nil && "EOF" != err.Error() {

stiray avatar Oct 19 '20 10:10 stiray

https://golang.org/pkg/io/#Copy

A successful Copy returns err == nil, not err == EOF. Because Copy is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

onokonem avatar Oct 19 '20 10:10 onokonem

Argh, true, copy doesnt matches err.Error() but matches err pointer within copy so the only proper way of returning error from read is io.EOF.

stiray avatar Oct 19 '20 10:10 stiray