Skip to content

Commit

Permalink
Make the ErrNothingRead to be exposed. (#827)
Browse files Browse the repository at this point in the history
* Make the ErrNothingRead to be exposed.

* Update header.go

update annotation.

Co-authored-by: Erik Dubbelboer <erik@dubbelboer.com>
  • Loading branch information
wangfakang and erikdubbelboer committed Jun 5, 2020
1 parent 853abb3 commit ac51d59
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ func (h *RequestHeader) tryRead(r *bufio.Reader, n int) error {
// n == 1 on the first read for the request.
if n == 1 {
// We didn't read a single byte.
return errNothingRead{err}
return ErrNothingRead{err}
}

return fmt.Errorf("error when reading request headers: %s", err)
Expand Down Expand Up @@ -2247,7 +2247,9 @@ var (
errSmallBuffer = errors.New("small read buffer. Increase ReadBufferSize")
)

type errNothingRead struct {
// ErrNothingRead is returned when a keep-alive connection is closed,
// either because the remote closed it or because of a read timeout.
type ErrNothingRead struct {
error
}

Expand Down
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ func (s *Server) serveConn(c net.Conn) (err error) {
// If reading from a keep-alive connection returns nothing it means
// the connection was closed (either timeout or from the other side).
if err != io.EOF {
err = errNothingRead{err}
err = ErrNothingRead{err}
}
}
}
Expand Down Expand Up @@ -2077,7 +2077,7 @@ func (s *Server) serveConn(c net.Conn) (err error) {
if err != nil {
if err == io.EOF {
err = nil
} else if nr, ok := err.(errNothingRead); ok {
} else if nr, ok := err.(ErrNothingRead); ok {
if connRequestNum > 1 {
// This is not the first request and we haven't read a single byte
// of a new request yet. This means it's just a keep-alive connection
Expand Down

0 comments on commit ac51d59

Please sign in to comment.