You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to write a middleware to intercept the response body and recover the response body ,I think that go use the responseWriter interface to io the response ,but it seems so hard to rewrite the body,
The text was updated successfully, but these errors were encountered:
jimmy-yu-1990
changed the title
How do I recover the body of the response body by the middleware,this question has perplex me long days,please help me,thank you all the same
How do I recover the body of the response body by the middleware,this question has perplex me a few days,please help me,thank you all the same
Oct 16, 2021
I believe that the standard ResponseWriter writes directly to the HTTP response, so you couldn't extract the response body from it. You could however replace the Writer field in gin.Context with your own implementation of a ResponseWriter. For example some kind of wrapper around the default writer that would buffer the response, transform it, etc.
One way to go about it would be to create a struct like:
typeMyResponseWriter {
gin.ResponseWriter
}
// implement all the methods you need to overridefunc (w*MyResponseWriter) Write([]byte) (int, error) { ... }
Description
I want to write a middleware to intercept the response body and recover the response body ,I think that go use the responseWriter interface to io the response ,but it seems so hard to rewrite the body,
relation
https://stackoverflow.com/questions/33606330/golang-rewrite-http-request-body
The text was updated successfully, but these errors were encountered: