forked from quic-go/quic-go
http3: add ConnContext to the server (#4230)
* Add ConnContext to http3.Server ConnContext can be used to modify the context used by a new http Request. * Make linter happy * Add nil check and integration test * Add the ServerContextKey check to the ConnContext func * Update integrationtests/self/http_test.go Co-authored-by: Marten Seemann <martenseemann@gmail.com> * Update http3/server.go Co-authored-by: Marten Seemann <martenseemann@gmail.com> --------- Co-authored-by: Marten Seemann <martenseemann@gmail.com>
This commit is contained in:
@@ -67,11 +67,15 @@ var _ = Describe("Server", func() {
|
||||
s *Server
|
||||
origQuicListenAddr = quicListenAddr
|
||||
)
|
||||
type testConnContextKey string
|
||||
|
||||
BeforeEach(func() {
|
||||
s = &Server{
|
||||
TLSConfig: testdata.GetTLSConfig(),
|
||||
logger: utils.DefaultLogger,
|
||||
ConnContext: func(ctx context.Context, c quic.Connection) context.Context {
|
||||
return context.WithValue(ctx, testConnContextKey("test"), c)
|
||||
},
|
||||
}
|
||||
origQuicListenAddr = quicListenAddr
|
||||
})
|
||||
@@ -163,6 +167,7 @@ var _ = Describe("Server", func() {
|
||||
Expect(req.Host).To(Equal("www.example.com"))
|
||||
Expect(req.RemoteAddr).To(Equal("127.0.0.1:1337"))
|
||||
Expect(req.Context().Value(ServerContextKey)).To(Equal(s))
|
||||
Expect(req.Context().Value(testConnContextKey("test"))).ToNot(Equal(nil))
|
||||
})
|
||||
|
||||
It("returns 200 with an empty handler", func() {
|
||||
|
||||
Reference in New Issue
Block a user