http3: add compatibility with net/http.ResponseController (#3790)

* feat: compatibility with "net/http".ResponseController

* better deadline tests

* don't run deadline tests on Go 1.19

* skip deadline tests on Go 1.19
This commit is contained in:
Kévin Dunglas
2023-05-01 13:40:33 +02:00
committed by GitHub
parent 4a2a5740b2
commit 172123c340
5 changed files with 129 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import (
"net/http"
"strconv"
"strings"
"time"
"github.com/quic-go/quic-go"
"github.com/quic-go/quic-go/internal/utils"
@@ -15,6 +16,7 @@ import (
type responseWriter struct {
conn quic.Connection
str quic.Stream
bufferedStr *bufio.Writer
buf []byte
@@ -36,6 +38,7 @@ func newResponseWriter(str quic.Stream, conn quic.Connection, logger utils.Logge
header: http.Header{},
buf: make([]byte, 16),
conn: conn,
str: str,
bufferedStr: bufio.NewWriter(str),
logger: logger,
}
@@ -121,6 +124,14 @@ func (w *responseWriter) StreamCreator() StreamCreator {
return w.conn
}
func (w *responseWriter) SetReadDeadline(deadline time.Time) error {
return w.str.SetReadDeadline(deadline)
}
func (w *responseWriter) SetWriteDeadline(deadline time.Time) error {
return w.str.SetWriteDeadline(deadline)
}
// copied from http2/http2.go
// bodyAllowedForStatus reports whether a given response status code
// permits a body. See RFC 2616, section 4.4.