diff --git a/client/docs/swagger-ui/swagger-ui-bundle.js b/client/docs/swagger-ui/swagger-ui-bundle.js index 4491b4b28445..07eceace9377 100644 --- a/client/docs/swagger-ui/swagger-ui-bundle.js +++ b/client/docs/swagger-ui/swagger-ui-bundle.js @@ -41773,4 +41773,4 @@ }, o.resolve = i, e.exports = o, o.id = 1058 }]) }); -//# sourceMappingURL=swagger-ui-bundle.js.map \ No newline at end of file +//# sourceMappingURL=swagger-ui-bundle.js.map diff --git a/client/docs/swagger_legacy.yaml b/client/docs/swagger_legacy.yaml index 6e996d42cd78..fe00efa48493 100644 --- a/client/docs/swagger_legacy.yaml +++ b/client/docs/swagger_legacy.yaml @@ -2595,4 +2595,4 @@ definitions: total: type: array items: - $ref: "#/definitions/Coin" \ No newline at end of file + $ref: "#/definitions/Coin" diff --git a/client/rest/rest.go b/client/rest/rest.go new file mode 100644 index 000000000000..9a0f901840a6 --- /dev/null +++ b/client/rest/rest.go @@ -0,0 +1,27 @@ +package rest + +import ( + "net/http" + + "github.com/gorilla/mux" +) + +// addHTTPDeprecationHeaders is a mux middleware function for adding HTTP +// Deprecation headers to a http handler +func addHTTPDeprecationHeaders(h http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Deprecation", "true") + w.Header().Set("Link", "; rel=\"deprecation\"") + w.Header().Set("Warning", "199 - \"this endpoint is deprecated and may not work as before, see deprecation link for more info\"") + h.ServeHTTP(w, r) + }) +} + +// WithHTTPDeprecationHeaders returns a new *mux.Router, identical to its input +// but with the addition of HTTP Deprecation headers. This is used to mark legacy +// amino REST endpoints as deprecated in the REST API. +func WithHTTPDeprecationHeaders(r *mux.Router) *mux.Router { + subRouter := r.NewRoute().Subrouter() + subRouter.Use(addHTTPDeprecationHeaders) + return subRouter +} diff --git a/types/module/module.go b/types/module/module.go index 97319e5d0036..6b678745e26c 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -31,9 +31,8 @@ package module import ( "encoding/json" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" diff --git a/x/auth/client/rest/rest.go b/x/auth/client/rest/rest.go index d3106edca229..77f8f4896465 100644 --- a/x/auth/client/rest/rest.go +++ b/x/auth/client/rest/rest.go @@ -4,6 +4,7 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/rest" ) // REST query and parameter values @@ -12,7 +13,8 @@ const ( ) // RegisterRoutes registers the auth module REST routes. -func RegisterRoutes(clientCtx client.Context, r *mux.Router, storeName string) { +func RegisterRoutes(clientCtx client.Context, rtr *mux.Router, storeName string) { + r := rest.WithHTTPDeprecationHeaders(rtr) r.HandleFunc( "/auth/accounts/{address}", QueryAccountRequestHandlerFn(storeName, clientCtx), ).Methods(MethodGet) @@ -24,7 +26,8 @@ func RegisterRoutes(clientCtx client.Context, r *mux.Router, storeName string) { } // RegisterTxRoutes registers all transaction routes on the provided router. -func RegisterTxRoutes(clientCtx client.Context, r *mux.Router) { +func RegisterTxRoutes(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(clientCtx)).Methods("GET") r.HandleFunc("/txs", QueryTxsRequestHandlerFn(clientCtx)).Methods("GET") r.HandleFunc("/txs", BroadcastTxRequest(clientCtx)).Methods("POST") diff --git a/x/bank/client/rest/rest.go b/x/bank/client/rest/rest.go index e70a946d2601..4325386d445e 100644 --- a/x/bank/client/rest/rest.go +++ b/x/bank/client/rest/rest.go @@ -1,6 +1,7 @@ package rest import ( + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" @@ -8,7 +9,8 @@ import ( // RegisterHandlers registers all x/bank transaction and query HTTP REST handlers // on the provided mux router. -func RegisterHandlers(clientCtx client.Context, r *mux.Router) { +func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) r.HandleFunc("/bank/accounts/{address}/transfers", NewSendRequestHandlerFn(clientCtx)).Methods("POST") r.HandleFunc("/bank/balances/{address}", QueryBalancesRequestHandlerFn(clientCtx)).Methods("GET") r.HandleFunc("/bank/total", totalSupplyHandlerFn(clientCtx)).Methods("GET") diff --git a/x/distribution/client/rest/rest.go b/x/distribution/client/rest/rest.go index 0269e9261188..3fdcef89e1cc 100644 --- a/x/distribution/client/rest/rest.go +++ b/x/distribution/client/rest/rest.go @@ -6,6 +6,7 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" + clientrest "github.com/cosmos/cosmos-sdk/client/rest" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -13,7 +14,9 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) -func RegisterHandlers(clientCtx client.Context, r *mux.Router) { +func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) { + r := clientrest.WithHTTPDeprecationHeaders(rtr) + registerQueryRoutes(clientCtx, r) registerTxHandlers(clientCtx, r) } diff --git a/x/evidence/client/rest/rest.go b/x/evidence/client/rest/rest.go index 89756eb58aa0..f2714cc7ba4e 100644 --- a/x/evidence/client/rest/rest.go +++ b/x/evidence/client/rest/rest.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/gorilla/mux" ) @@ -24,7 +25,9 @@ type EvidenceRESTHandler struct { // RegisterRoutes registers all Evidence submission handlers for the evidence module's // REST service handler. -func RegisterRoutes(clientCtx client.Context, r *mux.Router, handlers []EvidenceRESTHandler) { +func RegisterRoutes(clientCtx client.Context, rtr *mux.Router, handlers []EvidenceRESTHandler) { + r := rest.WithHTTPDeprecationHeaders(rtr) + registerQueryRoutes(clientCtx, r) registerTxRoutes(clientCtx, r, handlers) } diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index 5136e19ea1f5..f11798e96760 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -6,6 +6,7 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" + clientrest "github.com/cosmos/cosmos-sdk/client/rest" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" ) @@ -28,7 +29,8 @@ type ProposalRESTHandler struct { Handler func(http.ResponseWriter, *http.Request) } -func RegisterHandlers(clientCtx client.Context, r *mux.Router, phs []ProposalRESTHandler) { +func RegisterHandlers(clientCtx client.Context, rtr *mux.Router, phs []ProposalRESTHandler) { + r := clientrest.WithHTTPDeprecationHeaders(rtr) registerQueryRoutes(clientCtx, r) registerTxHandlers(clientCtx, r, phs) } diff --git a/x/mint/client/rest/rest.go b/x/mint/client/rest/rest.go index a159739a0b59..2ed28d41d771 100644 --- a/x/mint/client/rest/rest.go +++ b/x/mint/client/rest/rest.go @@ -4,9 +4,11 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/rest" ) // RegisterRoutes registers minting module REST handlers on the provided router. -func RegisterRoutes(clientCtx client.Context, r *mux.Router) { +func RegisterRoutes(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) registerQueryRoutes(clientCtx, r) } diff --git a/x/slashing/client/rest/rest.go b/x/slashing/client/rest/rest.go index cdce1a34a093..21d73a5e8866 100644 --- a/x/slashing/client/rest/rest.go +++ b/x/slashing/client/rest/rest.go @@ -1,12 +1,15 @@ package rest import ( + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" ) -func RegisterHandlers(clientCtx client.Context, r *mux.Router) { +func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) + registerQueryRoutes(clientCtx, r) registerTxHandlers(clientCtx, r) } diff --git a/x/staking/client/rest/rest.go b/x/staking/client/rest/rest.go index cdce1a34a093..bb4e82917c92 100644 --- a/x/staking/client/rest/rest.go +++ b/x/staking/client/rest/rest.go @@ -1,12 +1,14 @@ package rest import ( + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" ) -func RegisterHandlers(clientCtx client.Context, r *mux.Router) { +func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) registerQueryRoutes(clientCtx, r) registerTxHandlers(clientCtx, r) } diff --git a/x/upgrade/client/rest/rest.go b/x/upgrade/client/rest/rest.go index cdb078e7da58..83577c0cbc21 100644 --- a/x/upgrade/client/rest/rest.go +++ b/x/upgrade/client/rest/rest.go @@ -1,13 +1,15 @@ package rest import ( + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client" ) // RegisterRoutes registers REST routes for the upgrade module under the path specified by routeName. -func RegisterRoutes(clientCtx client.Context, r *mux.Router) { +func RegisterRoutes(clientCtx client.Context, rtr *mux.Router) { + r := rest.WithHTTPDeprecationHeaders(rtr) registerQueryRoutes(clientCtx, r) registerTxHandlers(clientCtx, r) }