You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/05/13 15:48:11 UTC

[GitHub] [apisix] tzssangglass commented on pull request #7040: feat(xrpc): register variable rpc_time

tzssangglass commented on PR #7040:
URL: https://github.com/apache/apisix/pull/7040#issuecomment-1126196778

   > We can apply the patch:
   > 
   > ```
   > index df6e430c..5bf3daa5 100644
   > --- apisix/core/ctx.lua
   > +++ apisix/core/ctx.lua
   > @@ -278,11 +278,12 @@ do
   >              else
   >                  local getter = apisix_var_names[key]
   >                  if getter then
   > +                    local ctx = t._ctx
   >                      if getter == true then
   > -                        val = ngx.ctx.api_ctx and ngx.ctx.api_ctx[key]
   > +                        val = ctx and ctx[key]
   >                      else
   >                          -- the getter is registered by ctx.register_var
   > -                        val = getter(ngx.ctx.api_ctx)
   > +                        val = getter(ctx)
   >                      end
   > 
   >                  else
   > @@ -341,6 +342,7 @@ function _M.set_vars_meta(ctx)
   >      end
   > 
   >      var._request = get_request()
   > +    var._ctx = ctx
   >      setmetatable(var, mt)
   >      ctx.var = var
   >  end
   > diff --git t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua
   > index 28fa4abc..3ea0c7ea 100644
   > --- t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua
   > +++ t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua
   > @@ -30,12 +30,7 @@ local str_byte = string.byte
   > 
   > 
   >  core.ctx.register_var("rpc_len", function(ctx)
   > -    local curr_ctx = ctx.xrpc_session and ctx.xrpc_session._curr_ctx
   > -    if not curr_ctx then
   > -        core.log.warn("can't find current context")
   > -        return nil
   > -    end
   > -    return curr_ctx.len
   > +    return ctx.len
   >  end)
   > 
   >  local _M = {}
   > ```
   
   update, thanks for pointing out a better way.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org