1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-16 04:04:56 +02:00

Guard against nil handlers

This commit is contained in:
Jose Garcia 2021-11-25 16:30:23 +00:00 committed by GitHub
parent c9c77b6bb9
commit 4a67c7872c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -355,6 +355,7 @@ func (id *ID) UnmarshalJSON(data []byte) error {
type Conn struct {
stream ObjectStream
// If Handler is nil, incoming requests are skipped
h Handler
mu sync.Mutex
@ -620,7 +621,11 @@ func (c *Conn) readMessages(ctx context.Context) {
for _, onRecv := range c.onRecv {
onRecv(m.request, nil)
}
c.h.Handle(ctx, c, m.request)
// If handler is not nil, handle the request.
if c.h != nil {
c.h.Handle(ctx, c, m.request)
}
case m.response != nil:
resp := m.response