make the responseWriter hijackable

This commit is contained in:
Marten Seemann 2022-03-27 17:52:39 +01:00
parent a983db0301
commit ff6313fdb3
4 changed files with 13 additions and 6 deletions

View file

@ -23,6 +23,7 @@ type DataStreamer interface {
}
type responseWriter struct {
conn quic.Connection
stream quic.Stream // needed for DataStream()
bufferedStream *bufio.Writer
@ -38,12 +39,14 @@ var (
_ http.ResponseWriter = &responseWriter{}
_ http.Flusher = &responseWriter{}
_ DataStreamer = &responseWriter{}
_ Hijacker = &responseWriter{}
)
func newResponseWriter(stream quic.Stream, logger utils.Logger) *responseWriter {
func newResponseWriter(stream quic.Stream, conn quic.Connection, logger utils.Logger) *responseWriter {
return &responseWriter{
header: http.Header{},
stream: stream,
conn: conn,
bufferedStream: bufio.NewWriter(stream),
logger: logger,
}
@ -123,6 +126,10 @@ func (w *responseWriter) StreamID() quic.StreamID {
return w.stream.StreamID()
}
func (w *responseWriter) StreamCreator() StreamCreator {
return w.conn
}
// copied from http2/http2.go
// bodyAllowedForStatus reports whether a given response status code
// permits a body. See RFC 2616, section 4.4.