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>
This commit is contained in:
Cory
2020-10-29 11:37:46 +00:00
committed by GitHub
co-authored by mergify[bot]
parent 82f15f306e
commit 536eb689dc
13 changed files with 62 additions and 14 deletions
+1 -1
View File
@@ -41773,4 +41773,4 @@
}, o.resolve = i, e.exports = o, o.id = 1058
}])
});
//# sourceMappingURL=swagger-ui-bundle.js.map
//# sourceMappingURL=swagger-ui-bundle.js.map
+1 -1
View File
@@ -2595,4 +2595,4 @@ definitions:
total:
type: array
items:
$ref: "#/definitions/Coin"
$ref: "#/definitions/Coin"
+27
View File
@@ -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
}