-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I intercept the response? #3582
Comments
I found that when calling func middleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Next()
fmt.Println("Response is not sent. Although it is not sent, you cannot modify the status code.")
time.Sleep(3 * time.Second)
fmt.Println("response sended!")
}
} |
This seems tangentially related to #3576. |
@asbjornu It may be related. In my issue, once the status code is set, it cannot be set again forever. I personally feel that this is a very unreasonable situation. |
@BlackHole1 you not being able to set the status code seems related to me not being able to set Also, I don't quite remember where I read it or the details of why it was, but I seem to recall that changing |
Description
Could I intercept the response before it's sent? Similar to "PreSendResponse". This is a common requirement as there may be a possibility of failure after calling the middleware's
c.Next()
function, and I need to rewrite theStatus Code
. However, the request may have already been sent, and I cannot rewrite it. Here's a sample pseudocode that uses the DynamoDB database and executes a transaction commit after callingc.Next()
. Once the transaction commit fails, I need to rewrite theStatus Code
andResponse Body
.The following is the code I wrote a simulation of this demand:
Expectations
Actual result
Environment
The text was updated successfully, but these errors were encountered: