mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	Remove obsolete code
This commit is contained in:
		@@ -16,30 +16,6 @@ namespace Ocelot.Headers
 | 
			
		||||
            _claimsParser = claimsParser;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //public Response SetHeadersOnContext(List<ClaimToThing> claimsToThings, HttpContext context)
 | 
			
		||||
        //{
 | 
			
		||||
        //    foreach (var config in claimsToThings)
 | 
			
		||||
        //    {
 | 
			
		||||
        //        var value = _claimsParser.GetValue(context.User.Claims, config.NewKey, config.Delimiter, config.Index);
 | 
			
		||||
 | 
			
		||||
        //        if (value.IsError)
 | 
			
		||||
        //        {
 | 
			
		||||
        //            return new ErrorResponse(value.Errors);
 | 
			
		||||
        //        }
 | 
			
		||||
 | 
			
		||||
        //        var exists = context.Request.Headers.FirstOrDefault(x => x.Key == config.ExistingKey);
 | 
			
		||||
 | 
			
		||||
        //        if (!string.IsNullOrEmpty(exists.Key))
 | 
			
		||||
        //        {
 | 
			
		||||
        //            context.Request.Headers.Remove(exists);
 | 
			
		||||
        //        }
 | 
			
		||||
 | 
			
		||||
        //        context.Request.Headers.Add(config.ExistingKey, new StringValues(value.Data));
 | 
			
		||||
        //    }
 | 
			
		||||
 | 
			
		||||
        //    return new OkResponse();
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        public Response SetHeadersOnDownstreamRequest(List<ClaimToThing> claimsToThings, IEnumerable<System.Security.Claims.Claim> claims, HttpRequestMessage downstreamRequest)
 | 
			
		||||
        {
 | 
			
		||||
            foreach (var config in claimsToThings)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,16 +1,13 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using Microsoft.AspNetCore.Http;
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
using System.Net.Http;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Headers
 | 
			
		||||
namespace Ocelot.Headers
 | 
			
		||||
{
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using System.Net.Http;
 | 
			
		||||
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
    using Ocelot.Responses;
 | 
			
		||||
 | 
			
		||||
    public interface IAddHeadersToRequest
 | 
			
		||||
    {
 | 
			
		||||
        //Response SetHeadersOnContext(List<ClaimToThing> claimsToThings,
 | 
			
		||||
        //    HttpContext context);
 | 
			
		||||
 | 
			
		||||
        Response SetHeadersOnDownstreamRequest(List<ClaimToThing> claimsToThings, IEnumerable<System.Security.Claims.Claim> claims, HttpRequestMessage downstreamRequest);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,6 @@ namespace Ocelot.Headers.Middleware
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogDebug("this route has instructions to convert claims to headers");
 | 
			
		||||
 | 
			
		||||
                //var response = _addHeadersToRequest.SetHeadersOnContext(DownstreamRoute.ReRoute.ClaimsToHeaders, context);
 | 
			
		||||
                var response = _addHeadersToRequest.SetHeadersOnDownstreamRequest(DownstreamRoute.ReRoute.ClaimsToHeaders, context.User.Claims, DownstreamRequest);
 | 
			
		||||
 | 
			
		||||
                if (response.IsError)
 | 
			
		||||
 
 | 
			
		||||
@@ -44,7 +44,6 @@ namespace Ocelot.LoadBalancer.Middleware
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            //SetHostAndPortForThisRequest(hostAndPort.Data);
 | 
			
		||||
            var uriBuilder = new UriBuilder(DownstreamRequest.RequestUri);
 | 
			
		||||
            uriBuilder.Host = hostAndPort.Data.DownstreamHost;
 | 
			
		||||
            if (hostAndPort.Data.DownstreamPort > 0)
 | 
			
		||||
 
 | 
			
		||||
@@ -19,36 +19,6 @@ namespace Ocelot.QueryStrings
 | 
			
		||||
            _claimsParser = claimsParser;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //public Response SetQueriesOnContext(List<ClaimToThing> claimsToThings, HttpContext context)
 | 
			
		||||
        //{
 | 
			
		||||
        //    var queryDictionary = ConvertQueryStringToDictionary(context.Request.QueryString);
 | 
			
		||||
 | 
			
		||||
        //    foreach (var config in claimsToThings)
 | 
			
		||||
        //    {
 | 
			
		||||
        //        var value = _claimsParser.GetValue(context.User.Claims, config.NewKey, config.Delimiter, config.Index);
 | 
			
		||||
 | 
			
		||||
        //        if (value.IsError)
 | 
			
		||||
        //        {
 | 
			
		||||
        //            return new ErrorResponse(value.Errors);
 | 
			
		||||
        //        }
 | 
			
		||||
 | 
			
		||||
        //        var exists = queryDictionary.FirstOrDefault(x => x.Key == config.ExistingKey);
 | 
			
		||||
 | 
			
		||||
        //        if (!string.IsNullOrEmpty(exists.Key))
 | 
			
		||||
        //        {
 | 
			
		||||
        //            queryDictionary[exists.Key] = value.Data;
 | 
			
		||||
        //        }
 | 
			
		||||
        //        else
 | 
			
		||||
        //        {
 | 
			
		||||
        //            queryDictionary.Add(config.ExistingKey, value.Data);
 | 
			
		||||
        //        }
 | 
			
		||||
        //    }
 | 
			
		||||
 | 
			
		||||
        //    context.Request.QueryString = ConvertDictionaryToQueryString(queryDictionary);
 | 
			
		||||
 | 
			
		||||
        //    return new OkResponse();
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        public Response SetQueriesOnDownstreamRequest(List<ClaimToThing> claimsToThings, IEnumerable<Claim> claims, HttpRequestMessage downstreamRequest)
 | 
			
		||||
        {
 | 
			
		||||
            var queryDictionary = ConvertQueryStringToDictionary(downstreamRequest.RequestUri.Query);
 | 
			
		||||
@@ -82,12 +52,6 @@ namespace Ocelot.QueryStrings
 | 
			
		||||
            return new OkResponse();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //private Dictionary<string, string> ConvertQueryStringToDictionary(HttpContext context)
 | 
			
		||||
        //{
 | 
			
		||||
        //    return Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(context.Request.QueryString.Value)
 | 
			
		||||
        //        .ToDictionary(q => q.Key, q => q.Value.FirstOrDefault() ?? string.Empty);
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        private Dictionary<string, string> ConvertQueryStringToDictionary(string queryString)
 | 
			
		||||
        {
 | 
			
		||||
            return Microsoft.AspNetCore.WebUtilities.QueryHelpers
 | 
			
		||||
@@ -95,13 +59,6 @@ namespace Ocelot.QueryStrings
 | 
			
		||||
                .ToDictionary(q => q.Key, q => q.Value.FirstOrDefault() ?? string.Empty);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //private Microsoft.AspNetCore.Http.QueryString ConvertDictionaryToQueryString(Dictionary<string, string> queryDictionary)
 | 
			
		||||
        //{
 | 
			
		||||
        //    var newQueryString = Microsoft.AspNetCore.WebUtilities.QueryHelpers.AddQueryString("", queryDictionary);
 | 
			
		||||
 | 
			
		||||
        //    return new Microsoft.AspNetCore.Http.QueryString(newQueryString);
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        private string ConvertDictionaryToQueryString(Dictionary<string, string> queryDictionary)
 | 
			
		||||
        {
 | 
			
		||||
            return Microsoft.AspNetCore.WebUtilities.QueryHelpers.AddQueryString("", queryDictionary);
 | 
			
		||||
 
 | 
			
		||||
@@ -9,9 +9,6 @@ namespace Ocelot.QueryStrings
 | 
			
		||||
{
 | 
			
		||||
    public interface IAddQueriesToRequest
 | 
			
		||||
    {
 | 
			
		||||
        //Response SetQueriesOnContext(List<ClaimToThing> claimsToThings,
 | 
			
		||||
        //    HttpContext context);
 | 
			
		||||
 | 
			
		||||
        Response SetQueriesOnDownstreamRequest(List<ClaimToThing> claimsToThings, IEnumerable<Claim> claims, HttpRequestMessage downstreamRequest);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,6 @@ namespace Ocelot.QueryStrings.Middleware
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogDebug("this route has instructions to convert claims to queries");
 | 
			
		||||
 | 
			
		||||
                //var response = _addQueriesToRequest.SetQueriesOnContext(DownstreamRoute.ReRoute.ClaimsToQueries, context);
 | 
			
		||||
                var response = _addQueriesToRequest.SetQueriesOnDownstreamRequest(DownstreamRoute.ReRoute.ClaimsToQueries, context.User.Claims, DownstreamRequest);
 | 
			
		||||
 | 
			
		||||
                if (response.IsError)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,24 +1,13 @@
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Microsoft.AspNetCore.Http;
 | 
			
		||||
using Ocelot.Requester.QoS;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
using System.Net.Http;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Request.Builder
 | 
			
		||||
namespace Ocelot.Request.Builder
 | 
			
		||||
{
 | 
			
		||||
    using System.Net.Http;
 | 
			
		||||
    using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
    using Ocelot.Requester.QoS;
 | 
			
		||||
    using Ocelot.Responses;
 | 
			
		||||
 | 
			
		||||
    public interface IRequestCreator
 | 
			
		||||
    {
 | 
			
		||||
        //Task<Response<Request>> Build(string httpMethod,
 | 
			
		||||
        //    string downstreamUrl,
 | 
			
		||||
        //    Stream content,
 | 
			
		||||
        //    IHeaderDictionary headers,
 | 
			
		||||
        //    QueryString queryString,
 | 
			
		||||
        //    string contentType,
 | 
			
		||||
        //    RequestId.RequestId requestId,
 | 
			
		||||
        //    bool isQos,
 | 
			
		||||
        //    IQoSProvider qosProvider);
 | 
			
		||||
 | 
			
		||||
        Task<Response<Request>> Build(
 | 
			
		||||
            HttpRequestMessage httpRequestMessage,
 | 
			
		||||
            bool isQos,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,191 +0,0 @@
 | 
			
		||||
//using System;
 | 
			
		||||
//using System.Collections.Generic;
 | 
			
		||||
//using System.IO;
 | 
			
		||||
//using System.Linq;
 | 
			
		||||
//using System.Net;
 | 
			
		||||
//using System.Net.Http;
 | 
			
		||||
//using System.Net.Http.Headers;
 | 
			
		||||
//using System.Threading.Tasks;
 | 
			
		||||
//using Microsoft.AspNetCore.Http;
 | 
			
		||||
//using Microsoft.Extensions.Primitives;
 | 
			
		||||
//using Ocelot.Requester.QoS;
 | 
			
		||||
 | 
			
		||||
//namespace Ocelot.Request.Builder
 | 
			
		||||
//{
 | 
			
		||||
//    internal sealed class RequestBuilder
 | 
			
		||||
//    {
 | 
			
		||||
//        private HttpMethod _method;
 | 
			
		||||
//        private string _downstreamUrl;
 | 
			
		||||
//        private QueryString _queryString;
 | 
			
		||||
//        private Stream _content;
 | 
			
		||||
//        private string _contentType;
 | 
			
		||||
//        private IHeaderDictionary _headers;
 | 
			
		||||
//        private RequestId.RequestId _requestId;
 | 
			
		||||
//        private readonly string[] _unsupportedHeaders = {"host"};
 | 
			
		||||
//        private bool _isQos;
 | 
			
		||||
//        private IQoSProvider _qoSProvider;
 | 
			
		||||
 | 
			
		||||
// ---- sets Method
 | 
			
		||||
 | 
			
		||||
//        public RequestBuilder WithHttpMethod(string httpMethod)
 | 
			
		||||
//        {
 | 
			
		||||
//            _method = new HttpMethod(httpMethod);
 | 
			
		||||
//            return this;
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
// ---- sets RequestUri
 | 
			
		||||
 | 
			
		||||
//        public RequestBuilder WithDownstreamUrl(string downstreamUrl)
 | 
			
		||||
//        {
 | 
			
		||||
//            _downstreamUrl = downstreamUrl;
 | 
			
		||||
//            return this;
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        public RequestBuilder WithQueryString(QueryString queryString)
 | 
			
		||||
//        {
 | 
			
		||||
//            _queryString = queryString;
 | 
			
		||||
//            return this;
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        private Uri CreateUri()
 | 
			
		||||
//        {
 | 
			
		||||
//            var uri = new Uri(string.Format("{0}{1}", _downstreamUrl, _queryString.ToUriComponent()));
 | 
			
		||||
//            return uri;
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
// ---- Content and ContentType
 | 
			
		||||
 | 
			
		||||
//        public RequestBuilder WithContent(Stream content)
 | 
			
		||||
//        {
 | 
			
		||||
//            _content = content;
 | 
			
		||||
//            return this;
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        public RequestBuilder WithContentType(string contentType)
 | 
			
		||||
//        {
 | 
			
		||||
//            _contentType = contentType;
 | 
			
		||||
//            return this;
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        private async Task AddContentToRequest(HttpRequestMessage httpRequestMessage)
 | 
			
		||||
//        {
 | 
			
		||||
//            if (_content != null)
 | 
			
		||||
//            {
 | 
			
		||||
//                httpRequestMessage.Content = new ByteArrayContent(await ToByteArray(_content));
 | 
			
		||||
//            }
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        private async Task<byte[]> ToByteArray(Stream stream)
 | 
			
		||||
//        {
 | 
			
		||||
//            using (stream)
 | 
			
		||||
//            {
 | 
			
		||||
//                using (var memStream = new MemoryStream())
 | 
			
		||||
//                {
 | 
			
		||||
//                    await stream.CopyToAsync(memStream);
 | 
			
		||||
//                    return memStream.ToArray();
 | 
			
		||||
//                }
 | 
			
		||||
//            }
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        private void AddContentTypeToRequest(HttpRequestMessage httpRequestMessage)
 | 
			
		||||
//        {
 | 
			
		||||
//            if (!string.IsNullOrEmpty(_contentType))
 | 
			
		||||
//            {
 | 
			
		||||
//                httpRequestMessage.Content.Headers.Remove("Content-Type");
 | 
			
		||||
//                httpRequestMessage.Content.Headers.TryAddWithoutValidation("Content-Type", _contentType);
 | 
			
		||||
//            }
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
// ---- Headers
 | 
			
		||||
 | 
			
		||||
//        public RequestBuilder WithHeaders(IHeaderDictionary headers)
 | 
			
		||||
//        {
 | 
			
		||||
//            _headers = headers;
 | 
			
		||||
//            return this;
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        private void AddHeadersToRequest(HttpRequestMessage httpRequestMessage)
 | 
			
		||||
//        {
 | 
			
		||||
//            if (_headers != null)
 | 
			
		||||
//            {
 | 
			
		||||
//                _headers.Remove("Content-Type");
 | 
			
		||||
 | 
			
		||||
//                foreach (var header in _headers)
 | 
			
		||||
//                {
 | 
			
		||||
//                    //todo get rid of if..
 | 
			
		||||
//                    if (IsSupportedHeader(header))
 | 
			
		||||
//                    {
 | 
			
		||||
//                        httpRequestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray());
 | 
			
		||||
//                    }
 | 
			
		||||
//                }
 | 
			
		||||
//            }
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        private bool IsSupportedHeader(KeyValuePair<string, StringValues> header)
 | 
			
		||||
//        {
 | 
			
		||||
//            return !_unsupportedHeaders.Contains(header.Key.ToLower());
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
// ---- Request ID
 | 
			
		||||
 | 
			
		||||
//        public RequestBuilder WithRequestId(RequestId.RequestId requestId)
 | 
			
		||||
//        {
 | 
			
		||||
//            _requestId = requestId;
 | 
			
		||||
//            return this;
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        private void AddRequestIdHeader(RequestId.RequestId requestId, HttpRequestMessage httpRequestMessage)
 | 
			
		||||
//        {
 | 
			
		||||
//            httpRequestMessage.Headers.Add(requestId.RequestIdKey, requestId.RequestIdValue);
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        private bool RequestIdInHeaders(RequestId.RequestId requestId, HttpRequestHeaders headers)
 | 
			
		||||
//        {
 | 
			
		||||
//            IEnumerable<string> value;
 | 
			
		||||
//            return headers.TryGetValues(requestId.RequestIdKey, out value);
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        private bool ShouldAddRequestId(RequestId.RequestId requestId, HttpRequestHeaders headers)
 | 
			
		||||
//        {
 | 
			
		||||
//            return !string.IsNullOrEmpty(requestId?.RequestIdKey)
 | 
			
		||||
//                   && !string.IsNullOrEmpty(requestId.RequestIdValue)
 | 
			
		||||
//                   && !RequestIdInHeaders(requestId, headers);
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
// ---- QoS
 | 
			
		||||
 | 
			
		||||
//        public RequestBuilder WithIsQos(bool isqos)
 | 
			
		||||
//        {
 | 
			
		||||
//            _isQos = isqos;
 | 
			
		||||
//            return this;
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
//        public RequestBuilder WithQos(IQoSProvider qoSProvider)
 | 
			
		||||
//        {
 | 
			
		||||
//            _qoSProvider = qoSProvider;
 | 
			
		||||
//            return this;
 | 
			
		||||
//        }
 | 
			
		||||
 | 
			
		||||
// ----
 | 
			
		||||
 | 
			
		||||
//        public async Task<Request> Build()
 | 
			
		||||
//        {
 | 
			
		||||
//            var uri = CreateUri();
 | 
			
		||||
 | 
			
		||||
//            var httpRequestMessage = new HttpRequestMessage(_method, uri);
 | 
			
		||||
 | 
			
		||||
//            await AddContentToRequest(httpRequestMessage);
 | 
			
		||||
 | 
			
		||||
//            AddContentTypeToRequest(httpRequestMessage);
 | 
			
		||||
 | 
			
		||||
//            AddHeadersToRequest(httpRequestMessage);
 | 
			
		||||
 | 
			
		||||
//            if (ShouldAddRequestId(_requestId, httpRequestMessage.Headers))
 | 
			
		||||
//            {
 | 
			
		||||
//                AddRequestIdHeader(_requestId, httpRequestMessage);
 | 
			
		||||
//            }
 | 
			
		||||
 | 
			
		||||
//            return new Request(httpRequestMessage,_isQos, _qoSProvider);
 | 
			
		||||
//        }
 | 
			
		||||
//    }
 | 
			
		||||
//}
 | 
			
		||||
		Reference in New Issue
	
	Block a user