public async Task Invoke(DownstreamContext context)
        {
            var response = _replacer
                           .Replace(context.DownstreamReRoute.DownstreamPathTemplate.Value, context.TemplatePlaceholderNameAndValues);

            if (response.IsError)
            {
                Logger.LogDebug("IDownstreamPathPlaceholderReplacer returned an error, setting pipeline error");

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

            if (!string.IsNullOrEmpty(context.DownstreamReRoute.DownstreamScheme))
            {
                context.DownstreamRequest.Scheme = context.DownstreamReRoute.DownstreamScheme;
            }

            if (ServiceFabricRequest(context))
            {
                var pathAndQuery = CreateServiceFabricUri(context, response);
                context.DownstreamRequest.AbsolutePath = pathAndQuery.path;
                context.DownstreamRequest.Query        = pathAndQuery.query;
            }
            else
            {
                var dsPath = response.Data;

                if (ContainsQueryString(dsPath))
                {
                    context.DownstreamRequest.AbsolutePath = GetPath(dsPath);

                    if (string.IsNullOrEmpty(context.DownstreamRequest.Query))
                    {
                        context.DownstreamRequest.Query = GetQueryString(dsPath);
                    }
                    else
                    {
                        context.DownstreamRequest.Query += GetQueryString(dsPath).Replace('?', '&');
                    }
                }
                else
                {
                    RemoveQueryStringParametersThatHaveBeenUsedInTemplate(context);

                    context.DownstreamRequest.AbsolutePath = dsPath.Value;
                }
            }

            Logger.LogDebug($"Downstream url is {context.DownstreamRequest}");

            await _next.Invoke(context);
        }
        public async Task Invoke(DownstreamContext context)
        {
            var dsPath = _replacer
                         .Replace(context.DownstreamReRoute.DownstreamPathTemplate, context.TemplatePlaceholderNameAndValues);

            if (dsPath.IsError)
            {
                _logger.LogDebug("IDownstreamPathPlaceholderReplacer returned an error, setting pipeline error");

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

            UriBuilder uriBuilder;

            if (ServiceFabricRequest(context))
            {
                uriBuilder = CreateServiceFabricUri(context, dsPath);
            }
            else
            {
                uriBuilder = new UriBuilder(context.DownstreamRequest.RequestUri)
                {
                    Path   = dsPath.Data.Value,
                    Scheme = context.DownstreamReRoute.DownstreamScheme
                };
            }

            context.DownstreamRequest.RequestUri = uriBuilder.Uri;

            _logger.LogDebug("downstream url is {downstreamUrl.Data.Value}", context.DownstreamRequest.RequestUri);

            await _next.Invoke(context);
        }
        public async Task Invoke(DownstreamContext context)
        {
            var dsPath = _replacer
                         .Replace(context.DownstreamReRoute.DownstreamPathTemplate, context.TemplatePlaceholderNameAndValues);

            if (dsPath.IsError)
            {
                _logger.LogDebug("IDownstreamPathPlaceholderReplacer returned an error, setting pipeline error");

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

            context.DownstreamRequest.Scheme = context.DownstreamReRoute.DownstreamScheme;

            if (ServiceFabricRequest(context))
            {
                var pathAndQuery = CreateServiceFabricUri(context, dsPath);
                context.DownstreamRequest.AbsolutePath = pathAndQuery.path;
                context.DownstreamRequest.Query        = pathAndQuery.query;
            }
            else
            {
                context.DownstreamRequest.AbsolutePath = dsPath.Data.Value;
            }

            _logger.LogDebug("downstream url is {context.DownstreamRequest}", context.DownstreamRequest);

            await _next.Invoke(context);
        }
        public async Task Invoke(HttpContext context)
        {
            var dsPath = _replacer
                         .Replace(DownstreamRoute.ReRoute.DownstreamPathTemplate, DownstreamRoute.TemplatePlaceholderNameAndValues);

            if (dsPath.IsError)
            {
                _logger.LogDebug("IDownstreamPathPlaceholderReplacer returned an error, setting pipeline error");

                SetPipelineError(dsPath.Errors);
                return;
            }

            var uriBuilder = new UriBuilder(DownstreamRequest.RequestUri)
            {
                Path   = dsPath.Data.Value,
                Scheme = DownstreamRoute.ReRoute.DownstreamScheme
            };

            DownstreamRequest.RequestUri = uriBuilder.Uri;

            _logger.LogDebug("downstream url is {downstreamUrl.Data.Value}", DownstreamRequest.RequestUri);

            await _next.Invoke(context);
        }
예제 #5
0
        public async Task Invoke(DownstreamContext context)
        {
            var response = _replacer
                           .Replace(context.DownstreamReRoute.DownstreamPathTemplate, context.TemplatePlaceholderNameAndValues);

            if (response.IsError)
            {
                Logger.LogDebug("IDownstreamPathPlaceholderReplacer returned an error, setting pipeline error");

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

            context.DownstreamRequest.Scheme = context.DownstreamReRoute.DownstreamScheme;

            if (ServiceFabricRequest(context))
            {
                var pathAndQuery = CreateServiceFabricUri(context, response);
                context.DownstreamRequest.AbsolutePath = pathAndQuery.path;
                context.DownstreamRequest.Query        = pathAndQuery.query;
            }
            else
            {
                var dsPath = response.Data;

                if (ContainsQueryString(dsPath))
                {
                    context.DownstreamRequest.AbsolutePath = GetPath(dsPath);
                    context.DownstreamRequest.Query        = GetQueryString(dsPath);

                    // todo - do we need to add anything from the request query string onto the query from the
                    // templae?
                }
                else
                {
                    context.DownstreamRequest.AbsolutePath = dsPath.Value;
                }
            }

            Logger.LogDebug($"Downstream url is {context.DownstreamRequest}");

            await _next.Invoke(context);
        }
예제 #6
0
        public async Task Invoke(HttpContext context)
        {
            _logger.LogDebug("started calling downstream url creator middleware");

            var dsPath = _replacer
                         .Replace(DownstreamRoute.ReRoute.DownstreamPathTemplate, DownstreamRoute.TemplatePlaceholderNameAndValues);

            if (dsPath.IsError)
            {
                _logger.LogDebug("IDownstreamPathPlaceholderReplacer returned an error, setting pipeline error");

                SetPipelineError(dsPath.Errors);
                return;
            }

            var dsScheme = DownstreamRoute.ReRoute.DownstreamScheme;

            var dsHostAndPort = HostAndPort;

            var dsUrl = _urlBuilder.Build(dsPath.Data.Value, dsScheme, dsHostAndPort);

            if (dsUrl.IsError)
            {
                _logger.LogDebug("IUrlBuilder returned an error, setting pipeline error");

                SetPipelineError(dsUrl.Errors);
                return;
            }

            _logger.LogDebug("downstream url is {downstreamUrl.Data.Value}", dsUrl.Data.Value);

            SetDownstreamUrlForThisRequest(dsUrl.Data.Value);

            _logger.LogDebug("calling next middleware");

            await _next.Invoke(context);

            _logger.LogDebug("succesfully called next middleware");
        }
 private void WhenIReplaceTheTemplateVariables()
 {
     _result = _downstreamPathReplacer.Replace(_downstreamRoute.ReRoute.DownstreamPathTemplate, _downstreamRoute.TemplatePlaceholderNameAndValues);
 }
        public async Task Invoke(HttpContext httpContext)
        {
            var downstreamRoute = httpContext.Items.DownstreamRoute();

            var templatePlaceholderNameAndValues = httpContext.Items.TemplatePlaceholderNameAndValues();

            var response = _replacer
                           .Replace(downstreamRoute.DownstreamPathTemplate.Value, templatePlaceholderNameAndValues);

            var downstreamRequest = httpContext.Items.DownstreamRequest();

            if (response.IsError)
            {
                Logger.LogDebug("IDownstreamPathPlaceholderReplacer returned an error, setting pipeline error");

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

            if (!string.IsNullOrEmpty(downstreamRoute.DownstreamScheme))
            {
                //todo make sure this works, hopefully there is a test ;E
                httpContext.Items.DownstreamRequest().Scheme = downstreamRoute.DownstreamScheme;
            }

            var internalConfiguration = httpContext.Items.IInternalConfiguration();

            if (ServiceFabricRequest(internalConfiguration, downstreamRoute))
            {
                var pathAndQuery = CreateServiceFabricUri(downstreamRequest, downstreamRoute, templatePlaceholderNameAndValues, response);

                //todo check this works again hope there is a test..
                downstreamRequest.AbsolutePath = pathAndQuery.path;
                downstreamRequest.Query        = pathAndQuery.query;
            }
            else
            {
                var dsPath = response.Data;

                if (ContainsQueryString(dsPath))
                {
                    downstreamRequest.AbsolutePath = GetPath(dsPath);

                    if (string.IsNullOrEmpty(downstreamRequest.Query))
                    {
                        downstreamRequest.Query = GetQueryString(dsPath);
                    }
                    else
                    {
                        downstreamRequest.Query += GetQueryString(dsPath).Replace('?', '&');
                    }
                }
                else
                {
                    RemoveQueryStringParametersThatHaveBeenUsedInTemplate(downstreamRequest, templatePlaceholderNameAndValues);

                    downstreamRequest.AbsolutePath = dsPath.Value;
                }
            }

            Logger.LogDebug($"Downstream url is {downstreamRequest}");

            await _next.Invoke(httpContext);
        }