mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
Add DownstreamHttpMethodCreatorMiddleware
This commit is contained in:
parent
41519b1e56
commit
58b82f0fc7
@ -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.DownstreamUrlCreator.Middleware
|
||||
{
|
||||
public class DownstreamHttpMethodCreatorMiddleware : OcelotMiddleware
|
||||
{
|
||||
private readonly OcelotRequestDelegate _next;
|
||||
|
||||
public DownstreamHttpMethodCreatorMiddleware(OcelotRequestDelegate next, IOcelotLoggerFactory loggerFactory)
|
||||
: base(loggerFactory.CreateLogger<DownstreamHttpMethodCreatorMiddleware>())
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public async Task Invoke(DownstreamContext context)
|
||||
{
|
||||
if (context.DownstreamReRoute.DownstreamHttpMethod != null)
|
||||
{
|
||||
context.DownstreamRequest.Method = context.DownstreamReRoute.DownstreamHttpMethod;
|
||||
}
|
||||
|
||||
await _next.Invoke(context);
|
||||
}
|
||||
}
|
||||
}
|
@ -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,8 @@ namespace Ocelot.Request.Middleware
|
||||
};
|
||||
|
||||
_request.RequestUri = uriBuilder.Uri;
|
||||
_request.Method = new HttpMethod(Method);
|
||||
_request.Content = Content;
|
||||
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<DownstreamHttpMethodCreatorMiddleware>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user