-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
context: inherits context cancelation and deadline from http.Request …
…context for Go>=1.7 (#1690) *gin.Context implements standard context.Context methods, but always returns data as context is still valid. Since Go 1.7, http.Request now contains a context.Context object, which can be controlled by the http.Server to indicates that the context is now closed, and persue of request should be canceled. This implements the propagation of http.Request context methods inside gin.Context to have HTTP context cancelation information at gin.Context level. Signed-off-by: Romain Beuque <romain.beuque@corp.ovh.com>
- Loading branch information
Showing
4 changed files
with
118 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2018 Gin Core Team. All rights reserved. | ||
// Use of this source code is governed by a MIT style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build !go1.7 | ||
|
||
package gin | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
/************************************/ | ||
/***** GOLANG.ORG/X/NET/CONTEXT *****/ | ||
/************************************/ | ||
|
||
// Deadline returns the time when work done on behalf of this context | ||
// should be canceled. Deadline returns ok==false when no deadline is | ||
// set. Successive calls to Deadline return the same results. | ||
func (c *Context) Deadline() (deadline time.Time, ok bool) { | ||
return | ||
} | ||
|
||
// Done returns a channel that's closed when work done on behalf of this | ||
// context should be canceled. Done may return nil if this context can | ||
// never be canceled. Successive calls to Done return the same value. | ||
func (c *Context) Done() <-chan struct{} { | ||
return nil | ||
} | ||
|
||
// Err returns a non-nil error value after Done is closed, | ||
// successive calls to Err return the same error. | ||
// If Done is not yet closed, Err returns nil. | ||
// If Done is closed, Err returns a non-nil error explaining why: | ||
// Canceled if the context was canceled | ||
// or DeadlineExceeded if the context's deadline passed. | ||
func (c *Context) Err() error { | ||
return nil | ||
} |