forked from quic-go/quic-go
http3: don't write response headers if the handler panicked (#3950)
This commit is contained in:
@@ -594,7 +594,6 @@ func (s *Server) handleRequest(conn quic.Connection, str quic.Stream, decoder *q
|
||||
ctx = context.WithValue(ctx, http.LocalAddrContextKey, conn.LocalAddr())
|
||||
req = req.WithContext(ctx)
|
||||
r := newResponseWriter(str, conn, s.logger)
|
||||
defer r.Flush()
|
||||
handler := s.Handler
|
||||
if handler == nil {
|
||||
handler = http.DefaultServeMux
|
||||
@@ -622,10 +621,10 @@ func (s *Server) handleRequest(conn quic.Connection, str quic.Stream, decoder *q
|
||||
return requestError{err: errHijacked}
|
||||
}
|
||||
|
||||
if panicked {
|
||||
r.WriteHeader(http.StatusInternalServerError)
|
||||
} else {
|
||||
// only write response when there is no panic
|
||||
if !panicked {
|
||||
r.WriteHeader(http.StatusOK)
|
||||
r.Flush()
|
||||
}
|
||||
// If the EOF was read by the handler, CancelRead() is a no-op.
|
||||
str.CancelRead(quic.StreamErrorCode(ErrCodeNoError))
|
||||
|
||||
@@ -193,8 +193,7 @@ var _ = Describe("Server", func() {
|
||||
|
||||
serr := s.handleRequest(conn, str, qpackDecoder, nil)
|
||||
Expect(serr.err).ToNot(HaveOccurred())
|
||||
hfs := decodeHeader(responseBuf)
|
||||
Expect(hfs).To(HaveKeyWithValue(":status", []string{"500"}))
|
||||
Expect(responseBuf.Bytes()).To(HaveLen(0))
|
||||
})
|
||||
|
||||
It("handles a panicking handler", func() {
|
||||
@@ -210,8 +209,7 @@ var _ = Describe("Server", func() {
|
||||
|
||||
serr := s.handleRequest(conn, str, qpackDecoder, nil)
|
||||
Expect(serr.err).ToNot(HaveOccurred())
|
||||
hfs := decodeHeader(responseBuf)
|
||||
Expect(hfs).To(HaveKeyWithValue(":status", []string{"500"}))
|
||||
Expect(responseBuf.Bytes()).To(HaveLen(0))
|
||||
})
|
||||
|
||||
Context("hijacking bidirectional streams", func() {
|
||||
|
||||
Reference in New Issue
Block a user