mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 07:18:16 +08:00
fixed problems where routes were not mathing
This commit is contained in:
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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}";
|
||||
|
17
src/Ocelot/Utilities/StringExtensions.cs
Normal file
17
src/Ocelot/Utilities/StringExtensions.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user