mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-07 15:10:01 +08:00
feat: add option to ignore unknown fields in gateway request parsing (#5058)
This commit is contained in:
@@ -30,11 +30,12 @@ type (
|
||||
// Server is a gateway server.
|
||||
Server struct {
|
||||
*rest.Server
|
||||
upstreams []Upstream
|
||||
conns []zrpc.Client
|
||||
processHeader func(http.Header) []string
|
||||
dialer func(conf zrpc.RpcClientConf) zrpc.Client
|
||||
middlewares []rest.Middleware
|
||||
upstreams []Upstream
|
||||
conns []zrpc.Client
|
||||
processHeader func(http.Header) []string
|
||||
dialer func(conf zrpc.RpcClientConf) zrpc.Client
|
||||
middlewares []rest.Middleware
|
||||
ignoreUnknownFields bool
|
||||
}
|
||||
|
||||
// Option defines the method to customize Server.
|
||||
@@ -44,8 +45,9 @@ type (
|
||||
// MustNewServer creates a new gateway server.
|
||||
func MustNewServer(c GatewayConf, opts ...Option) *Server {
|
||||
svr := &Server{
|
||||
upstreams: c.Upstreams,
|
||||
Server: rest.MustNewServer(c.RestConf),
|
||||
upstreams: c.Upstreams,
|
||||
Server: rest.MustNewServer(c.RestConf),
|
||||
ignoreUnknownFields: c.IgnoreUnknownFields,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(svr)
|
||||
@@ -114,7 +116,7 @@ func (s *Server) buildChainHandler(handler http.HandlerFunc) http.HandlerFunc {
|
||||
func (s *Server) buildGrpcHandler(source grpcurl.DescriptorSource, resolver jsonpb.AnyResolver,
|
||||
cli zrpc.Client, rpcPath string) func(http.ResponseWriter, *http.Request) {
|
||||
handler := func(w http.ResponseWriter, r *http.Request) {
|
||||
parser, err := internal.NewRequestParser(r, resolver)
|
||||
parser, err := internal.NewRequestParser(r, resolver, s.ignoreUnknownFields)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
@@ -223,7 +225,6 @@ func (s *Server) buildHttpHandler(target *HttpClientConf) http.HandlerFunc {
|
||||
logc.Error(r.Context(), err)
|
||||
}
|
||||
}
|
||||
|
||||
return s.buildChainHandler(handler)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user