Skip to content

Commit

Permalink
Remove obsolete code
Browse files Browse the repository at this point in the history
  • Loading branch information
binarymash committed Apr 18, 2017
1 parent a1c6ab4 commit 878eacf
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 302 deletions.
24 changes: 0 additions & 24 deletions src/Ocelot/Headers/AddHeadersToRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,6 @@ public AddHeadersToRequest(IClaimsParser claimsParser)
_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)
Expand Down
17 changes: 7 additions & 10 deletions src/Ocelot/Headers/IAddHeadersToRequest.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public async Task Invoke(HttpContext context)
{
_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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public async Task Invoke(HttpContext context)
return;
}

//SetHostAndPortForThisRequest(hostAndPort.Data);
var uriBuilder = new UriBuilder(DownstreamRequest.RequestUri);
uriBuilder.Host = hostAndPort.Data.DownstreamHost;
if (hostAndPort.Data.DownstreamPort > 0)
Expand Down
43 changes: 0 additions & 43 deletions src/Ocelot/QueryStrings/AddQueriesToRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,6 @@ public AddQueriesToRequest(IClaimsParser claimsParser)
_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);
Expand Down Expand Up @@ -82,26 +52,13 @@ public Response SetQueriesOnDownstreamRequest(List<ClaimToThing> claimsToThings,
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
.ParseQuery(queryString)
.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);
Expand Down
3 changes: 0 additions & 3 deletions src/Ocelot/QueryStrings/IAddQueriesToRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public async Task Invoke(HttpContext context)
{
_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)
Expand Down
25 changes: 7 additions & 18 deletions src/Ocelot/Request/Builder/IRequestCreator.cs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
191 changes: 0 additions & 191 deletions src/Ocelot/Request/Builder/RequestBuilder.cs

This file was deleted.

3 changes: 0 additions & 3 deletions test/Ocelot.UnitTests/Headers/AddHeadersToRequestTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
using Moq;
using Ocelot.Configuration;
using Ocelot.Errors;
Expand All @@ -23,7 +21,6 @@ public class AddHeadersToRequestTests
private readonly HttpRequestMessage _downstreamRequest;
private List<Claim> _claims;
private List<ClaimToThing> _configuration;
private HttpContext _context;
private Response _result;
private Response<string> _claimValue;

Expand Down
Loading

0 comments on commit 878eacf

Please sign in to comment.