Skip to content

Commit

Permalink
Merge pull request #273 from rykov/master
Browse files Browse the repository at this point in the history
Added ResponseWriter.Unwrap() for ResponseController
  • Loading branch information
jszwedko authored Mar 18, 2023
2 parents dc8359a + 59d32aa commit b935227
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func (rw *responseWriter) ReadFrom(r io.Reader) (n int64, err error) {
return
}

// Satisfy http.ResponseController support (Go 1.20+)
func (rw *responseWriter) Unwrap() http.ResponseWriter {
return rw.ResponseWriter
}

func (rw *responseWriter) Status() int {
if rw.Written() {
return rw.status
Expand Down
11 changes: 11 additions & 0 deletions response_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ func TestResponseWriterBefore(t *testing.T) {
expect(t, result, "barfoo")
}

func TestResponseWriterUnwrap(t *testing.T) {
rec := httptest.NewRecorder()
rw := NewResponseWriter(rec)
switch v := rw.(type) {
case interface{ Unwrap() http.ResponseWriter }:
expect(t, v.Unwrap(), rec)
default:
t.Error("Does not implement Unwrap()")
}
}

func TestResponseWriterHijack(t *testing.T) {
hijackable := newHijackableResponse()
rw := NewResponseWriter(hijackable)
Expand Down

0 comments on commit b935227

Please sign in to comment.