mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 14:58:16 +08:00
Added the possibility to manage the placeholders from outside ocelot (#724)
This commit is contained in:

committed by
Brian Delgado

parent
9bbb6364f2
commit
35253025c7
@ -35,6 +35,8 @@
|
||||
FileValidationFailedError,
|
||||
UnableToFindDelegatingHandlerProviderError,
|
||||
CouldNotFindPlaceholderError,
|
||||
CouldNotFindAggregatorError
|
||||
CouldNotFindAggregatorError,
|
||||
CannotAddPlaceholderError,
|
||||
CannotRemovePlaceholderError
|
||||
}
|
||||
}
|
||||
|
12
src/Ocelot/Infrastructure/CannotAddPlaceholderError.cs
Normal file
12
src/Ocelot/Infrastructure/CannotAddPlaceholderError.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using Ocelot.Errors;
|
||||
|
||||
namespace Ocelot.Infrastructure
|
||||
{
|
||||
public class CannotAddPlaceholderError : Error
|
||||
{
|
||||
public CannotAddPlaceholderError(string message)
|
||||
: base(message, OcelotErrorCode.CannotAddPlaceholderError)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
12
src/Ocelot/Infrastructure/CannotRemovePlaceholderError.cs
Normal file
12
src/Ocelot/Infrastructure/CannotRemovePlaceholderError.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using Ocelot.Errors;
|
||||
|
||||
namespace Ocelot.Infrastructure
|
||||
{
|
||||
public class CannotRemovePlaceholderError : Error
|
||||
{
|
||||
public CannotRemovePlaceholderError(string message)
|
||||
: base(message, OcelotErrorCode.CannotRemovePlaceholderError)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using Ocelot.Request.Middleware;
|
||||
using Ocelot.Responses;
|
||||
@ -8,5 +9,7 @@ namespace Ocelot.Infrastructure
|
||||
{
|
||||
Response<string> Get(string key);
|
||||
Response<string> Get(string key, DownstreamRequest request);
|
||||
Response Add(string key, Func<Response<string>> func);
|
||||
Response Remove(string key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,28 @@ namespace Ocelot.Infrastructure
|
||||
return new ErrorResponse<string>(new CouldNotFindPlaceholderError(key));
|
||||
}
|
||||
|
||||
public Response Add(string key, Func<Response<string>> func)
|
||||
{
|
||||
if(_placeholders.ContainsKey(key))
|
||||
{
|
||||
return new ErrorResponse(new CannotAddPlaceholderError($"Unable to add placeholder: {key}, placeholder already exists"));
|
||||
}
|
||||
|
||||
_placeholders.Add(key, func);
|
||||
return new OkResponse();
|
||||
}
|
||||
|
||||
public Response Remove(string key)
|
||||
{
|
||||
if(!_placeholders.ContainsKey(key))
|
||||
{
|
||||
return new ErrorResponse(new CannotRemovePlaceholderError($"Unable to remove placeholder: {key}, placeholder does not exists"));
|
||||
}
|
||||
|
||||
_placeholders.Remove(key);
|
||||
return new OkResponse();
|
||||
}
|
||||
|
||||
private Func<Response<string>> GetRemoteIpAddress()
|
||||
{
|
||||
return () =>
|
||||
|
Reference in New Issue
Block a user