Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 80dd44e

Browse files
authored
Merge pull request #353 from justcoding121/develop
beta|develop
2 parents 7a44e45 + 5fe2599 commit 80dd44e

35 files changed

+971
-637
lines changed

Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,20 @@ private async Task OnTunnelConnectResponse(object sender, TunnelConnectSessionEv
143143
}
144144

145145
//intecept & cancel redirect or update requests
146-
public async Task OnRequest(object sender, SessionEventArgs e)
146+
private async Task OnRequest(object sender, SessionEventArgs e)
147147
{
148148
Console.WriteLine("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount);
149149
Console.WriteLine(e.WebSession.Request.Url);
150150

151151
//read request headers
152152
requestHeaderHistory[e.Id] = e.WebSession.Request.Headers;
153153

154+
////This sample shows how to get the multipart form data headers
155+
//if (e.WebSession.Request.Host == "mail.yahoo.com" && e.WebSession.Request.IsMultipartFormData)
156+
//{
157+
// e.MultipartRequestPartSent += MultipartRequestPartSent;
158+
//}
159+
154160
if (e.WebSession.Request.HasBody)
155161
{
156162
//Get/Set request body bytes
@@ -185,7 +191,17 @@ public async Task OnRequest(object sender, SessionEventArgs e)
185191
}
186192

187193
//Modify response
188-
public async Task OnResponse(object sender, SessionEventArgs e)
194+
private void MultipartRequestPartSent(object sender, MultipartRequestPartSentEventArgs e)
195+
{
196+
var session = (SessionEventArgs)sender;
197+
Console.WriteLine("Multipart form data headers:");
198+
foreach (var header in e.Headers)
199+
{
200+
Console.WriteLine(header);
201+
}
202+
}
203+
204+
private async Task OnResponse(object sender, SessionEventArgs e)
189205
{
190206
Console.WriteLine("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
191207

Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Titanium.Web.Proxy.Helpers;
1212
using Titanium.Web.Proxy.Http;
1313
using Titanium.Web.Proxy.Models;
14-
using Titanium.Web.Proxy.Network;
1514

1615
namespace Titanium.Web.Proxy.Examples.Wpf
1716
{
@@ -63,13 +62,14 @@ public int ServerConnectionCount
6362
public MainWindow()
6463
{
6564
proxyServer = new ProxyServer();
66-
//proxyServer.CertificateEngine = CertificateEngine.BouncyCastle;
65+
//proxyServer.CertificateEngine = CertificateEngine.DefaultWindows;
6766
proxyServer.TrustRootCertificate = true;
6867
proxyServer.CertificateManager.TrustRootCertificateAsAdministrator();
6968
proxyServer.ForwardToUpstreamGateway = true;
7069

7170
var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true)
7271
{
72+
ExcludedHttpsHostNameRegex = new[] { "ssllabs.com" },
7373
//IncludedHttpsHostNameRegex = new string[0],
7474
};
7575

@@ -134,10 +134,9 @@ private async Task ProxyServer_BeforeResponse(object sender, SessionEventArgs e)
134134
SessionListItem item = null;
135135
await Dispatcher.InvokeAsync(() =>
136136
{
137-
if (sessionDictionary.TryGetValue(e.WebSession, out var item2))
137+
if (sessionDictionary.TryGetValue(e.WebSession, out item))
138138
{
139-
item2.Update();
140-
item = item2;
139+
item.Update();
141140
}
142141
});
143142

@@ -147,6 +146,11 @@ await Dispatcher.InvokeAsync(() =>
147146
{
148147
e.WebSession.Response.KeepBody = true;
149148
await e.GetResponseBody();
149+
150+
await Dispatcher.InvokeAsync(() =>
151+
{
152+
item.Update();
153+
});
150154
}
151155
}
152156
}

Examples/Titanium.Web.Proxy.Examples.Wpf/SessionListItem.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class SessionListItem : INotifyPropertyChanged
1313
private string protocol;
1414
private string host;
1515
private string url;
16-
private long bodySize;
16+
private long? bodySize;
1717
private string process;
1818
private long receivedDataCount;
1919
private long sentDataCount;
@@ -48,7 +48,7 @@ public string Url
4848
set => SetField(ref url, value);
4949
}
5050

51-
public long BodySize
51+
public long? BodySize
5252
{
5353
get => bodySize;
5454
set => SetField(ref bodySize, value);
@@ -76,8 +76,11 @@ public long SentDataCount
7676

7777
protected void SetField<T>(ref T field, T value,[CallerMemberName] string propertyName = null)
7878
{
79-
field = value;
80-
OnPropertyChanged(propertyName);
79+
if (!Equals(field, value))
80+
{
81+
field = value;
82+
OnPropertyChanged(propertyName);
83+
}
8184
}
8285

8386
[NotifyPropertyChangedInvocator]
@@ -105,7 +108,24 @@ public void Update()
105108
Url = request.RequestUri.AbsolutePath;
106109
}
107110

108-
BodySize = response?.ContentLength ?? -1;
111+
if (!IsTunnelConnect)
112+
{
113+
long responseSize = -1;
114+
if (response != null)
115+
{
116+
if (response.ContentLength != -1)
117+
{
118+
responseSize = response.ContentLength;
119+
}
120+
else if (response.IsBodyRead && response.Body != null)
121+
{
122+
responseSize = response.Body.Length;
123+
}
124+
}
125+
126+
BodySize = responseSize;
127+
}
128+
109129
Process = GetProcessDescription(WebSession.ProcessId.Value);
110130
}
111131

Examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
<WarningLevel>4</WarningLevel>
5252
</PropertyGroup>
5353
<ItemGroup>
54-
<Reference Include="StreamExtended, Version=1.0.110.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL">
55-
<HintPath>..\..\packages\StreamExtended.1.0.110-beta\lib\net45\StreamExtended.dll</HintPath>
54+
<Reference Include="StreamExtended, Version=1.0.132.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL">
55+
<HintPath>..\..\packages\StreamExtended.1.0.132-beta\lib\net45\StreamExtended.dll</HintPath>
5656
</Reference>
5757
<Reference Include="System" />
5858
<Reference Include="System.Data" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="StreamExtended" version="1.0.110-beta" targetFramework="net45" />
3+
<package id="StreamExtended" version="1.0.132-beta" targetFramework="net45" />
44
</packages>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
namespace Titanium.Web.Proxy.EventArguments
5+
{
6+
public delegate Task AsyncEventHandler<TEventArgs>(object sender, TEventArgs e);
7+
}

0 commit comments

Comments
 (0)