mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 14:02:49 +08:00
Merge branch 'feature/MethodTransformer' of https://github.com/pitming/Ocelot into pitming-feature/MethodTransformer
This commit is contained in:
commit
4bd2243f5e
@ -41,6 +41,7 @@ namespace Ocelot.Configuration.Builder
|
||||
private List<AddHeader> _addHeadersToUpstream;
|
||||
private bool _dangerousAcceptAnyServerCertificateValidator;
|
||||
private SecurityOptions _securityOptions;
|
||||
private string _downstreamHttpMethod;
|
||||
|
||||
public DownstreamReRouteBuilder()
|
||||
{
|
||||
@ -56,6 +57,12 @@ namespace Ocelot.Configuration.Builder
|
||||
return this;
|
||||
}
|
||||
|
||||
public DownstreamReRouteBuilder WithDownStreamHttpMethod(string method)
|
||||
{
|
||||
_downstreamHttpMethod = method;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DownstreamReRouteBuilder WithLoadBalancerOptions(LoadBalancerOptions loadBalancerOptions)
|
||||
{
|
||||
_loadBalancerOptions = loadBalancerOptions;
|
||||
@ -282,7 +289,8 @@ namespace Ocelot.Configuration.Builder
|
||||
_addHeadersToDownstream,
|
||||
_addHeadersToUpstream,
|
||||
_dangerousAcceptAnyServerCertificateValidator,
|
||||
_securityOptions);
|
||||
_securityOptions,
|
||||
_downstreamHttpMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,6 +138,7 @@ namespace Ocelot.Configuration.Creator
|
||||
.WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream)
|
||||
.WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator)
|
||||
.WithSecurityOptions(securityOptions)
|
||||
.WithDownStreamHttpMethod(fileReRoute.DownstreamHttpMethod)
|
||||
.Build();
|
||||
|
||||
return reRoute;
|
||||
|
@ -38,7 +38,8 @@ namespace Ocelot.Configuration
|
||||
List<AddHeader> addHeadersToDownstream,
|
||||
List<AddHeader> addHeadersToUpstream,
|
||||
bool dangerousAcceptAnyServerCertificateValidator,
|
||||
SecurityOptions securityOptions)
|
||||
SecurityOptions securityOptions,
|
||||
string downstreamHttpMethod)
|
||||
{
|
||||
DangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
|
||||
AddHeadersToDownstream = addHeadersToDownstream;
|
||||
@ -72,6 +73,7 @@ namespace Ocelot.Configuration
|
||||
LoadBalancerKey = loadBalancerKey;
|
||||
AddHeadersToUpstream = addHeadersToUpstream;
|
||||
SecurityOptions = securityOptions;
|
||||
DownstreamHttpMethod = downstreamHttpMethod;
|
||||
}
|
||||
|
||||
public string Key { get; }
|
||||
@ -106,5 +108,6 @@ namespace Ocelot.Configuration
|
||||
public List<AddHeader> AddHeadersToUpstream { get; }
|
||||
public bool DangerousAcceptAnyServerCertificateValidator { get; }
|
||||
public SecurityOptions SecurityOptions { get; }
|
||||
public string DownstreamHttpMethod { get; }
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ namespace Ocelot.Configuration.File
|
||||
public string DownstreamPathTemplate { get; set; }
|
||||
public string UpstreamPathTemplate { get; set; }
|
||||
public List<string> UpstreamHttpMethod { get; set; }
|
||||
public string DownstreamHttpMethod { get; set; }
|
||||
public Dictionary<string, string> AddHeadersToRequest { get; set; }
|
||||
public Dictionary<string, string> UpstreamHeaderTransform { get; set; }
|
||||
public Dictionary<string, string> DownstreamHeaderTransform { get; set; }
|
||||
|
@ -0,0 +1,27 @@
|
||||
using Ocelot.Logging;
|
||||
using Ocelot.Middleware;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ocelot.DownstreamMethodTransformer.Middleware
|
||||
{
|
||||
public class DownstreamMethodTransformerMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly OcelotRequestDelegate _next;
|
||||
|
||||
public DownstreamMethodTransformerMiddleware(OcelotRequestDelegate next, IOcelotLoggerFactory loggerFactory)
|
||||
: base(loggerFactory.CreateLogger<DownstreamMethodTransformerMiddleware>())
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public async Task Invoke(DownstreamContext context)
|
||||
{
|
||||
if (context.DownstreamReRoute.DownstreamHttpMethod != null)
|
||||
{
|
||||
context.DownstreamRequest.Method = context.DownstreamReRoute.DownstreamHttpMethod;
|
||||
}
|
||||
|
||||
await _next.Invoke(context);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using Ocelot.Authorisation.Middleware;
|
||||
using Ocelot.Cache.Middleware;
|
||||
using Ocelot.Claims.Middleware;
|
||||
using Ocelot.DownstreamMethodTransformer.Middleware;
|
||||
using Ocelot.DownstreamRouteFinder.Middleware;
|
||||
using Ocelot.DownstreamUrlCreator.Middleware;
|
||||
using Ocelot.Errors.Middleware;
|
||||
@ -68,6 +69,9 @@ namespace Ocelot.Middleware.Pipeline
|
||||
// Initialises downstream request
|
||||
builder.UseDownstreamRequestInitialiser();
|
||||
|
||||
//change Http Method
|
||||
builder.UseMiddleware<DownstreamMethodTransformerMiddleware>();
|
||||
|
||||
// We check whether the request is ratelimit, and if there is no continue processing
|
||||
builder.UseRateLimiting();
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace Ocelot.Request.Middleware
|
||||
|
||||
public HttpRequestHeaders Headers { get; }
|
||||
|
||||
public string Method { get; }
|
||||
public string Method { get; set; }
|
||||
|
||||
public string OriginalString { get; }
|
||||
|
||||
@ -52,6 +52,7 @@ namespace Ocelot.Request.Middleware
|
||||
};
|
||||
|
||||
_request.RequestUri = uriBuilder.Uri;
|
||||
_request.Method = new HttpMethod(Method);
|
||||
return _request;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Ocelot.DownstreamUrlCreator.Middleware;
|
||||
using Ocelot.Middleware.Pipeline;
|
||||
|
||||
namespace Ocelot.Request.Middleware
|
||||
@ -7,7 +8,8 @@ namespace Ocelot.Request.Middleware
|
||||
{
|
||||
public static IOcelotPipelineBuilder UseDownstreamRequestInitialiser(this IOcelotPipelineBuilder builder)
|
||||
{
|
||||
return builder.UseMiddleware<DownstreamRequestInitialiserMiddleware>();
|
||||
return builder.UseMiddleware<DownstreamRequestInitialiserMiddleware>()
|
||||
.UseMiddleware<DownstreamMethodTransformerMiddleware>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user