Add ability to specify whether to UseProxy or not on ReRoutes (#390) (#391)

* Add ability to specify whether to UseProxy or not on ReRoutes (#390)

* Remove useProxy default value from HttpHandlerOptions constructor
This commit is contained in:
Marco Antonio Araujo
2018-06-12 06:08:25 +01:00
committed by Tom Pallister
parent 0f2a9c1d0d
commit 87c13bd9b4
10 changed files with 86 additions and 34 deletions

View File

@ -15,10 +15,10 @@ namespace Ocelot.Configuration.Creator
public HttpHandlerOptions Create(FileHttpHandlerOptions options)
{
var useTracing = _tracer.GetType() != typeof(FakeServiceTracer) && options.UseTracing;
var useTracing = _tracer.GetType() != typeof(FakeServiceTracer) && options.UseTracing;
return new HttpHandlerOptions(options.AllowAutoRedirect,
options.UseCookieContainer, useTracing);
options.UseCookieContainer, useTracing, options.UseProxy);
}
}
}

View File

@ -5,13 +5,16 @@
public FileHttpHandlerOptions()
{
AllowAutoRedirect = false;
UseCookieContainer = false;
UseCookieContainer = false;
UseProxy = true;
}
public bool AllowAutoRedirect { get; set; }
public bool UseCookieContainer { get; set; }
public bool UseTracing { get; set; }
public bool UseTracing { get; set; }
public bool UseProxy { get; set; }
}
}

View File

@ -6,11 +6,12 @@
/// </summary>
public class HttpHandlerOptions
{
public HttpHandlerOptions(bool allowAutoRedirect, bool useCookieContainer, bool useTracing)
public HttpHandlerOptions(bool allowAutoRedirect, bool useCookieContainer, bool useTracing, bool useProxy)
{
AllowAutoRedirect = allowAutoRedirect;
UseCookieContainer = useCookieContainer;
UseTracing = useTracing;
UseProxy = useProxy;
}
/// <summary>
@ -23,9 +24,14 @@
/// </summary>
public bool UseCookieContainer { get; private set; }
// <summary>
/// <summary>
/// Specify is handler has to use a opentracing
/// </summary>
public bool UseTracing { get; private set; }
public bool UseTracing { get; private set; }
/// <summary>
/// Specify if handler has to use a proxy
/// </summary>
public bool UseProxy { get; private set; }
}
}

View File

@ -5,6 +5,7 @@
private bool _allowAutoRedirect;
private bool _useCookieContainer;
private bool _useTracing;
private bool _useProxy;
public HttpHandlerOptionsBuilder WithAllowAutoRedirect(bool input)
{
@ -24,9 +25,15 @@
return this;
}
public HttpHandlerOptionsBuilder WithUseProxy(bool useProxy)
{
_useProxy = useProxy;
return this;
}
public HttpHandlerOptions Build()
{
return new HttpHandlerOptions(_allowAutoRedirect, _useCookieContainer, _useTracing);
return new HttpHandlerOptions(_allowAutoRedirect, _useCookieContainer, _useTracing, _useProxy);
}
}
}

View File

@ -89,6 +89,7 @@ namespace Ocelot.Requester
{
AllowAutoRedirect = context.DownstreamReRoute.HttpHandlerOptions.AllowAutoRedirect,
UseCookies = context.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer,
UseProxy = context.DownstreamReRoute.HttpHandlerOptions.UseProxy
};
}
@ -98,6 +99,7 @@ namespace Ocelot.Requester
{
AllowAutoRedirect = context.DownstreamReRoute.HttpHandlerOptions.AllowAutoRedirect,
UseCookies = context.DownstreamReRoute.HttpHandlerOptions.UseCookieContainer,
UseProxy = context.DownstreamReRoute.HttpHandlerOptions.UseProxy,
CookieContainer = new CookieContainer()
};
}