simplify stream handling in the http3.Server

This commit is contained in:
Marten Seemann 2020-06-02 14:39:48 +07:00
parent c8e5bb5b50
commit 5720053807
2 changed files with 5 additions and 8 deletions

View file

@ -276,7 +276,7 @@ func (s *Server) handleRequest(sess quic.Session, str quic.Stream, decoder *qpac
handler = http.DefaultServeMux
}
var panicked, readEOF bool
var panicked bool
func() {
defer func() {
if p := recover(); p != nil {
@ -289,10 +289,6 @@ func (s *Server) handleRequest(sess quic.Session, str quic.Stream, decoder *qpac
}
}()
handler.ServeHTTP(responseWriter, req)
// read the eof
if _, err = str.Read([]byte{0}); err == io.EOF {
readEOF = true
}
}()
if panicked {
@ -301,9 +297,8 @@ func (s *Server) handleRequest(sess quic.Session, str quic.Stream, decoder *qpac
responseWriter.WriteHeader(200)
}
if !readEOF {
// If the EOF was read by the handler, CancelRead() is a no-op.
str.CancelRead(quic.ErrorCode(errorEarlyResponse))
}
return requestError{}
}

View file

@ -122,6 +122,7 @@ var _ = Describe("Server", func() {
str.EXPECT().Write(gomock.Any()).DoAndReturn(func(p []byte) (int, error) {
return len(p), nil
}).AnyTimes()
str.EXPECT().CancelRead(gomock.Any())
Expect(s.handleRequest(sess, str, qpackDecoder, nil)).To(Equal(requestError{}))
var req *http.Request
@ -140,6 +141,7 @@ var _ = Describe("Server", func() {
str.EXPECT().Write(gomock.Any()).DoAndReturn(func(p []byte) (int, error) {
return responseBuf.Write(p)
}).AnyTimes()
str.EXPECT().CancelRead(gomock.Any())
serr := s.handleRequest(sess, str, qpackDecoder, nil)
Expect(serr.err).ToNot(HaveOccurred())