示例#1
0
        public async Task Invoke(HttpContext context)
        {
            _logger.LogDebug("started calling headers builder middleware");

            if (DownstreamRoute.ReRoute.ClaimsToHeaders.Any())
            {
                _logger.LogDebug("this route has instructions to convert claims to headers");

                var response = _addHeadersToRequest.SetHeadersOnDownstreamRequest(DownstreamRoute.ReRoute.ClaimsToHeaders, context.User.Claims, DownstreamRequest);

                if (response.IsError)
                {
                    _logger.LogDebug("there was an error setting headers on context, setting pipeline error");

                    SetPipelineError(response.Errors);
                    return;
                }

                _logger.LogDebug("headers have been set on context");
            }

            _logger.LogDebug("calling next middleware");

            await _next.Invoke(context);

            _logger.LogDebug("succesfully called next middleware");
        }
        public async Task Invoke(HttpContext httpContext)
        {
            var downstreamRoute = httpContext.Items.DownstreamRoute();

            var preFAndRs = downstreamRoute.UpstreamHeadersFindAndReplace;

            //todo - this should be on httprequestmessage not httpcontext?
            _preReplacer.Replace(httpContext, preFAndRs);

            _addHeadersToRequest.SetHeadersOnDownstreamRequest(downstreamRoute.AddHeadersToUpstream, httpContext);

            await _next.Invoke(httpContext);

            // todo check errors is ok
            //todo put this check on the base class?
            if (httpContext.Items.Errors().Count > 0)
            {
                return;
            }

            var postFAndRs = downstreamRoute.DownstreamHeadersFindAndReplace;

            _postReplacer.Replace(httpContext, postFAndRs);

            var downstreamResponse = httpContext.Items.DownstreamResponse();

            _addHeadersToResponse.Add(downstreamRoute.AddHeadersToDownstream, downstreamResponse);
        }
        public async Task Invoke(HttpContext httpContext)
        {
            var downstreamRoute = httpContext.Items.DownstreamRoute();

            if (downstreamRoute.ClaimsToHeaders.Any())
            {
                Logger.LogInformation($"{downstreamRoute.DownstreamPathTemplate.Value} has instructions to convert claims to headers");

                var downstreamRequest = httpContext.Items.DownstreamRequest();

                var response = _addHeadersToRequest.SetHeadersOnDownstreamRequest(downstreamRoute.ClaimsToHeaders, httpContext.User.Claims, downstreamRequest);

                if (response.IsError)
                {
                    Logger.LogWarning("Error setting headers on context, setting pipeline error");

                    httpContext.Items.UpsertErrors(response.Errors);
                    return;
                }

                Logger.LogInformation("headers have been set on context");
            }

            await _next.Invoke(httpContext);
        }
        public async Task Invoke(DownstreamContext context)
        {
            var preFAndRs = context.DownstreamReRoute.UpstreamHeadersFindAndReplace;

            //todo - this should be on httprequestmessage not httpcontext?
            _preReplacer.Replace(context.HttpContext, preFAndRs);

            _addHeadersToRequest.SetHeadersOnDownstreamRequest(context.DownstreamReRoute.AddHeadersToUpstream, context.HttpContext);

            await _next.Invoke(context);

            var postFAndRs = context.DownstreamReRoute.DownstreamHeadersFindAndReplace;

            _postReplacer.Replace(context.DownstreamResponse, postFAndRs, context.DownstreamRequest);

            _addHeadersToResponse.Add(context.DownstreamReRoute.AddHeadersToDownstream, context.DownstreamResponse);
        }
        public async Task Invoke(DownstreamContext context)
        {
            if (context.DownstreamReRoute.ClaimsToHeaders.Any())
            {
                _logger.LogDebug($"{ context.DownstreamReRoute.DownstreamPathTemplate.Value} has instructions to convert claims to headers");

                var response = _addHeadersToRequest.SetHeadersOnDownstreamRequest(context.DownstreamReRoute.ClaimsToHeaders, context.HttpContext.User.Claims, context.DownstreamRequest);

                if (response.IsError)
                {
                    _logger.LogDebug("Error setting headers on context, setting pipeline error");

                    SetPipelineError(context, response.Errors);
                    return;
                }

                _logger.LogDebug("headers have been set on context");
            }

            await _next.Invoke(context);
        }