Example #1
0
        public async Task Invoke(DownstreamContext context)
        {
            //下游路由信息的匹配
            MapDownstreamContextAsync(context);

            //没有错误,才进入下一个中间件
            if (!context.IsError)
            {
                await _next.Invoke(context);
            }
        }
        public async Task Invoke(DownstreamContext context)
        {
            //如果不需要校验权限
            if (!context.DownstreamRoute.Authentication)
            {
                await _next.Invoke(context);
            }
            else
            {
                //获取token
                string token = GetToken(context.HttpContext);

                if (string.IsNullOrWhiteSpace(token) || !ValidateToken(token))
                {
                    SetPipelineError(context, new AuthorizationError());
                }
                else
                {
                    await _next.Invoke(context);
                }
            }
        }
Example #3
0
        public async Task Invoke(DownstreamContext context)
        {
            await _next.Invoke(context);

            if (context.IsError)
            {
                //保存请求的信息
                BaseLogModel logModel = new BaseLogModel()
                {
                    Type    = 1,
                    Content = $"{context.ToErrorString()} errors found in {MiddlewareName}. Setting error response for request path:{context.HttpContext.Request.Path}, request method: {context.HttpContext.Request.Method}"
                };

                _log.Error(logModel);

                SetErrorResponse(context.HttpContext, context.Errors);
            }
            else
            {
                //Logger.LogDebug("no pipeline errors, setting and returning completed response");
                await _responder.SetResponseOnHttpContext(context.HttpContext, context.DownstreamResponse);
            }
        }