|
|
@@ -93,7 +93,7 @@ func newHandler(connCtx context.Context, conn jsonWriter, idgen func() ID, reg *
|
|
|
}
|
|
|
|
|
|
// handleBatch executes all messages in a batch and returns the responses.
|
|
|
-func (h *handler) handleBatch(msgs []*jsonrpcMessage) {
|
|
|
+func (h *handler) handleBatch(ctx context.Context, msgs []*jsonrpcMessage) {
|
|
|
// Emit error response for empty batches:
|
|
|
if len(msgs) == 0 {
|
|
|
h.startCallProc(func(cp *callProc) {
|
|
|
@@ -116,7 +116,7 @@ func (h *handler) handleBatch(msgs []*jsonrpcMessage) {
|
|
|
h.startCallProc(func(cp *callProc) {
|
|
|
answers := make([]*jsonrpcMessage, 0, len(msgs))
|
|
|
for _, msg := range calls {
|
|
|
- if answer := h.handleCallMsg(cp, msg); answer != nil {
|
|
|
+ if answer := h.handleCallMsg(cp, ctx, msg); answer != nil {
|
|
|
answers = append(answers, answer)
|
|
|
}
|
|
|
}
|
|
|
@@ -131,12 +131,12 @@ func (h *handler) handleBatch(msgs []*jsonrpcMessage) {
|
|
|
}
|
|
|
|
|
|
// handleMsg handles a single message.
|
|
|
-func (h *handler) handleMsg(msg *jsonrpcMessage) {
|
|
|
+func (h *handler) handleMsg(ctx context.Context, msg *jsonrpcMessage) {
|
|
|
if ok := h.handleImmediate(msg); ok {
|
|
|
return
|
|
|
}
|
|
|
h.startCallProc(func(cp *callProc) {
|
|
|
- answer := h.handleCallMsg(cp, msg)
|
|
|
+ answer := h.handleCallMsg(cp, ctx, msg)
|
|
|
h.addSubscriptions(cp.notifiers)
|
|
|
if answer != nil {
|
|
|
h.conn.writeJSON(cp.ctx, answer)
|
|
|
@@ -287,7 +287,7 @@ func (h *handler) handleResponse(msg *jsonrpcMessage) {
|
|
|
}
|
|
|
|
|
|
// handleCallMsg executes a call message and returns the answer.
|
|
|
-func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMessage {
|
|
|
+func (h *handler) handleCallMsg(ctx *callProc, reqCtx context.Context, msg *jsonrpcMessage) *jsonrpcMessage {
|
|
|
start := time.Now()
|
|
|
switch {
|
|
|
case msg.isNotification():
|
|
|
@@ -297,7 +297,8 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess
|
|
|
case msg.isCall():
|
|
|
resp := h.handleCall(ctx, msg)
|
|
|
if resp.Error != nil {
|
|
|
- h.log.Warn("Served "+msg.Method, "reqid", idForLog{msg.ID}, "t", time.Since(start), "err", resp.Error.Message)
|
|
|
+ xForward := reqCtx.Value("X-Forwarded-For")
|
|
|
+ h.log.Warn("Served "+msg.Method, "reqid", idForLog{msg.ID}, "t", time.Since(start), "err", resp.Error.Message, "X-Forwarded-For", xForward)
|
|
|
} else {
|
|
|
h.log.Debug("Served "+msg.Method, "reqid", idForLog{msg.ID}, "t", time.Since(start))
|
|
|
}
|