Skip to content

chore(response_writer): add Unwrap() method to ResponseWriter interface - #4506

Open
raju-mechatronics wants to merge 3 commits into
gin-gonic:masterfrom
raju-mechatronics:responsewriter/unwrap
Open

raju-mechatronics wants to merge 3 commits into
gin-gonic:masterfrom
raju-mechatronics:responsewriter/unwrap

Conversation

@raju-mechatronics

Copy link
Copy Markdown
Contributor

Description

This PR adds the Unwrap() http.ResponseWriter method to the exported ResponseWriter interface.

Motivation

  • The concrete *responseWriter type already implements Unwrap().
  • However the interface does not declare it.
  • This creates an inconsistency: code that receives a gin.ResponseWriter cannot safely/portably call .Unwrap().
  • Passing the underlying http.ResponseWriter to third-party handlers/middleware (c.Writer.Unwrap())

Adding it to the interface makes usage more idiomatic and type-safe.

// returns underlying http.ResponseWriter
responseWriter := c.Writer.Unwrap()

@codecov

codecov Bot commented Jan 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.65%. Comparing base (0f09c3a) to head (7b06809).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4506   +/-   ##
=======================================
  Coverage   98.65%   98.65%           
=======================================
  Files          48       48           
  Lines        3188     3188           
=======================================
  Hits         3145     3145           
  Misses         43       43           
Flag Coverage Δ
--ldflags="-checklinkname=0" -tags sonic 98.64% <ø> (ø)
-tags go_json 98.57% <ø> (ø)
-tags nomsgpack 98.63% <ø> (ø)
go-1.26 98.33% <ø> (ø)
go-1.27 98.67% <ø> (ø)
macos-latest 98.65% <ø> (ø)
ubuntu-latest 98.65% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@raju-mechatronics

Copy link
Copy Markdown
Contributor Author

@appleboy is this useful? The unwrap function is already implemented. I just exposed it via the ResponseWriter interface.

@appleboy

Copy link
Copy Markdown
Member

@raju-mechatronics Please write the unit testing.

@appleboy appleboy added this to the v1.13 milestone Mar 21, 2026
@raju-mechatronics

Copy link
Copy Markdown
Contributor Author

@raju-mechatronics Please write the unit testing.

sure. I'll add the unit tests soon and push the update.

@raju-mechatronics

Copy link
Copy Markdown
Contributor Author

@raju-mechatronics Please write the unit testing.

Added unit tests for the Unwrap() method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants