From 60b1e593f1d1fbb37ad8e614a57cb12aa0a54133 Mon Sep 17 00:00:00 2001 From: longxboy Date: Tue, 15 Jun 2021 11:40:41 +0800 Subject: [PATCH] add http transport (#1060) * add http transport * delete method and path --- transport/http/client.go | 3 +-- transport/http/server.go | 3 +-- transport/http/transport.go | 24 ++++-------------------- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/transport/http/client.go b/transport/http/client.go index 526150e5b..9eb84c51a 100644 --- a/transport/http/client.go +++ b/transport/http/client.go @@ -199,9 +199,8 @@ func (client *Client) Invoke(ctx context.Context, method, path string, args inte ctx = transport.NewClientContext(ctx, &Transport{ endpoint: client.opts.endpoint, header: headerCarrier(req.Header), - path: path, - method: method, operation: c.operation, + request: req, }) return client.invoke(ctx, req, args, reply, c) } diff --git a/transport/http/server.go b/transport/http/server.go index aa7acbf2b..93f31e950 100644 --- a/transport/http/server.go +++ b/transport/http/server.go @@ -164,10 +164,9 @@ func (s *Server) filter() mux.MiddlewareFunc { } tr := &Transport{ endpoint: s.endpoint.String(), - path: req.RequestURI, - method: req.Method, operation: req.RequestURI, header: headerCarrier(req.Header), + request: req, } if r := mux.CurrentRoute(req); r != nil { if path, err := r.GetPathTemplate(); err == nil { diff --git a/transport/http/transport.go b/transport/http/transport.go index 1789c7374..743cd316f 100644 --- a/transport/http/transport.go +++ b/transport/http/transport.go @@ -14,10 +14,9 @@ var ( // Transport is an HTTP transport. type Transport struct { endpoint string - path string - method string operation string header headerCarrier + request *http.Request } // Kind returns the transport kind. @@ -40,24 +39,9 @@ func (tr *Transport) Header() transport.Header { return tr.header } -// Path returns the Transport path from server context. -func Path(ctx context.Context) string { - if tr, ok := transport.FromServerContext(ctx); ok { - if tr, ok := tr.(*Transport); ok { - return tr.path - } - } - return "" -} - -// Method returns the Transport method from server context. -func Method(ctx context.Context) string { - if tr, ok := transport.FromServerContext(ctx); ok { - if tr, ok := tr.(*Transport); ok { - return tr.method - } - } - return "" +// Request returns the transport request. +func (tr *Transport) Request() *http.Request { + return tr.request } // SetOperation sets the transport operation.