Skip to content

Commit 953fdfd

Browse files
committed
add a regression test
1 parent 827fb3f commit 953fdfd

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/net/http/serve_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6126,6 +6126,39 @@ func TestServerContextsHTTP2(t *testing.T) {
61266126
}
61276127
}
61286128

6129+
// Issue 35750: check ConnContext not modifying context for other connections
6130+
func TestConnContextNotModifyingAllContexts(t *testing.T) {
6131+
setParallel(t)
6132+
defer afterTest(t)
6133+
type connKey struct{}
6134+
ts := httptest.NewUnstartedServer(HandlerFunc(func(rw ResponseWriter, r *Request) {
6135+
rw.Header().Set("Connection", "close")
6136+
}))
6137+
ts.Config.ConnContext = func(ctx context.Context, c net.Conn) context.Context {
6138+
if got := ctx.Value(connKey{}); got != nil {
6139+
t.Errorf("in ConnContext, unexpected context key = %#v", got)
6140+
}
6141+
return context.WithValue(ctx, connKey{}, "conn")
6142+
}
6143+
ts.Start()
6144+
defer ts.Close()
6145+
6146+
var res *Response
6147+
var err error
6148+
6149+
res, err = ts.Client().Get(ts.URL)
6150+
if err != nil {
6151+
t.Fatal(err)
6152+
}
6153+
res.Body.Close()
6154+
6155+
res, err = ts.Client().Get(ts.URL)
6156+
if err != nil {
6157+
t.Fatal(err)
6158+
}
6159+
res.Body.Close()
6160+
}
6161+
61296162
// Issue 30710: ensure that as per the spec, a server responds
61306163
// with 501 Not Implemented for unsupported transfer-encodings.
61316164
func TestUnsupportedTransferEncodingsReturn501(t *testing.T) {

0 commit comments

Comments
 (0)