Browse Source

HTTP responses are pretty JSON

pull/176/head
Jae Kwon 9 years ago
parent
commit
1d34bb173e
1 changed files with 2 additions and 8 deletions
  1. +2
    -8
      rpc/server/http_server.go

+ 2
- 8
rpc/server/http_server.go View File

@ -3,7 +3,6 @@ package rpcserver
import ( import (
"bufio" "bufio"
"bytes"
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
@ -33,15 +32,10 @@ func StartHTTPServer(listenAddr string, handler http.Handler) (net.Listener, err
} }
func WriteRPCResponseHTTP(w http.ResponseWriter, res RPCResponse) { func WriteRPCResponseHTTP(w http.ResponseWriter, res RPCResponse) {
buf, n, err := new(bytes.Buffer), int(0), error(nil)
wire.WriteJSON(res, buf, &n, &err)
if err != nil {
log.Error("Failed to write RPC response", "error", err, "res", res)
}
jsonBytes := wire.JSONBytesPretty(res)
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200) w.WriteHeader(200)
w.Write(buf.Bytes())
w.Write(jsonBytes)
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------


Loading…
Cancel
Save