fixed problems where routes were not mathing

This commit is contained in:
TomPallister
2016-11-26 14:08:09 +00:00
parent 2103c60d4a
commit 536db48049
10 changed files with 128 additions and 20 deletions

View File

@ -7,6 +7,7 @@ using Ocelot.Configuration.File;
using Ocelot.Configuration.Parser;
using Ocelot.Configuration.Validator;
using Ocelot.Responses;
using Ocelot.Utilities;
namespace Ocelot.Configuration.Creator
{
@ -90,7 +91,6 @@ namespace Ocelot.Configuration.Creator
? globalConfiguration.RequestIdKey
: reRoute.RequestIdKey;
if (isAuthenticated)
{
var authOptionsForRoute = new AuthenticationOptions(reRoute.AuthenticationOptions.Provider,
@ -120,6 +120,8 @@ namespace Ocelot.Configuration.Creator
{
var upstreamTemplate = reRoute.UpstreamTemplate;
upstreamTemplate = upstreamTemplate.SetLastCharacterAs('/');
var placeholders = new List<string>();
for (var i = 0; i < upstreamTemplate.Length; i++)
@ -138,9 +140,11 @@ namespace Ocelot.Configuration.Creator
upstreamTemplate = upstreamTemplate.Replace(placeholder, RegExMatchEverything);
}
return reRoute.ReRouteIsCaseSensitive
var route = reRoute.ReRouteIsCaseSensitive
? $"{upstreamTemplate}{RegExMatchEndString}"
: $"{RegExIgnoreCase}{upstreamTemplate}{RegExMatchEndString}";
return route;
}
private List<ClaimToThing> GetAddThingsToRequest(Dictionary<string,string> thingBeingAdded)

View File

@ -5,6 +5,7 @@ using Ocelot.DownstreamRouteFinder.Finder;
using Ocelot.Infrastructure.RequestData;
using Ocelot.Logging;
using Ocelot.Middleware;
using Ocelot.Utilities;
namespace Ocelot.DownstreamRouteFinder.Middleware
{
@ -29,7 +30,7 @@ namespace Ocelot.DownstreamRouteFinder.Middleware
{
_logger.LogDebug("started calling downstream route finder middleware");
var upstreamUrlPath = context.Request.Path.ToString();
var upstreamUrlPath = context.Request.Path.ToString().SetLastCharacterAs('/');
_logger.LogDebug("upstream url path is {upstreamUrlPath}", upstreamUrlPath);

View File

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
@ -46,14 +47,16 @@ namespace Ocelot.Errors.Middleware
_logger.LogDebug("ocelot pipeline finished");
}
private static async Task SetInternalServerErrorOnResponse(HttpContext context)
private async Task SetInternalServerErrorOnResponse(HttpContext context)
{
context.Response.StatusCode = 500;
context.Response.ContentType = "application/json";
await context.Response.WriteAsync("Internal Server Error");
context.Response.OnStarting(x =>
{
context.Response.StatusCode = 500;
return Task.CompletedTask;
}, context);
}
private static string CreateMessage(HttpContext context, Exception e)
private string CreateMessage(HttpContext context, Exception e)
{
var message =
$"Exception caught in global error handler, exception message: {e.Message}, exception stack: {e.StackTrace}";

View File

@ -0,0 +1,17 @@
namespace Ocelot.Utilities
{
public static class StringExtensions
{
public static string SetLastCharacterAs(this string valueToSetLastChar,
char expectedLastChar)
{
var last = valueToSetLastChar[valueToSetLastChar.Length - 1];
if (last != expectedLastChar)
{
valueToSetLastChar = $"{valueToSetLastChar}{expectedLastChar}";
}
return valueToSetLastChar;
}
}
}