Skip to content

Commit a7802ea

Browse files
imxybaldas
authored andcommitted
add supprt for go1.20 http.rwUnwrapper
1 parent c0bc886 commit a7802ea

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

response.go

+7
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error) {
9494
return r.Writer.(http.Hijacker).Hijack()
9595
}
9696

97+
// Unwrap returns the original http.ResponseWriter.
98+
// ResponseController can be used to access the original http.ResponseWriter.
99+
// See [https://go.dev/blog/go1.20]
100+
func (r *Response) Unwrap() http.ResponseWriter {
101+
return r.Writer
102+
}
103+
97104
func (r *Response) reset(w http.ResponseWriter) {
98105
r.beforeFuncs = nil
99106
r.afterFuncs = nil

response_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,11 @@ func TestResponse_ChangeStatusCodeBeforeWrite(t *testing.T) {
7272

7373
assert.Equal(t, http.StatusOK, rec.Code)
7474
}
75+
76+
func TestResponse_Unwrap(t *testing.T) {
77+
e := New()
78+
rec := httptest.NewRecorder()
79+
res := &Response{echo: e, Writer: rec}
80+
81+
assert.Equal(t, rec, res.Unwrap())
82+
}

0 commit comments

Comments
 (0)