From a7802ea523e56c79a1b9e9620c48d68bcff5212e Mon Sep 17 00:00:00 2001 From: imxyb Date: Tue, 28 Mar 2023 17:25:11 +0800 Subject: [PATCH] add supprt for go1.20 http.rwUnwrapper --- response.go | 7 +++++++ response_test.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/response.go b/response.go index 84f7c9e7..d9c9aa6e 100644 --- a/response.go +++ b/response.go @@ -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 diff --git a/response_test.go b/response_test.go index d95e079f..e4fd636d 100644 --- a/response_test.go +++ b/response_test.go @@ -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()) +}