mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
embed: mutate /v3alpha requests with /v3beta for backward compatibilities
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
5fd419ff50
commit
c706c6e238
@ -104,7 +104,7 @@ func (sctx *serveCtx) serve(
|
|||||||
httpmux := sctx.createMux(gwmux, handler)
|
httpmux := sctx.createMux(gwmux, handler)
|
||||||
|
|
||||||
srvhttp := &http.Server{
|
srvhttp := &http.Server{
|
||||||
Handler: httpmux,
|
Handler: wrapMux(httpmux),
|
||||||
ErrorLog: logger, // do not log user error
|
ErrorLog: logger, // do not log user error
|
||||||
}
|
}
|
||||||
httpl := m.Match(cmux.HTTP1())
|
httpl := m.Match(cmux.HTTP1())
|
||||||
@ -144,7 +144,7 @@ func (sctx *serveCtx) serve(
|
|||||||
httpmux := sctx.createMux(gwmux, handler)
|
httpmux := sctx.createMux(gwmux, handler)
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Handler: httpmux,
|
Handler: wrapMux(httpmux),
|
||||||
TLSConfig: tlscfg,
|
TLSConfig: tlscfg,
|
||||||
ErrorLog: logger, // do not log user error
|
ErrorLog: logger, // do not log user error
|
||||||
}
|
}
|
||||||
@ -234,6 +234,21 @@ func (sctx *serveCtx) createMux(gwmux *gw.ServeMux, handler http.Handler) *http.
|
|||||||
return httpmux
|
return httpmux
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wraps HTTP multiplexer to mute requests to /v3alpha
|
||||||
|
// TODO: deprecate this in 3.4 release
|
||||||
|
func wrapMux(mux *http.ServeMux) http.Handler { return &v3alphaMutator{mux: mux} }
|
||||||
|
|
||||||
|
type v3alphaMutator struct {
|
||||||
|
mux *http.ServeMux
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *v3alphaMutator) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
if req != nil && req.URL != nil && strings.HasPrefix(req.URL.Path, "/v3alpha/") {
|
||||||
|
req.URL.Path = strings.Replace(req.URL.Path, "/v3alpha/", "/v3beta/", 1)
|
||||||
|
}
|
||||||
|
m.mux.ServeHTTP(rw, req)
|
||||||
|
}
|
||||||
|
|
||||||
func (sctx *serveCtx) registerUserHandler(s string, h http.Handler) {
|
func (sctx *serveCtx) registerUserHandler(s string, h http.Handler) {
|
||||||
if sctx.userHandlers[s] != nil {
|
if sctx.userHandlers[s] != nil {
|
||||||
plog.Warningf("path %s already registered by user handler", s)
|
plog.Warningf("path %s already registered by user handler", s)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user