Skip to content

Commit

Permalink
add supprt for go1.20 http.rwUnwrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
imxyb authored and aldas committed Apr 6, 2023
1 parent c0bc886 commit a7802ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return r.Writer.(http.Hijacker).Hijack()
}

// Unwrap returns the original http.ResponseWriter.
// ResponseController can be used to access the original http.ResponseWriter.
// See [https://go.dev/blog/go1.20]
func (r *Response) Unwrap() http.ResponseWriter {
return r.Writer
}

func (r *Response) reset(w http.ResponseWriter) {
r.beforeFuncs = nil
r.afterFuncs = nil
Expand Down
8 changes: 8 additions & 0 deletions response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,11 @@ func TestResponse_ChangeStatusCodeBeforeWrite(t *testing.T) {

assert.Equal(t, http.StatusOK, rec.Code)
}

func TestResponse_Unwrap(t *testing.T) {
e := New()
rec := httptest.NewRecorder()
res := &Response{echo: e, Writer: rec}

assert.Equal(t, rec, res.Unwrap())
}

0 comments on commit a7802ea

Please sign in to comment.