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() defer cancel()
md, _ := grpcmd.FromIncomingContext(ctx) md, _ := grpcmd.FromIncomingContext(ctx)
replyHeader := grpcmd.MD{} replyHeader := grpcmd.MD{}
ctx = transport.NewServerContext(ctx, &Transport{ tr := &Transport{
endpoint: s.endpoint.String(),
operation: info.FullMethod, operation: info.FullMethod,
reqHeader: headerCarrier(md), reqHeader: headerCarrier(md),
replyHeader: headerCarrier(replyHeader), replyHeader: headerCarrier(replyHeader),
}) }
if s.endpoint != nil {
tr.endpoint = s.endpoint.String()
}
ctx = transport.NewServerContext(ctx, tr)
if s.timeout > 0 { if s.timeout > 0 {
ctx, cancel = context.WithTimeout(ctx, s.timeout) ctx, cancel = context.WithTimeout(ctx, s.timeout)
defer cancel() defer cancel()

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

Loading…
Cancel
Save