mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:42:50 +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 List<AddHeader> _addHeadersToUpstream;
|
||||||
private bool _dangerousAcceptAnyServerCertificateValidator;
|
private bool _dangerousAcceptAnyServerCertificateValidator;
|
||||||
private SecurityOptions _securityOptions;
|
private SecurityOptions _securityOptions;
|
||||||
|
private string _downstreamHttpMethod;
|
||||||
|
|
||||||
public DownstreamReRouteBuilder()
|
public DownstreamReRouteBuilder()
|
||||||
{
|
{
|
||||||
@ -56,6 +57,12 @@ namespace Ocelot.Configuration.Builder
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DownstreamReRouteBuilder WithDownStreamHttpMethod(string method)
|
||||||
|
{
|
||||||
|
_downstreamHttpMethod = method;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public DownstreamReRouteBuilder WithLoadBalancerOptions(LoadBalancerOptions loadBalancerOptions)
|
public DownstreamReRouteBuilder WithLoadBalancerOptions(LoadBalancerOptions loadBalancerOptions)
|
||||||
{
|
{
|
||||||
_loadBalancerOptions = loadBalancerOptions;
|
_loadBalancerOptions = loadBalancerOptions;
|
||||||
@ -282,7 +289,8 @@ namespace Ocelot.Configuration.Builder
|
|||||||
_addHeadersToDownstream,
|
_addHeadersToDownstream,
|
||||||
_addHeadersToUpstream,
|
_addHeadersToUpstream,
|
||||||
_dangerousAcceptAnyServerCertificateValidator,
|
_dangerousAcceptAnyServerCertificateValidator,
|
||||||
_securityOptions);
|
_securityOptions,
|
||||||
|
_downstreamHttpMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,6 +138,7 @@ namespace Ocelot.Configuration.Creator
|
|||||||
.WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream)
|
.WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream)
|
||||||
.WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator)
|
.WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator)
|
||||||
.WithSecurityOptions(securityOptions)
|
.WithSecurityOptions(securityOptions)
|
||||||
|
.WithDownStreamHttpMethod(fileReRoute.DownstreamHttpMethod)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
return reRoute;
|
return reRoute;
|
||||||
|
@ -38,7 +38,8 @@ namespace Ocelot.Configuration
|
|||||||
List<AddHeader> addHeadersToDownstream,
|
List<AddHeader> addHeadersToDownstream,
|
||||||
List<AddHeader> addHeadersToUpstream,
|
List<AddHeader> addHeadersToUpstream,
|
||||||
bool dangerousAcceptAnyServerCertificateValidator,
|
bool dangerousAcceptAnyServerCertificateValidator,
|
||||||
SecurityOptions securityOptions)
|
SecurityOptions securityOptions,
|
||||||
|
string downstreamHttpMethod)
|
||||||
{
|
{
|
||||||
DangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
|
DangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
|
||||||
AddHeadersToDownstream = addHeadersToDownstream;
|
AddHeadersToDownstream = addHeadersToDownstream;
|
||||||
@ -72,6 +73,7 @@ namespace Ocelot.Configuration
|
|||||||
LoadBalancerKey = loadBalancerKey;
|
LoadBalancerKey = loadBalancerKey;
|
||||||
AddHeadersToUpstream = addHeadersToUpstream;
|
AddHeadersToUpstream = addHeadersToUpstream;
|
||||||
SecurityOptions = securityOptions;
|
SecurityOptions = securityOptions;
|
||||||
|
DownstreamHttpMethod = downstreamHttpMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Key { get; }
|
public string Key { get; }
|
||||||
@ -106,5 +108,6 @@ namespace Ocelot.Configuration
|
|||||||
public List<AddHeader> AddHeadersToUpstream { get; }
|
public List<AddHeader> AddHeadersToUpstream { get; }
|
||||||
public bool DangerousAcceptAnyServerCertificateValidator { get; }
|
public bool DangerousAcceptAnyServerCertificateValidator { get; }
|
||||||
public SecurityOptions SecurityOptions { get; }
|
public SecurityOptions SecurityOptions { get; }
|
||||||
|
public string DownstreamHttpMethod { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ namespace Ocelot.Configuration.File
|
|||||||
public string DownstreamPathTemplate { get; set; }
|
public string DownstreamPathTemplate { get; set; }
|
||||||
public string UpstreamPathTemplate { get; set; }
|
public string UpstreamPathTemplate { get; set; }
|
||||||
public List<string> UpstreamHttpMethod { get; set; }
|
public List<string> UpstreamHttpMethod { get; set; }
|
||||||
|
public string DownstreamHttpMethod { get; set; }
|
||||||
public Dictionary<string, string> AddHeadersToRequest { get; set; }
|
public Dictionary<string, string> AddHeadersToRequest { get; set; }
|
||||||
public Dictionary<string, string> UpstreamHeaderTransform { get; set; }
|
public Dictionary<string, string> UpstreamHeaderTransform { get; set; }
|
||||||
public Dictionary<string, string> DownstreamHeaderTransform { 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.Authorisation.Middleware;
|
||||||
using Ocelot.Cache.Middleware;
|
using Ocelot.Cache.Middleware;
|
||||||
using Ocelot.Claims.Middleware;
|
using Ocelot.Claims.Middleware;
|
||||||
|
using Ocelot.DownstreamMethodTransformer.Middleware;
|
||||||
using Ocelot.DownstreamRouteFinder.Middleware;
|
using Ocelot.DownstreamRouteFinder.Middleware;
|
||||||
using Ocelot.DownstreamUrlCreator.Middleware;
|
using Ocelot.DownstreamUrlCreator.Middleware;
|
||||||
using Ocelot.Errors.Middleware;
|
using Ocelot.Errors.Middleware;
|
||||||
@ -68,6 +69,9 @@ namespace Ocelot.Middleware.Pipeline
|
|||||||
// Initialises downstream request
|
// Initialises downstream request
|
||||||
builder.UseDownstreamRequestInitialiser();
|
builder.UseDownstreamRequestInitialiser();
|
||||||
|
|
||||||
|
//change Http Method
|
||||||
|
builder.UseMiddleware<DownstreamMethodTransformerMiddleware>();
|
||||||
|
|
||||||
// We check whether the request is ratelimit, and if there is no continue processing
|
// We check whether the request is ratelimit, and if there is no continue processing
|
||||||
builder.UseRateLimiting();
|
builder.UseRateLimiting();
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ namespace Ocelot.Request.Middleware
|
|||||||
|
|
||||||
public HttpRequestHeaders Headers { get; }
|
public HttpRequestHeaders Headers { get; }
|
||||||
|
|
||||||
public string Method { get; }
|
public string Method { get; set; }
|
||||||
|
|
||||||
public string OriginalString { get; }
|
public string OriginalString { get; }
|
||||||
|
|
||||||
@ -52,6 +52,7 @@ namespace Ocelot.Request.Middleware
|
|||||||
};
|
};
|
||||||
|
|
||||||
_request.RequestUri = uriBuilder.Uri;
|
_request.RequestUri = uriBuilder.Uri;
|
||||||
|
_request.Method = new HttpMethod(Method);
|
||||||
return _request;
|
return _request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Ocelot.DownstreamUrlCreator.Middleware;
|
||||||
using Ocelot.Middleware.Pipeline;
|
using Ocelot.Middleware.Pipeline;
|
||||||
|
|
||||||
namespace Ocelot.Request.Middleware
|
namespace Ocelot.Request.Middleware
|
||||||
@ -7,7 +8,8 @@ namespace Ocelot.Request.Middleware
|
|||||||
{
|
{
|
||||||
public static IOcelotPipelineBuilder UseDownstreamRequestInitialiser(this IOcelotPipelineBuilder builder)
|
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