Merge 39e1cae4073c5fa466c7e33e3ead672099144c96 into 0f09c3a9b4626d9fe9979cf4d0521d6ae32ab646

This commit is contained in:
ViktorBystrov72 2026-11-12 10:10:58 +05:00 committed by GitHub
commit 07474057a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -117,8 +117,11 @@ func (c *Context) reset() {
*c.skippedNodes = (*c.skippedNodes)[:0]
}
// Copy returns a copy of the current context that can be safely used outside the request's scope.
// Copy returns a copy of the current context for use outside the request's scope.
// This has to be used when the context has to be passed to a goroutine.
//
// The copy's underlying http.ResponseWriter is nil, so it cannot write the HTTP response.
// Do not call response-writing methods such as JSON, String, or Stream on the copy.
func (c *Context) Copy() *Context {
cp := Context{
writermem: c.writermem,

View File

@ -617,6 +617,8 @@ func main() {
When starting new Goroutines inside a middleware or handler, you **SHOULD NOT** use the original context inside it, you have to use a read-only copy.
The copy's underlying `http.ResponseWriter` is `nil`, so it cannot write the HTTP response. Do not call response-writing methods such as `JSON`, `String`, or `Stream` on the copy. Write the response from the original handler before it returns.
```go
func main() {
r := gin.Default()