feat(api): Add block height to response headers (#24428)
Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
This commit is contained in:
co-authored by
Alex | Interchain Labs
parent
1e92c9c7b7
commit
f18c6ea274
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
tmrpcserver "github.com/cometbft/cometbft/rpc/jsonrpc/server"
|
||||
gateway "github.com/cosmos/gogogateway"
|
||||
"github.com/golang/protobuf/proto" //nolint:staticcheck // grpc-gateway uses deprecated golang/protobuf
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
@@ -84,11 +85,23 @@ func New(clientCtx client.Context, logger log.Logger, grpcSrv *grpc.Server) *Ser
|
||||
// Custom header matcher for mapping request headers to
|
||||
// GRPC metadata
|
||||
runtime.WithIncomingHeaderMatcher(CustomGRPCHeaderMatcher),
|
||||
|
||||
// extension to set custom response headers
|
||||
runtime.WithForwardResponseOption(customGRPCResponseHeaders),
|
||||
),
|
||||
GRPCSrv: grpcSrv,
|
||||
}
|
||||
}
|
||||
|
||||
func customGRPCResponseHeaders(ctx context.Context, w http.ResponseWriter, _ proto.Message) error {
|
||||
if meta, ok := runtime.ServerMetadataFromContext(ctx); ok {
|
||||
if values := meta.HeaderMD.Get(grpctypes.GRPCBlockHeightHeader); len(values) == 1 {
|
||||
w.Header().Set(grpctypes.GRPCBlockHeightHeader, values[0])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start starts the API server. Internally, the API server leverages CometBFT's
|
||||
// JSON RPC server. Configuration options are provided via config.APIConfig
|
||||
// and are delegated to the CometBFT JSON RPC server.
|
||||
|
||||
Reference in New Issue
Block a user