diff --git a/contrib/middleware/http_path.go b/contrib/middleware/http_path.go new file mode 100644 index 0000000000000000000000000000000000000000..cc8f315dbf570c4e6421464b5b97c966b3e61aed --- /dev/null +++ b/contrib/middleware/http_path.go @@ -0,0 +1,16 @@ +package middleware + +import ( + "path" + + "gfx.cafe/open/jrpc/pkg/jsonrpc" +) + +func HttpPathMethod(h jsonrpc.Handler) jsonrpc.Handler { + return jsonrpc.HandlerFunc(func(w jsonrpc.ResponseWriter, r *jsonrpc.Request) { + if r.Peer.HTTP != nil { + r.Method = path.Join(r.Peer.HTTP.URL.Path, r.Method) + } + h.ServeRPC(w, r) + }) +}