Fix for issue #2460

This commit is contained in:
lihaowei 2020-08-15 12:00:40 +08:00
parent b94d23d1b4
commit 8321affbca

View File

@ -102,6 +102,7 @@ func (c *Context) reset() {
// 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 that can be safely used outside the request's scope.
// This has to be used when the context has to be passed to a goroutine. // This has to be used when the context has to be passed to a goroutine.
func (c *Context) Copy() *Context { func (c *Context) Copy() *Context {
c.mu.Lock()
cp := Context{ cp := Context{
writermem: c.writermem, writermem: c.writermem,
Request: c.Request, Request: c.Request,
@ -119,6 +120,7 @@ func (c *Context) Copy() *Context {
paramCopy := make([]Param, len(cp.Params)) paramCopy := make([]Param, len(cp.Params))
copy(paramCopy, cp.Params) copy(paramCopy, cp.Params)
cp.Params = paramCopy cp.Params = paramCopy
c.mu.Unlock()
return &cp return &cp
} }
@ -957,7 +959,7 @@ func (c *Context) File(filepath string) {
http.ServeFile(c.Writer, c.Request, filepath) http.ServeFile(c.Writer, c.Request, filepath)
} }
// FileFromFS writes the specified file from http.FileSytem into the body stream in an efficient way. // FileFromFS writes the specified file from http.FileSystem into the body stream in an efficient way.
func (c *Context) FileFromFS(filepath string, fs http.FileSystem) { func (c *Context) FileFromFS(filepath string, fs http.FileSystem) {
defer func(old string) { defer func(old string) {
c.Request.URL.Path = old c.Request.URL.Path = old