mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 15:04:22 +00:00
We should not set cache-control headers on RPC responses. HTTP caching interacts poorly with resources that are expected to change frequently, or whose rate of change is unpredictable. More subtly, all calls to the POST endpoint use the same URL, which means a cacheable response from one call may actually "hide" an uncacheable response from a subsequent one. This is less of a problem for the GET endpoints, but that means the behaviour of RPCs varies depending on which HTTP method your client happens to use. Websocket requests were already marked statically uncacheable, adding yet a third combination. To address this: - Stop setting cache-control headers. - Update the tests that were checking for those headers. - Remove the flags to request cache-control. Apart from affecting the HTTP response headers, this change does not modify the behaviour of any of the RPC methods.
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server"
|
|
)
|
|
|
|
var routes = map[string]*rpcserver.RPCFunc{
|
|
"hello_world": rpcserver.NewRPCFunc(HelloWorld, "name,num"),
|
|
}
|
|
|
|
func HelloWorld(ctx context.Context, name string, num int) (Result, error) {
|
|
return Result{fmt.Sprintf("hi %s %d", name, num)}, nil
|
|
}
|
|
|
|
type Result struct {
|
|
Result string
|
|
}
|
|
|
|
func main() {
|
|
var (
|
|
mux = http.NewServeMux()
|
|
logger = log.MustNewDefaultLogger(log.LogFormatPlain, log.LogLevelInfo)
|
|
)
|
|
|
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer cancel()
|
|
|
|
rpcserver.RegisterRPCFuncs(mux, routes, logger)
|
|
config := rpcserver.DefaultConfig()
|
|
listener, err := rpcserver.Listen("tcp://127.0.0.1:8008", config.MaxOpenConnections)
|
|
if err != nil {
|
|
logger.Error("rpc listening", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if err = rpcserver.Serve(ctx, listener, mux, logger, config); err != nil {
|
|
logger.Error("rpc serve", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|