-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Deprecation headers for legacy rest endpoints (#7686)
* add deprecation headers for legacy rest endpoints * add deprecation headers for missing tx routes * rm handler-level deprecation headers * switch to middleware Route.Use method for setting deprecation Headers * set deprecation headers using subrouter * cleanup gofmt * goimports * Update client/rest/rest.go * update deprecation headers to be set on each module individually Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5a46012
commit e1c7d02
Showing
13 changed files
with
62 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2595,4 +2595,4 @@ definitions: | |
total: | ||
type: array | ||
items: | ||
$ref: "#/definitions/Coin" | ||
$ref: "#/definitions/Coin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", "<https://docs.cosmos.network/v0.40/interfaces/rest.html>; 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |