aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/http.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-05-15 01:39:57 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-05-15 01:39:57 +0800
commit5c6540452ac49db3defdfa1e141b4acf8eaaaad7 (patch)
tree937c21378a762f13ba25897aa7db3e6a7bb1ca89 /rpc/http.go
parentf7fdb4dfbe1a0851b6fb2970b0a6b11fd31273d6 (diff)
downloadgo-tangerine-5c6540452ac49db3defdfa1e141b4acf8eaaaad7.tar
go-tangerine-5c6540452ac49db3defdfa1e141b4acf8eaaaad7.tar.gz
go-tangerine-5c6540452ac49db3defdfa1e141b4acf8eaaaad7.tar.bz2
go-tangerine-5c6540452ac49db3defdfa1e141b4acf8eaaaad7.tar.lz
go-tangerine-5c6540452ac49db3defdfa1e141b4acf8eaaaad7.tar.xz
go-tangerine-5c6540452ac49db3defdfa1e141b4acf8eaaaad7.tar.zst
go-tangerine-5c6540452ac49db3defdfa1e141b4acf8eaaaad7.zip
Omit replies for notification requests
When Id is missing, the client does not want a response
Diffstat (limited to 'rpc/http.go')
-rw-r--r--rpc/http.go25
1 files changed, 22 insertions, 3 deletions
diff --git a/rpc/http.go b/rpc/http.go
index c5bb10c80..9220c730c 100644
--- a/rpc/http.go
+++ b/rpc/http.go
@@ -87,7 +87,9 @@ func JSONRPC(pipe *xeth.XEth) http.Handler {
var reqSingle RpcRequest
if err := json.Unmarshal(body, &reqSingle); err == nil {
response := RpcResponse(api, &reqSingle)
- send(w, &response)
+ if reqSingle.Id != nil {
+ send(w, &response)
+ }
return
}
@@ -96,11 +98,28 @@ func JSONRPC(pipe *xeth.XEth) http.Handler {
if err := json.Unmarshal(body, &reqBatch); err == nil {
// Build response batch
resBatch := make([]*interface{}, len(reqBatch))
+ resCount := 0
+
for i, request := range reqBatch {
response := RpcResponse(api, &request)
- resBatch[i] = response
+ // this leaves nil entries in the response batch for later removal
+ if request.Id != nil {
+ resBatch[i] = response
+ resCount = resCount + 1
+ }
}
- send(w, resBatch)
+
+ // make response omitting nil entries
+ respBatchComp := make([]*interface{}, resCount)
+ resCount = resCount - 1
+ for _, v := range resBatch {
+ if v != nil {
+ respBatchComp[resCount] = v
+ resCount = resCount - 1
+ }
+ }
+
+ send(w, respBatchComp)
return
}