Commit f02a8bfd authored by Jehonathan's avatar Jehonathan Committed by GitHub

Merge pull request #252 from justcoding121/develop

Beta
parents 7b3b1f96 5fb387be
...@@ -116,8 +116,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -116,8 +116,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
//read request headers //read request headers
var requestHeaders = e.WebSession.Request.RequestHeaders; var requestHeaders = e.WebSession.Request.RequestHeaders;
var method = e.WebSession.Request.Method.ToUpper(); if (e.WebSession.Request.HasBody)
if (method == "POST" || method == "PUT" || method == "PATCH")
{ {
//Get/Set request body bytes //Get/Set request body bytes
byte[] bodyBytes = await e.GetRequestBody(); byte[] bodyBytes = await e.GetRequestBody();
......
...@@ -111,8 +111,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -111,8 +111,7 @@ namespace Titanium.Web.Proxy.EventArguments
private async Task ReadRequestBody() private async Task ReadRequestBody()
{ {
//GET request don't have a request body to read //GET request don't have a request body to read
var method = WebSession.Request.Method.ToUpper(); if (!WebSession.Request.HasBody)
if (method != "POST" && method != "PUT" && method != "PATCH")
{ {
throw new BodyNotFoundException("Request don't have a body. " + throw new BodyNotFoundException("Request don't have a body. " +
"Please verify that this request is a Http POST/PUT/PATCH and request " + "Please verify that this request is a Http POST/PUT/PATCH and request " +
......
...@@ -7,15 +7,16 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -7,15 +7,16 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary> /// </summary>
internal class RunTime internal class RunTime
{ {
private static Lazy<bool> isMonoRuntime
= new Lazy<bool>(()=> Type.GetType("Mono.Runtime") != null);
/// <summary> /// <summary>
/// Checks if current run time is Mono /// cache for mono runtime check
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
internal static bool IsRunningOnMono() private static Lazy<bool> isRunningOnMono
{ = new Lazy<bool>(()=> Type.GetType("Mono.Runtime") != null);
return isMonoRuntime.Value;
} /// <summary>
/// Is running on Mono?
/// </summary>
internal static bool IsRunningOnMono => isRunningOnMono.Value;
} }
} }
...@@ -26,6 +26,11 @@ namespace Titanium.Web.Proxy.Http ...@@ -26,6 +26,11 @@ namespace Titanium.Web.Proxy.Http
/// </summary> /// </summary>
public Version HttpVersion { get; set; } public Version HttpVersion { get; set; }
/// <summary>
/// Has request body?
/// </summary>
public bool HasBody => Method == "POST" || Method == "PUT" || Method == "PATCH";
/// <summary> /// <summary>
/// Request Http hostanem /// Request Http hostanem
/// </summary> /// </summary>
......
...@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Network
set set
{ {
//For Mono only Bouncy Castle is supported //For Mono only Bouncy Castle is supported
if (RunTime.IsRunningOnMono()) if (RunTime.IsRunningOnMono)
{ {
value = CertificateEngine.BouncyCastle; value = CertificateEngine.BouncyCastle;
} }
...@@ -226,7 +226,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -226,7 +226,7 @@ namespace Titanium.Web.Proxy.Network
/// <returns></returns> /// <returns></returns>
public bool TrustRootCertificateAsAdministrator() public bool TrustRootCertificateAsAdministrator()
{ {
if (RunTime.IsRunningOnMono()) if (RunTime.IsRunningOnMono)
{ {
return false; return false;
} }
......
...@@ -348,7 +348,7 @@ namespace Titanium.Web.Proxy ...@@ -348,7 +348,7 @@ namespace Titanium.Web.Proxy
/// <param name="endPoint"></param> /// <param name="endPoint"></param>
public void SetAsSystemHttpProxy(ExplicitProxyEndPoint endPoint) public void SetAsSystemHttpProxy(ExplicitProxyEndPoint endPoint)
{ {
if (RunTime.IsRunningOnMono()) if (RunTime.IsRunningOnMono)
{ {
throw new Exception("Mono Runtime do not support system proxy settings."); throw new Exception("Mono Runtime do not support system proxy settings.");
} }
...@@ -375,7 +375,7 @@ namespace Titanium.Web.Proxy ...@@ -375,7 +375,7 @@ namespace Titanium.Web.Proxy
/// <param name="endPoint"></param> /// <param name="endPoint"></param>
public void SetAsSystemHttpsProxy(ExplicitProxyEndPoint endPoint) public void SetAsSystemHttpsProxy(ExplicitProxyEndPoint endPoint)
{ {
if (RunTime.IsRunningOnMono()) if (RunTime.IsRunningOnMono)
{ {
throw new Exception("Mono Runtime do not support system proxy settings."); throw new Exception("Mono Runtime do not support system proxy settings.");
} }
...@@ -416,7 +416,7 @@ namespace Titanium.Web.Proxy ...@@ -416,7 +416,7 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
public void DisableSystemHttpProxy() public void DisableSystemHttpProxy()
{ {
if (RunTime.IsRunningOnMono()) if (RunTime.IsRunningOnMono)
{ {
throw new Exception("Mono Runtime do not support system proxy settings."); throw new Exception("Mono Runtime do not support system proxy settings.");
} }
...@@ -429,7 +429,7 @@ namespace Titanium.Web.Proxy ...@@ -429,7 +429,7 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
public void DisableSystemHttpsProxy() public void DisableSystemHttpsProxy()
{ {
if (RunTime.IsRunningOnMono()) if (RunTime.IsRunningOnMono)
{ {
throw new Exception("Mono Runtime do not support system proxy settings."); throw new Exception("Mono Runtime do not support system proxy settings.");
} }
...@@ -442,7 +442,7 @@ namespace Titanium.Web.Proxy ...@@ -442,7 +442,7 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
public void DisableAllSystemProxies() public void DisableAllSystemProxies()
{ {
if (RunTime.IsRunningOnMono()) if (RunTime.IsRunningOnMono)
{ {
throw new Exception("Mono Runtime do not support system proxy settings."); throw new Exception("Mono Runtime do not support system proxy settings.");
} }
...@@ -474,8 +474,9 @@ namespace Titanium.Web.Proxy ...@@ -474,8 +474,9 @@ namespace Titanium.Web.Proxy
CertificateManager.ClearIdleCertificates(CertificateCacheTimeOutMinutes); CertificateManager.ClearIdleCertificates(CertificateCacheTimeOutMinutes);
if (!RunTime.IsRunningOnMono()) if (!RunTime.IsRunningOnMono)
{ {
//clear orphaned windows auth states every 2 minutes
WinAuthEndPoint.ClearIdleStates(2); WinAuthEndPoint.ClearIdleStates(2);
} }
......
...@@ -322,6 +322,16 @@ namespace Titanium.Web.Proxy ...@@ -322,6 +322,16 @@ namespace Titanium.Web.Proxy
PrepareRequestHeaders(args.WebSession.Request.RequestHeaders, args.WebSession); PrepareRequestHeaders(args.WebSession.Request.RequestHeaders, args.WebSession);
args.WebSession.Request.Host = args.WebSession.Request.RequestUri.Authority; args.WebSession.Request.Host = args.WebSession.Request.RequestUri.Authority;
//if win auth is enabled
//we need a cache of request body
//so that we can send it after authentication in WinAuthHandler.cs
if (EnableWinAuth
&& !RunTime.IsRunningOnMono
&& args.WebSession.Request.HasBody)
{
await args.GetRequestBody();
}
//If user requested interception do it //If user requested interception do it
if (BeforeRequest != null) if (BeforeRequest != null)
{ {
...@@ -461,8 +471,7 @@ namespace Titanium.Web.Proxy ...@@ -461,8 +471,7 @@ namespace Titanium.Web.Proxy
if (!args.WebSession.Request.ExpectationFailed) if (!args.WebSession.Request.ExpectationFailed)
{ {
//If its a post/put/patch request, then read the client html body and send it to server //If its a post/put/patch request, then read the client html body and send it to server
var method = args.WebSession.Request.Method.ToUpper(); if (args.WebSession.Request.HasBody)
if (method == "POST" || method == "PUT" || method == "PATCH")
{ {
await SendClientRequestBody(args); await SendClientRequestBody(args);
} }
......
...@@ -38,7 +38,7 @@ namespace Titanium.Web.Proxy ...@@ -38,7 +38,7 @@ namespace Titanium.Web.Proxy
//check for windows authentication //check for windows authentication
if(EnableWinAuth if(EnableWinAuth
&& !RunTime.IsRunningOnMono() && !RunTime.IsRunningOnMono
&& args.WebSession.Response.ResponseStatusCode == "401") && args.WebSession.Response.ResponseStatusCode == "401")
{ {
var disposed = await Handle401UnAuthorized(args); var disposed = await Handle401UnAuthorized(args);
......
...@@ -96,7 +96,8 @@ namespace Titanium.Web.Proxy ...@@ -96,7 +96,8 @@ namespace Titanium.Web.Proxy
//challenge value will start with any of the scheme selected //challenge value will start with any of the scheme selected
else else
{ {
scheme = authSchemes.FirstOrDefault(x => authHeader.Value.StartsWith(x, StringComparison.OrdinalIgnoreCase)); scheme = authSchemes.FirstOrDefault(x => authHeader.Value.StartsWith(x, StringComparison.OrdinalIgnoreCase)
&& authHeader.Value.Length > x.Length + 1);
var serverToken = authHeader.Value.Substring(scheme.Length + 1); var serverToken = authHeader.Value.Substring(scheme.Length + 1);
var clientToken = WinAuthHandler.GetFinalAuthToken(args.WebSession.Request.Host, serverToken, args.Id); var clientToken = WinAuthHandler.GetFinalAuthToken(args.WebSession.Request.Host, serverToken, args.Id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment