httpWriteTimeout = time.Hour
)
+const (
+ // SUCCESS indicates the rpc calling is successful.
+ SUCCESS = "success"
+ // FAIL indicated the rpc calling is failed.
+ FAIL = "fail"
+)
+
+// Response describes the response standard.
+type Response struct {
+ Status string `json:"status,omitempty"`
+ Msg string `json:"msg,omitempty"`
+ Data interface{} `json:"data,omitempty"`
+}
+
//NewSuccessResponse success response
func NewSuccessResponse(data interface{}) Response {
return Response{Status: SUCCESS, Data: data}
m.Handle("/delete-transaction-feed", jsonHandler(a.deleteTxFeed))
m.Handle("/list-transaction-feeds", jsonHandler(a.listTxFeeds))
m.Handle("/list-unspent-outputs", jsonHandler(a.listUnspentOutputs))
- m.Handle("/info", jsonHandler(a.bcr.info))
+ m.Handle("/info", jsonHandler(a.bcr.Info))
m.Handle("/create-access-token", jsonHandler(a.createAccessToken))
m.Handle("/list-access-tokens", jsonHandler(a.listAccessTokens))
}
m.ServeHTTP(w, req)
})
- handler := maxBytes(latencyHandler) // TODO(tessr): consider moving this to non-core specific mux
+ handler := maxBytesHandler(latencyHandler) // TODO(tessr): consider moving this to non-core specific mux
handler = webAssetsHandler(handler)
a.handler = handler
}
+func maxBytesHandler(h http.Handler) http.Handler {
+ const maxReqSize = 1e7 // 10MB
+ return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
+ // A block can easily be bigger than maxReqSize, but everything
+ // else should be pretty small.
+ if req.URL.Path != crosscoreRPCPrefix+"signer/sign-block" {
+ req.Body = http.MaxBytesReader(w, req.Body, maxReqSize)
+ }
+ h.ServeHTTP(w, req)
+ })
+}
+
// json Handler
func jsonHandler(f interface{}) http.Handler {
h, err := httpjson.Handler(f, errorFormatter.Write)