add 2 options to control httpinvoke and jsonrpc 2.0 services

This commit is contained in:
smallnest
2019-05-30 20:12:39 +08:00
parent d681726821
commit d90b4ba208
2 changed files with 16 additions and 8 deletions

View File

@@ -27,11 +27,17 @@ func (s *Server) startGateway(network string, ln net.Listener) net.Listener {
m := cmux.New(ln) m := cmux.New(ln)
rpcxLn := m.Match(rpcxPrefixByteMatcher()) rpcxLn := m.Match(rpcxPrefixByteMatcher())
jsonrpc2Ln := m.Match(cmux.HTTP1HeaderField("X-JSONRPC-2.0", "true"))
httpLn := m.Match(cmux.HTTP1Fast())
go s.startJSONRPC2(jsonrpc2Ln) if !s.DisableJSONRPC {
go s.startHTTP1APIGateway(httpLn) jsonrpc2Ln := m.Match(cmux.HTTP1HeaderField("X-JSONRPC-2.0", "true"))
go s.startJSONRPC2(jsonrpc2Ln)
}
if !s.DisableHTTPGateway {
httpLn := m.Match(cmux.HTTP1Fast())
go s.startHTTP1APIGateway(httpLn)
}
go m.Serve() go m.Serve()
return rpcxLn return rpcxLn

View File

@@ -59,10 +59,12 @@ var (
// Server is rpcx server that use TCP or UDP. // Server is rpcx server that use TCP or UDP.
type Server struct { type Server struct {
ln net.Listener ln net.Listener
readTimeout time.Duration readTimeout time.Duration
writeTimeout time.Duration writeTimeout time.Duration
gatewayHTTPServer *http.Server gatewayHTTPServer *http.Server
DisableHTTPGateway bool // should disable http invoke or not.
DisableJSONRPC bool // should disable json rpc or not.
serviceMapMu sync.RWMutex serviceMapMu sync.RWMutex
serviceMap map[string]*service serviceMap map[string]*service