fix(transport): http endpoint listening (#2180)

* fix http serve

* fix endpoint nil

Co-authored-by: chenzhihui <chenzhihui@bilibili.com>
pull/2183/head
Tony Chen 2 years ago committed by GitHub
parent c90eab4577
commit 6ac63e6439
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      transport/grpc/interceptor.go
  2. 6
      transport/http/server.go

@ -17,12 +17,15 @@ func (s *Server) unaryServerInterceptor() grpc.UnaryServerInterceptor {
defer cancel()
md, _ := grpcmd.FromIncomingContext(ctx)
replyHeader := grpcmd.MD{}
ctx = transport.NewServerContext(ctx, &Transport{
endpoint: s.endpoint.String(),
tr := &Transport{
operation: info.FullMethod,
reqHeader: headerCarrier(md),
replyHeader: headerCarrier(replyHeader),
})
}
if s.endpoint != nil {
tr.endpoint = s.endpoint.String()
}
ctx = transport.NewServerContext(ctx, tr)
if s.timeout > 0 {
ctx, cancel = context.WithTimeout(ctx, s.timeout)
defer cancel()

@ -153,7 +153,6 @@ func NewServer(opts ...ServerOption) *Server {
Handler: FilterChain(srv.filters...)(srv.router),
TLSConfig: srv.tlsConf,
}
srv.err = srv.listenAndEndpoint()
return srv
}
@ -208,14 +207,15 @@ func (s *Server) filter() mux.MiddlewareFunc {
}
tr := &Transport{
endpoint: s.endpoint.String(),
operation: pathTemplate,
reqHeader: headerCarrier(req.Header),
replyHeader: headerCarrier(w.Header()),
request: req,
pathTemplate: pathTemplate,
}
if s.endpoint != nil {
tr.endpoint = s.endpoint.String()
}
tr.request = req.WithContext(transport.NewServerContext(ctx, tr))
next.ServeHTTP(w, tr.request)
})

Loading…
Cancel
Save