Commit a0de0080 authored by Honfika's avatar Honfika

fixes 1

parent f8d876c6
......@@ -5,6 +5,7 @@ using System.Net;
using System.Net.Security;
using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Exceptions;
using Titanium.Web.Proxy.Helpers;
using Titanium.Web.Proxy.Http;
using Titanium.Web.Proxy.Models;
......@@ -35,7 +36,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
//generate root certificate without storing it in file system
//proxyServer.CertificateManager.CreateRootCertificate(false);
//proxyServer.CertificateManager.TrustRootCertificate();
//proxyServer.CertificateManager.TrustRootCertificateAsAdmin();
......@@ -45,7 +46,15 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
var color = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(exception.Message);
if (exception is ProxyHttpException phex)
{
Console.WriteLine(exception.Message + ": " + phex.InnerException?.Message);
}
else
{
Console.WriteLine(exception.Message);
}
Console.ForegroundColor = color;
}
};
......@@ -63,7 +72,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
proxyServer.BeforeRequest += OnRequest;
proxyServer.BeforeResponse += OnResponse;
proxyServer.ServerCertificateValidationCallback += OnCertificateValidation;
proxyServer.ClientCertificateSelectionCallback += OnCertificateSelection;
......@@ -71,12 +80,12 @@ namespace Titanium.Web.Proxy.Examples.Basic
explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true)
{
//You can set only one of the ExcludedHttpsHostNameRegex and IncludedHttpsHostNameRegex properties, otherwise ArgumentException will be thrown
//You can set only one of the ExcludedHttpsHostNameRegex and IncludedHttpsHostNameRegex properties, otherwise ArgumentException will be thrown
//Use self-issued generic certificate on all https requests
//Optimizes performance by not creating a certificate for each https-enabled domain
//Useful when certificate trust is not required by proxy clients
//GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
//Use self-issued generic certificate on all https requests
//Optimizes performance by not creating a certificate for each https-enabled domain
//Useful when certificate trust is not required by proxy clients
//GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
};
//Fired when a CONNECT request is received
......@@ -136,7 +145,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
private async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
{
string hostname = e.WebSession.Request.RequestUri.Host;
Console.WriteLine("Tunnel to: " + hostname);
WriteToConsole("Tunnel to: " + hostname);
if (hostname.Contains("dropbox.com"))
{
......@@ -154,8 +163,8 @@ namespace Titanium.Web.Proxy.Examples.Basic
//intecept & cancel redirect or update requests
private async Task OnRequest(object sender, SessionEventArgs e)
{
Console.WriteLine("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount);
Console.WriteLine(e.WebSession.Request.Url);
WriteToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount);
WriteToConsole(e.WebSession.Request.Url);
//read request headers
requestHeaderHistory[e.Id] = e.WebSession.Request.Headers;
......@@ -203,16 +212,16 @@ namespace Titanium.Web.Proxy.Examples.Basic
private void MultipartRequestPartSent(object sender, MultipartRequestPartSentEventArgs e)
{
var session = (SessionEventArgs)sender;
Console.WriteLine("Multipart form data headers:");
WriteToConsole("Multipart form data headers:");
foreach (var header in e.Headers)
{
Console.WriteLine(header);
WriteToConsole(header.ToString());
}
}
private async Task OnResponse(object sender, SessionEventArgs e)
{
Console.WriteLine("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
WriteToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
//if (requestBodyHistory.ContainsKey(e.Id))
//{
......@@ -224,7 +233,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
//responseHeaderHistory[e.Id] = e.WebSession.Response.Headers;
//// print out process id of current session
////Console.WriteLine($"PID: {e.WebSession.ProcessId.Value}");
////WriteToConsole($"PID: {e.WebSession.ProcessId.Value}");
////if (!e.ProxySession.Request.Host.Equals("medeczane.sgk.gov.tr")) return;
//if (e.WebSession.Request.Method == "GET" || e.WebSession.Request.Method == "POST")
......@@ -270,5 +279,13 @@ namespace Titanium.Web.Proxy.Examples.Basic
return Task.FromResult(0);
}
private void WriteToConsole(string message)
{
lock (lockObj)
{
Console.WriteLine(message);
}
}
}
}
......@@ -51,8 +51,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="StreamExtended, Version=1.0.138.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL">
<HintPath>..\..\packages\StreamExtended.1.0.138-beta\lib\net45\StreamExtended.dll</HintPath>
<Reference Include="StreamExtended, Version=1.0.141.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL">
<HintPath>..\..\packages\StreamExtended.1.0.141-beta\lib\net45\StreamExtended.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="StreamExtended" version="1.0.138-beta" targetFramework="net45" />
<package id="StreamExtended" version="1.0.141-beta" targetFramework="net45" />
</packages>
\ No newline at end of file
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
using StreamExtended.Helpers;
using StreamExtended.Network;
......@@ -325,7 +326,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
if (newReader)
{
var bufStream = new CustomBufferedStream(s, bufferSize);
var bufStream = new CustomBufferedStream(s, bufferSize, true);
s = bufStream;
reader = new CustomBinaryReader(bufStream, bufferSize);
}
......@@ -337,7 +338,11 @@ namespace Titanium.Web.Proxy.EventArguments
if (newReader)
{
reader?.Dispose();
decompressStream?.Dispose();
if (decompressStream != null && decompressStream != stream)
{
decompressStream.Dispose();
}
if (chunkedStream != null)
{
await chunkedStream.Finish();
......
......@@ -465,6 +465,7 @@ namespace Titanium.Web.Proxy
catch (Exception e)
{
args.Exception = e;
throw e;
}
finally
{
......
......@@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.1.4" />
<PackageReference Include="StreamExtended" Version="1.0.138-beta" />
<PackageReference Include="StreamExtended" Version="1.0.141-beta" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
......
......@@ -14,7 +14,7 @@
<copyright>Copyright &#x00A9; Titanium. All rights reserved.</copyright>
<tags></tags>
<dependencies>
<dependency id="StreamExtended" version="1.0.138-beta" />
<dependency id="StreamExtended" version="1.0.141-beta" />
<dependency id="Portable.BouncyCastle" version="1.8.1.4" />
</dependencies>
</metadata>
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Portable.BouncyCastle" version="1.8.1.4" targetFramework="net45" />
<package id="StreamExtended" version="1.0.138-beta" targetFramework="net45" />
<package id="StreamExtended" version="1.0.141-beta" targetFramework="net45" />
</packages>
\ No newline at end of file
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