-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Deprecation headers for legacy rest endpoints #7686
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
923ad0a
add deprecation headers for legacy rest endpoints
clevinson f2e4a8a
add deprecation headers for missing tx routes
clevinson 17c4cf9
rm handler-level deprecation headers
clevinson abd6170
switch to middleware Route.Use method for setting deprecation Headers
clevinson b7e828d
set deprecation headers using subrouter
clevinson abccbb2
cleanup gofmt
clevinson 7d509fd
goimports
clevinson 3e39d45
Update client/rest/rest.go
clevinson abe10d8
update deprecation headers to be set on each module individually
clevinson 2791a54
Merge branch 'master' into clevinson/legacy-deprecation-headers-7636
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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\"") | ||
clevinson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also want to set
Sunset
and orWarning
headers?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sunset
headers requires a specific date of sunset, I can addWarning
headers with essentially the same information, but a bit more verbose.