Make send internal

pull/543/merge
Taylor Gerring 10 years ago
parent c7b616ac14
commit abc3d8d50a
  1. 12
      rpc/http.go

@ -28,7 +28,7 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
// Limit request size to resist DoS // Limit request size to resist DoS
if req.ContentLength > maxSizeReqLength { if req.ContentLength > maxSizeReqLength {
jsonerr := &RpcErrorObject{-32700, "Request too large"} jsonerr := &RpcErrorObject{-32700, "Request too large"}
Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr}) send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr})
return return
} }
@ -37,14 +37,14 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
body, err := ioutil.ReadAll(req.Body) body, err := ioutil.ReadAll(req.Body)
if err != nil { if err != nil {
jsonerr := &RpcErrorObject{-32700, "Could not read request body"} jsonerr := &RpcErrorObject{-32700, "Could not read request body"}
Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr}) send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr})
} }
// Try to parse the request as a single // Try to parse the request as a single
var reqSingle RpcRequest var reqSingle RpcRequest
if err := json.Unmarshal(body, &reqSingle); err == nil { if err := json.Unmarshal(body, &reqSingle); err == nil {
response := RpcResponse(api, &reqSingle) response := RpcResponse(api, &reqSingle)
Send(w, &response) send(w, &response)
return return
} }
@ -57,13 +57,13 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
response := RpcResponse(api, &request) response := RpcResponse(api, &request)
resBatch[i] = response resBatch[i] = response
} }
Send(w, resBatch) send(w, resBatch)
return return
} }
// Not a batch or single request, error // Not a batch or single request, error
jsonerr := &RpcErrorObject{-32600, "Could not decode request"} jsonerr := &RpcErrorObject{-32600, "Could not decode request"}
Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr}) send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr})
}) })
} }
@ -88,7 +88,7 @@ func RpcResponse(api *EthereumApi, request *RpcRequest) *interface{} {
return &response return &response
} }
func Send(writer io.Writer, v interface{}) (n int, err error) { func send(writer io.Writer, v interface{}) (n int, err error) {
var payload []byte var payload []byte
payload, err = json.MarshalIndent(v, "", "\t") payload, err = json.MarshalIndent(v, "", "\t")
if err != nil { if err != nil {

Loading…
Cancel
Save