Skip to content

Commit b29f7cf

Browse files
Dean KarnDean Karn
authored andcommitted
update NativeHandlerChain to avoid a shallow copy
- updated to avoid shallow copies with context
1 parent ea42f83 commit b29f7cf

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
##LARS
22
<img align="right" src="https://github.com/raw/go-playground/lars/master/examples/README/test.gif">
3-
![Project status](https://img.shields.io/badge/version-3.5.0-green.svg)
3+
![Project status](https://img.shields.io/badge/version-3.6.0-green.svg)
44
[![Build Status](https://semaphoreci.com/api/v1/projects/4351aa2d-2f94-40be-a6ef-85c248490378/679708/badge.svg)](https://semaphoreci.com/joeybloggs/lars)
55
[![Coverage Status](https://coveralls.io/repos/github/go-playground/lars/badge.svg?branch=master)](https://coveralls.io/github/go-playground/lars?branch=master)
66
[![Go Report Card](https://goreportcard.com/badge/go-playground/lars)](https://goreportcard.com/report/go-playground/lars)

context_17.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (c *Ctx) RequestStart(w http.ResponseWriter, r *http.Request) {
8383
// golang.org/x/net/context contained on this Context.
8484
// It is a shortcut for context.WithValue(..., ...)
8585
func (c *Ctx) Set(key interface{}, value interface{}) {
86-
*c.request = *c.request.WithContext(context.WithValue(c.request.Context(), key, value)) // temporarily shallow copying to avoid problems with external libraries
86+
c.request = c.request.WithContext(context.WithValue(c.request.Context(), key, value)) // temporarily shallow copying to avoid problems with external libraries
8787
}
8888

8989
// Get returns the value for the given key and is a shortcut
@@ -108,7 +108,7 @@ func (c *Ctx) Context() context.Context {
108108
// WithContext updates the underlying request's context with to ctx
109109
// The provided ctx must be non-nil.
110110
func (c *Ctx) WithContext(ctx context.Context) {
111-
*c.request = *c.request.WithContext(ctx) // temporarily shallow copying to avoid problems with external libraries
111+
c.request = c.request.WithContext(ctx) // temporarily shallow copying to avoid problems with external libraries
112112
}
113113

114114
// Deadline calls the underlying golang.org/x/net/context Deadline()
@@ -135,29 +135,29 @@ func (c *Ctx) Value(key interface{}) interface{} {
135135
// updates context on the containing las.Context object.
136136
func (c *Ctx) WithCancel() context.CancelFunc {
137137
ctx, cf := context.WithCancel(c.request.Context())
138-
*c.request = *c.request.WithContext(ctx) // temporarily shallow copying to avoid problems with external libraries
138+
c.request = c.request.WithContext(ctx) // temporarily shallow copying to avoid problems with external libraries
139139
return cf
140140
}
141141

142142
// WithDeadline calls golang.org/x/net/context WithDeadline and automatically
143143
// updates context on the containing las.Context object.
144144
func (c *Ctx) WithDeadline(deadline time.Time) context.CancelFunc {
145145
ctx, cf := context.WithDeadline(c.request.Context(), deadline)
146-
*c.request = *c.request.WithContext(ctx) // temporarily shallow copying to avoid problems with external libraries
146+
c.request = c.request.WithContext(ctx) // temporarily shallow copying to avoid problems with external libraries
147147
return cf
148148
}
149149

150150
// WithTimeout calls golang.org/x/net/context WithTimeout and automatically
151151
// updates context on the containing las.Context object.
152152
func (c *Ctx) WithTimeout(timeout time.Duration) context.CancelFunc {
153153
ctx, cf := context.WithTimeout(c.request.Context(), timeout)
154-
*c.request = *c.request.WithContext(ctx) // temporarily shallow copying to avoid problems with external libraries
154+
c.request = c.request.WithContext(ctx) // temporarily shallow copying to avoid problems with external libraries
155155
return cf
156156
}
157157

158158
// WithValue calls golang.org/x/net/context WithValue and automatically
159159
// updates context on the containing las.Context object.
160160
// Can also use Set() function on Context object (Recommended)
161161
func (c *Ctx) WithValue(key interface{}, val interface{}) {
162-
*c.request = *c.request.WithContext(context.WithValue(c.request.Context(), key, val)) // temporarily shallow copying to avoid problems with external libraries
162+
c.request = c.request.WithContext(context.WithValue(c.request.Context(), key, val)) // temporarily shallow copying to avoid problems with external libraries
163163
}

util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var NativeChainHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Re
1515
c := GetContext(w)
1616
b := c.BaseContext()
1717

18-
*b.request = *r
18+
b.request = r
1919

2020
if b.index+1 < len(b.handlers) {
2121
c.Next()

0 commit comments

Comments
 (0)