mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 04:37:36 +03:00
simplify stream handling in the http3.Server
This commit is contained in:
parent
c8e5bb5b50
commit
5720053807
2 changed files with 5 additions and 8 deletions
|
@ -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 {
|
||||
str.CancelRead(quic.ErrorCode(errorEarlyResponse))
|
||||
}
|
||||
// If the EOF was read by the handler, CancelRead() is a no-op.
|
||||
str.CancelRead(quic.ErrorCode(errorEarlyResponse))
|
||||
return requestError{}
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue