-
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
Changes from 6 commits
923ad0a
f2e4a8a
17c4cf9
abd6170
b7e828d
abccbb2
7d509fd
3e39d45
abe10d8
2791a54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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
|
||
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,13 +31,13 @@ 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" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/rest" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
@@ -110,8 +110,9 @@ func (bm BasicManager) ValidateGenesis(cdc codec.JSONMarshaler, txEncCfg client. | |
|
||
// RegisterRESTRoutes registers all module rest routes | ||
func (bm BasicManager) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { | ||
r := rest.WithHTTPDeprecationHeaders(rtr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually shouldn't be be doing this module by module? Putting this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought this was what we wanted, as this entire process for generating REST routes will be deprecated at the SDK level in future releases, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're probably right... That would make SDK maintenance easier. Still this deprecation goes to clients. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry- i'm not following exactly what you mean. Is this still something you are wanting changed? Or do you now think the current implementation is correct in the context of this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes It still should be their decision. So I would prefer we do module by module. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This should be on by default to let the developers and users to know and prepare for that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we need to coustomze it at the SDK level, then we can add a parameter to the
|
||
for _, b := range bm { | ||
b.RegisterRESTRoutes(clientCtx, rtr) | ||
b.RegisterRESTRoutes(clientCtx, r) | ||
} | ||
} | ||
|
||
|
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.