Unverified Commit c2e5c449 authored by honfika's avatar honfika Committed by GitHub

Merge pull request #617 from justcoding121/master

Master to beta
parents 0e8e25ca 1b3d813a
...@@ -1245,7 +1245,7 @@ Defaults via any IP addresses of this machine.</p> ...@@ -1245,7 +1245,7 @@ Defaults via any IP addresses of this machine.</p>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_DisableAllSystemProxies.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.DisableAllSystemProxies%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_DisableAllSystemProxies.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.DisableAllSystemProxies%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span> </span>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L536">View Source</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L550">View Source</a>
</span> </span>
<a id="Titanium_Web_Proxy_ProxyServer_DisableAllSystemProxies_" data-uid="Titanium.Web.Proxy.ProxyServer.DisableAllSystemProxies*"></a> <a id="Titanium_Web_Proxy_ProxyServer_DisableAllSystemProxies_" data-uid="Titanium.Web.Proxy.ProxyServer.DisableAllSystemProxies*"></a>
<h4 id="Titanium_Web_Proxy_ProxyServer_DisableAllSystemProxies" data-uid="Titanium.Web.Proxy.ProxyServer.DisableAllSystemProxies">DisableAllSystemProxies()</h4> <h4 id="Titanium_Web_Proxy_ProxyServer_DisableAllSystemProxies" data-uid="Titanium.Web.Proxy.ProxyServer.DisableAllSystemProxies">DisableAllSystemProxies()</h4>
...@@ -1293,7 +1293,7 @@ Defaults via any IP addresses of this machine.</p> ...@@ -1293,7 +1293,7 @@ Defaults via any IP addresses of this machine.</p>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_DisableSystemProxy_Titanium_Web_Proxy_Models_ProxyProtocolType_.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.DisableSystemProxy(Titanium.Web.Proxy.Models.ProxyProtocolType)%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_DisableSystemProxy_Titanium_Web_Proxy_Models_ProxyProtocolType_.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.DisableSystemProxy(Titanium.Web.Proxy.Models.ProxyProtocolType)%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span> </span>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L522">View Source</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L536">View Source</a>
</span> </span>
<a id="Titanium_Web_Proxy_ProxyServer_DisableSystemProxy_" data-uid="Titanium.Web.Proxy.ProxyServer.DisableSystemProxy*"></a> <a id="Titanium_Web_Proxy_ProxyServer_DisableSystemProxy_" data-uid="Titanium.Web.Proxy.ProxyServer.DisableSystemProxy*"></a>
<h4 id="Titanium_Web_Proxy_ProxyServer_DisableSystemProxy_Titanium_Web_Proxy_Models_ProxyProtocolType_" data-uid="Titanium.Web.Proxy.ProxyServer.DisableSystemProxy(Titanium.Web.Proxy.Models.ProxyProtocolType)">DisableSystemProxy(ProxyProtocolType)</h4> <h4 id="Titanium_Web_Proxy_ProxyServer_DisableSystemProxy_Titanium_Web_Proxy_Models_ProxyProtocolType_" data-uid="Titanium.Web.Proxy.ProxyServer.DisableSystemProxy(Titanium.Web.Proxy.Models.ProxyProtocolType)">DisableSystemProxy(ProxyProtocolType)</h4>
...@@ -1326,7 +1326,7 @@ Defaults via any IP addresses of this machine.</p> ...@@ -1326,7 +1326,7 @@ Defaults via any IP addresses of this machine.</p>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_Dispose.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.Dispose%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_Dispose.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.Dispose%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span> </span>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L884">View Source</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L898">View Source</a>
</span> </span>
<a id="Titanium_Web_Proxy_ProxyServer_Dispose_" data-uid="Titanium.Web.Proxy.ProxyServer.Dispose*"></a> <a id="Titanium_Web_Proxy_ProxyServer_Dispose_" data-uid="Titanium.Web.Proxy.ProxyServer.Dispose*"></a>
<h4 id="Titanium_Web_Proxy_ProxyServer_Dispose" data-uid="Titanium.Web.Proxy.ProxyServer.Dispose">Dispose()</h4> <h4 id="Titanium_Web_Proxy_ProxyServer_Dispose" data-uid="Titanium.Web.Proxy.ProxyServer.Dispose">Dispose()</h4>
...@@ -1372,6 +1372,22 @@ Will throw error if the end point doesn&apos;t exist.</p> ...@@ -1372,6 +1372,22 @@ Will throw error if the end point doesn&apos;t exist.</p>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<span class="small pull-right mobile-hide">
<span class="divider">|</span>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_RestoreOriginalProxySettings.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.RestoreOriginalProxySettings%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span>
<span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L522">View Source</a>
</span>
<a id="Titanium_Web_Proxy_ProxyServer_RestoreOriginalProxySettings_" data-uid="Titanium.Web.Proxy.ProxyServer.RestoreOriginalProxySettings*"></a>
<h4 id="Titanium_Web_Proxy_ProxyServer_RestoreOriginalProxySettings" data-uid="Titanium.Web.Proxy.ProxyServer.RestoreOriginalProxySettings">RestoreOriginalProxySettings()</h4>
<div class="markdown level1 summary"><p>Restores the original proxy settings.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public void RestoreOriginalProxySettings()</code></pre>
</div>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<span class="divider">|</span> <span class="divider">|</span>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_SetAsSystemHttpProxy_Titanium_Web_Proxy_Models_ExplicitProxyEndPoint_.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.SetAsSystemHttpProxy(Titanium.Web.Proxy.Models.ExplicitProxyEndPoint)%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_SetAsSystemHttpProxy_Titanium_Web_Proxy_Models_ExplicitProxyEndPoint_.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.SetAsSystemHttpProxy(Titanium.Web.Proxy.Models.ExplicitProxyEndPoint)%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
...@@ -1485,7 +1501,7 @@ Will throw error if the end point doesn&apos;t exist.</p> ...@@ -1485,7 +1501,7 @@ Will throw error if the end point doesn&apos;t exist.</p>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_Start.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.Start%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_Start.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.Start%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span> </span>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L550">View Source</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L564">View Source</a>
</span> </span>
<a id="Titanium_Web_Proxy_ProxyServer_Start_" data-uid="Titanium.Web.Proxy.ProxyServer.Start*"></a> <a id="Titanium_Web_Proxy_ProxyServer_Start_" data-uid="Titanium.Web.Proxy.ProxyServer.Start*"></a>
<h4 id="Titanium_Web_Proxy_ProxyServer_Start" data-uid="Titanium.Web.Proxy.ProxyServer.Start">Start()</h4> <h4 id="Titanium_Web_Proxy_ProxyServer_Start" data-uid="Titanium.Web.Proxy.ProxyServer.Start">Start()</h4>
...@@ -1501,7 +1517,7 @@ Will throw error if the end point doesn&apos;t exist.</p> ...@@ -1501,7 +1517,7 @@ Will throw error if the end point doesn&apos;t exist.</p>
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_Stop.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.Stop%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_Stop.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.Stop%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
</span> </span>
<span class="small pull-right mobile-hide"> <span class="small pull-right mobile-hide">
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L610">View Source</a> <a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L624">View Source</a>
</span> </span>
<a id="Titanium_Web_Proxy_ProxyServer_Stop_" data-uid="Titanium.Web.Proxy.ProxyServer.Stop*"></a> <a id="Titanium_Web_Proxy_ProxyServer_Stop_" data-uid="Titanium.Web.Proxy.ProxyServer.Stop*"></a>
<h4 id="Titanium_Web_Proxy_ProxyServer_Stop" data-uid="Titanium.Web.Proxy.ProxyServer.Stop">Stop()</h4> <h4 id="Titanium_Web_Proxy_ProxyServer_Stop" data-uid="Titanium.Web.Proxy.ProxyServer.Stop">Stop()</h4>
......
This diff is collapsed.
...@@ -3744,6 +3744,19 @@ references: ...@@ -3744,6 +3744,19 @@ references:
isSpec: "True" isSpec: "True"
fullName: Titanium.Web.Proxy.ProxyServer.RemoveEndPoint fullName: Titanium.Web.Proxy.ProxyServer.RemoveEndPoint
nameWithType: ProxyServer.RemoveEndPoint nameWithType: ProxyServer.RemoveEndPoint
- uid: Titanium.Web.Proxy.ProxyServer.RestoreOriginalProxySettings
name: RestoreOriginalProxySettings()
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_RestoreOriginalProxySettings
commentId: M:Titanium.Web.Proxy.ProxyServer.RestoreOriginalProxySettings
fullName: Titanium.Web.Proxy.ProxyServer.RestoreOriginalProxySettings()
nameWithType: ProxyServer.RestoreOriginalProxySettings()
- uid: Titanium.Web.Proxy.ProxyServer.RestoreOriginalProxySettings*
name: RestoreOriginalProxySettings
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_RestoreOriginalProxySettings_
commentId: Overload:Titanium.Web.Proxy.ProxyServer.RestoreOriginalProxySettings
isSpec: "True"
fullName: Titanium.Web.Proxy.ProxyServer.RestoreOriginalProxySettings
nameWithType: ProxyServer.RestoreOriginalProxySettings
- uid: Titanium.Web.Proxy.ProxyServer.ReuseSocket - uid: Titanium.Web.Proxy.ProxyServer.ReuseSocket
name: ReuseSocket name: ReuseSocket
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_ReuseSocket href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_ReuseSocket
......
...@@ -119,7 +119,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -119,7 +119,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
private async Task onBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e) private async Task onBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
{ {
string hostname = e.HttpClient.Request.RequestUri.Host; string hostname = e.HttpClient.Request.RequestUri.Host;
await writeToConsole("Tunnel to: " + hostname); //await writeToConsole("Tunnel to: " + hostname);
if (hostname.Contains("dropbox.com")) if (hostname.Contains("dropbox.com"))
{ {
...@@ -138,8 +138,8 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -138,8 +138,8 @@ namespace Titanium.Web.Proxy.Examples.Basic
// intecept & cancel redirect or update requests // intecept & cancel redirect or update requests
private async Task onRequest(object sender, SessionEventArgs e) private async Task onRequest(object sender, SessionEventArgs e)
{ {
await writeToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount); //await writeToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount);
await writeToConsole(e.HttpClient.Request.Url); //await writeToConsole(e.HttpClient.Request.Url);
// store it in the UserData property // store it in the UserData property
// It can be a simple integer, Guid, or any type // It can be a simple integer, Guid, or any type
...@@ -189,7 +189,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -189,7 +189,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
private async Task onResponse(object sender, SessionEventArgs e) private async Task onResponse(object sender, SessionEventArgs e)
{ {
await writeToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount); //await writeToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
string ext = System.IO.Path.GetExtension(e.HttpClient.Request.RequestUri.AbsolutePath); string ext = System.IO.Path.GetExtension(e.HttpClient.Request.RequestUri.AbsolutePath);
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
</TabItem> </TabItem>
</TabControl> </TabControl>
<StackPanel Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" Orientation="Horizontal"> <StackPanel Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" Orientation="Horizontal">
<ToggleButton IsChecked="True" Content="On/Off" Click="ButtonProxyOnOff_OnClick" />
<TextBlock Text="ClientConnectionCount:" /> <TextBlock Text="ClientConnectionCount:" />
<TextBlock Text="{Binding ClientConnectionCount}" Margin="10,0,20,0" /> <TextBlock Text="{Binding ClientConnectionCount}" Margin="10,0,20,0" />
<TextBlock Text="ServerConnectionCount:" /> <TextBlock Text="ServerConnectionCount:" />
......
...@@ -8,6 +8,7 @@ using System.Text; ...@@ -8,6 +8,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using Titanium.Web.Proxy.EventArguments; using Titanium.Web.Proxy.EventArguments;
...@@ -284,15 +285,26 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -284,15 +285,26 @@ namespace Titanium.Web.Proxy.Examples.Wpf
{ {
if (e.Key == Key.Delete) if (e.Key == Key.Delete)
{ {
bool isSelected = false;
var selectedItems = ((ListView)sender).SelectedItems; var selectedItems = ((ListView)sender).SelectedItems;
Sessions.SuppressNotification = true; Sessions.SuppressNotification = true;
foreach (var item in selectedItems.Cast<SessionListItem>().ToArray()) foreach (var item in selectedItems.Cast<SessionListItem>().ToArray())
{ {
if (item == SelectedSession)
{
isSelected = true;
}
Sessions.Remove(item); Sessions.Remove(item);
sessionDictionary.Remove(item.HttpClient); sessionDictionary.Remove(item.HttpClient);
} }
Sessions.SuppressNotification = false; Sessions.SuppressNotification = false;
if (isSelected)
{
SelectedSession = null;
}
} }
} }
...@@ -300,6 +312,9 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -300,6 +312,9 @@ namespace Titanium.Web.Proxy.Examples.Wpf
{ {
if (SelectedSession == null) if (SelectedSession == null)
{ {
TextBoxRequest.Text = null;
TextBoxResponse.Text = string.Empty;
ImageResponse.Source = null;
return; return;
} }
...@@ -307,7 +322,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -307,7 +322,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
var session = SelectedSession.HttpClient; var session = SelectedSession.HttpClient;
var request = session.Request; var request = session.Request;
var fullData = (request.IsBodyRead ? request.Body : null) ?? new byte[0]; var fullData = (request.IsBodyRead ? request.Body : null) ?? Array.Empty<byte>();
var data = fullData; var data = fullData;
bool truncated = data.Length > truncateLimit; bool truncated = data.Length > truncateLimit;
if (truncated) if (truncated)
...@@ -324,7 +339,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -324,7 +339,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
TextBoxRequest.Text = sb.ToString(); TextBoxRequest.Text = sb.ToString();
var response = session.Response; var response = session.Response;
fullData = (response.IsBodyRead ? response.Body : null) ?? new byte[0]; fullData = (response.IsBodyRead ? response.Body : null) ?? Array.Empty<byte>();
data = fullData; data = fullData;
truncated = data.Length > truncateLimit; truncated = data.Length > truncateLimit;
if (truncated) if (truncated)
...@@ -348,16 +363,33 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -348,16 +363,33 @@ namespace Titanium.Web.Proxy.Examples.Wpf
try try
{ {
using (MemoryStream stream = new MemoryStream(fullData)) if (fullData.Length > 0)
{
using (var stream = new MemoryStream(fullData))
{ {
ImageResponse.Source = ImageResponse.Source =
BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
} }
} }
}
catch catch
{ {
ImageResponse.Source = null; ImageResponse.Source = null;
} }
} }
private void ButtonProxyOnOff_OnClick(object sender, RoutedEventArgs e)
{
var button = (ToggleButton)sender;
if (button.IsChecked == true)
{
proxyServer.SetAsSystemProxy((ExplicitProxyEndPoint)proxyServer.ProxyEndPoints[0],
ProxyProtocolType.AllHttp);
}
else
{
proxyServer.RestoreOriginalProxySettings();
}
}
} }
} }
...@@ -265,8 +265,8 @@ namespace Titanium.Web.Proxy ...@@ -265,8 +265,8 @@ namespace Titanium.Web.Proxy
try try
{ {
await clientStream.ReadAsync(data, 0, available, cancellationToken);
// clientStream.Available should be at most BufferSize because it is using the same buffer size // clientStream.Available should be at most BufferSize because it is using the same buffer size
await clientStream.ReadAsync(data, 0, available, cancellationToken);
await connection.StreamWriter.WriteAsync(data, 0, available, true, cancellationToken); await connection.StreamWriter.WriteAsync(data, 0, available, true, cancellationToken);
} }
finally finally
...@@ -279,11 +279,14 @@ namespace Titanium.Web.Proxy ...@@ -279,11 +279,14 @@ namespace Titanium.Web.Proxy
((ConnectResponse)connectArgs.HttpClient.Response).ServerHelloInfo = serverHelloInfo; ((ConnectResponse)connectArgs.HttpClient.Response).ServerHelloInfo = serverHelloInfo;
} }
if (!clientStream.IsClosed && !connection.Stream.IsClosed)
{
await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool, BufferSize, await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool, BufferSize,
(buffer, offset, count) => { connectArgs.OnDataSent(buffer, offset, count); }, (buffer, offset, count) => { connectArgs.OnDataSent(buffer, offset, count); },
(buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); }, (buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); },
connectArgs.CancellationTokenSource, ExceptionFunc); connectArgs.CancellationTokenSource, ExceptionFunc);
} }
}
finally finally
{ {
await tcpConnectionFactory.Release(connection, true); await tcpConnectionFactory.Release(connection, true);
......
using System; using System;
using System.Net;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
...@@ -99,7 +100,13 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -99,7 +100,13 @@ namespace Titanium.Web.Proxy.Helpers
{ {
// only for subdomains we need wild card // only for subdomains we need wild card
// example www.google.com or gstatic.google.com // example www.google.com or gstatic.google.com
// but NOT for google.com // but NOT for google.com or IP address
if (IPAddress.TryParse(hostname, out _))
{
return hostname;
}
if (hostname.Split(ProxyConstants.DotSplit).Length > 2) if (hostname.Split(ProxyConstants.DotSplit).Length > 2)
{ {
int idx = hostname.IndexOf(ProxyConstants.DotSplit); int idx = hostname.IndexOf(ProxyConstants.DotSplit);
......
...@@ -481,6 +481,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -481,6 +481,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
try try
{ {
var cutOff = DateTime.Now.AddSeconds(-1 * Server.ConnectionTimeOutSeconds);
foreach (var item in cache) foreach (var item in cache)
{ {
var queue = item.Value; var queue = item.Value;
...@@ -489,7 +490,6 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -489,7 +490,6 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
if (queue.TryDequeue(out var connection)) if (queue.TryDequeue(out var connection))
{ {
var cutOff = DateTime.Now.AddSeconds(-1 * Server.ConnectionTimeOutSeconds);
if (!Server.EnableConnectionPool if (!Server.EnableConnectionPool
|| connection.LastAccess < cutOff) || connection.LastAccess < cutOff)
{ {
...@@ -512,7 +512,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -512,7 +512,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
var emptyKeys = cache.Where(x => x.Value.Count == 0).Select(x => x.Key).ToList(); var emptyKeys = cache.Where(x => x.Value.Count == 0).Select(x => x.Key).ToList();
foreach (string key in emptyKeys) foreach (string key in emptyKeys)
{ {
cache.TryRemove(key, out var _); cache.TryRemove(key, out _);
} }
} }
finally finally
......
...@@ -516,6 +516,20 @@ namespace Titanium.Web.Proxy ...@@ -516,6 +516,20 @@ namespace Titanium.Web.Proxy
DisableSystemProxy(ProxyProtocolType.Https); DisableSystemProxy(ProxyProtocolType.Https);
} }
/// <summary>
/// Restores the original proxy settings.
/// </summary>
public void RestoreOriginalProxySettings()
{
if (!RunTime.IsWindows)
{
throw new NotSupportedException(@"Setting system proxy settings are only supported in Windows.
Please manually configure your operating system to use this proxy's port and address.");
}
systemProxySettingsManager.RestoreOriginalSettings();
}
/// <summary> /// <summary>
/// Clear the specified proxy setting for current machine. /// Clear the specified proxy setting for current machine.
/// </summary> /// </summary>
...@@ -524,7 +538,7 @@ namespace Titanium.Web.Proxy ...@@ -524,7 +538,7 @@ namespace Titanium.Web.Proxy
if (!RunTime.IsWindows) if (!RunTime.IsWindows)
{ {
throw new NotSupportedException(@"Setting system proxy settings are only supported in Windows. throw new NotSupportedException(@"Setting system proxy settings are only supported in Windows.
Please manually confugure you operating system to use this proxy's port and address."); Please manually configure your operating system to use this proxy's port and address.");
} }
systemProxySettingsManager.RemoveProxy(protocolType); systemProxySettingsManager.RemoveProxy(protocolType);
......
...@@ -65,6 +65,11 @@ namespace Titanium.Web.Proxy ...@@ -65,6 +65,11 @@ namespace Titanium.Web.Proxy
// (assuming HTTP connection is kept alive by client) // (assuming HTTP connection is kept alive by client)
while (true) while (true)
{ {
if (clientStream.IsClosed)
{
return;
}
// read the request line // read the request line
string httpCmd = await clientStream.ReadLineAsync(cancellationToken); string httpCmd = await clientStream.ReadLineAsync(cancellationToken);
...@@ -255,11 +260,11 @@ namespace Titanium.Web.Proxy ...@@ -255,11 +260,11 @@ namespace Titanium.Web.Proxy
throw new Exception("Session was terminated by user."); throw new Exception("Session was terminated by user.");
} }
//Release server connection for each HTTP session instead of per client connection. // Release server connection for each HTTP session instead of per client connection.
//This will be more efficient especially when client is idly holding server connection // This will be more efficient especially when client is idly holding server connection
//between sessions without using it. // between sessions without using it.
//Do not release authenticated connections for performance reasons. // Do not release authenticated connections for performance reasons.
//Otherwise it will keep authenticating per session. // Otherwise it will keep authenticating per session.
if (EnableConnectionPool && connection != null if (EnableConnectionPool && connection != null
&& !connection.IsWinAuthenticated) && !connection.IsWinAuthenticated)
{ {
......
using System.Collections.Concurrent; using System.Buffers;
using System.Collections.Concurrent;
namespace Titanium.Web.Proxy.StreamExtended.BufferPool namespace Titanium.Web.Proxy.StreamExtended.BufferPool
{ {
...@@ -10,8 +11,6 @@ namespace Titanium.Web.Proxy.StreamExtended.BufferPool ...@@ -10,8 +11,6 @@ namespace Titanium.Web.Proxy.StreamExtended.BufferPool
/// </summary> /// </summary>
public class DefaultBufferPool : IBufferPool public class DefaultBufferPool : IBufferPool
{ {
private readonly ConcurrentStack<byte[]> buffers = new ConcurrentStack<byte[]>();
/// <summary> /// <summary>
/// Gets a buffer. /// Gets a buffer.
/// </summary> /// </summary>
...@@ -19,12 +18,7 @@ namespace Titanium.Web.Proxy.StreamExtended.BufferPool ...@@ -19,12 +18,7 @@ namespace Titanium.Web.Proxy.StreamExtended.BufferPool
/// <returns></returns> /// <returns></returns>
public byte[] GetBuffer(int bufferSize) public byte[] GetBuffer(int bufferSize)
{ {
if (!buffers.TryPop(out var buffer) || buffer.Length != bufferSize) return ArrayPool<byte>.Shared.Rent(bufferSize);
{
buffer = new byte[bufferSize];
}
return buffer;
} }
/// <summary> /// <summary>
...@@ -33,15 +27,11 @@ namespace Titanium.Web.Proxy.StreamExtended.BufferPool ...@@ -33,15 +27,11 @@ namespace Titanium.Web.Proxy.StreamExtended.BufferPool
/// <param name="buffer">The buffer.</param> /// <param name="buffer">The buffer.</param>
public void ReturnBuffer(byte[] buffer) public void ReturnBuffer(byte[] buffer)
{ {
if (buffer != null) ArrayPool<byte>.Shared.Return(buffer);
{
buffers.Push(buffer);
}
} }
public void Dispose() public void Dispose()
{ {
buffers.Clear();
} }
} }
} }
...@@ -9,6 +9,7 @@ namespace Titanium.Web.Proxy.StreamExtended.BufferPool ...@@ -9,6 +9,7 @@ namespace Titanium.Web.Proxy.StreamExtended.BufferPool
public interface IBufferPool : IDisposable public interface IBufferPool : IDisposable
{ {
byte[] GetBuffer(int bufferSize); byte[] GetBuffer(int bufferSize);
void ReturnBuffer(byte[] buffer); void ReturnBuffer(byte[] buffer);
} }
} }
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Titanium.Web.Proxy.StreamExtended.Network
{
/// <summary>
/// Mimic a Task but you can set AsyncState
/// </summary>
/// <typeparam name="T"></typeparam>
public class TaskResult : IAsyncResult
{
Task Task;
readonly object asyncState;
public TaskResult(Task pTask, object state)
{
Task = pTask;
asyncState = state;
}
public object AsyncState => asyncState;
public WaitHandle AsyncWaitHandle => ((IAsyncResult)Task).AsyncWaitHandle;
public bool CompletedSynchronously => ((IAsyncResult)Task).CompletedSynchronously;
public bool IsCompleted => Task.IsCompleted;
public void GetResult() { this.Task.GetAwaiter().GetResult(); }
}
/// <summary>
/// Mimic a Task<T> but you can set AsyncState
/// </summary>
/// <typeparam name="T"></typeparam>
public class TaskResult<T> : IAsyncResult
{
Task<T> Task;
readonly object asyncState;
public TaskResult(Task<T> pTask, object state)
{
Task = pTask;
asyncState = state;
}
public object AsyncState => asyncState;
public WaitHandle AsyncWaitHandle => ((IAsyncResult)Task).AsyncWaitHandle;
public bool CompletedSynchronously => ((IAsyncResult)Task).CompletedSynchronously;
public bool IsCompleted => Task.IsCompleted;
public T Result => Task.Result;
}
}
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="BrotliSharpLib" Version="0.3.3" /> <PackageReference Include="BrotliSharpLib" Version="0.3.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" /> <PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'"> <ItemGroup Condition="'$(TargetFramework)' == 'net461'">
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="BrotliSharpLib" Version="0.3.3" /> <PackageReference Include="BrotliSharpLib" Version="0.3.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" /> <PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"> <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="BrotliSharpLib" Version="0.3.3" /> <PackageReference Include="BrotliSharpLib" Version="0.3.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" /> <PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"> <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
......
...@@ -18,12 +18,14 @@ ...@@ -18,12 +18,14 @@
<dependency id="Portable.BouncyCastle" version="1.8.5" /> <dependency id="Portable.BouncyCastle" version="1.8.5" />
<dependency id="BrotliSharpLib" version="0.3.3" /> <dependency id="BrotliSharpLib" version="0.3.3" />
<dependency id="Microsoft.Win32.Registry" version="4.5.0" /> <dependency id="Microsoft.Win32.Registry" version="4.5.0" />
<dependency id="System.Buffers" version="4.5.0" />
<dependency id="System.Security.Principal.Windows" version="4.5.1" /> <dependency id="System.Security.Principal.Windows" version="4.5.1" />
</group> </group>
<group targetFramework="netcoreapp2.1"> <group targetFramework="netcoreapp2.1">
<dependency id="Portable.BouncyCastle" version="1.8.5" /> <dependency id="Portable.BouncyCastle" version="1.8.5" />
<dependency id="BrotliSharpLib" version="0.3.3" /> <dependency id="BrotliSharpLib" version="0.3.3" />
<dependency id="Microsoft.Win32.Registry" version="4.5.0" /> <dependency id="Microsoft.Win32.Registry" version="4.5.0" />
<dependency id="System.Buffers" version="4.5.0" />
<dependency id="System.Security.Principal.Windows" version="4.5.1" /> <dependency id="System.Security.Principal.Windows" version="4.5.1" />
</group> </group>
</dependencies> </dependencies>
......
...@@ -103,7 +103,6 @@ namespace Titanium.Web.Proxy ...@@ -103,7 +103,6 @@ namespace Titanium.Web.Proxy
try try
{ {
CustomBufferedStream serverStream = null;
int available = clientStream.Available; int available = clientStream.Available;
if (available > 0) if (available > 0)
...@@ -114,9 +113,7 @@ namespace Titanium.Web.Proxy ...@@ -114,9 +113,7 @@ namespace Titanium.Web.Proxy
{ {
// clientStream.Available should be at most BufferSize because it is using the same buffer size // clientStream.Available should be at most BufferSize because it is using the same buffer size
await clientStream.ReadAsync(data, 0, available, cancellationToken); await clientStream.ReadAsync(data, 0, available, cancellationToken);
serverStream = connection.Stream; await connection.StreamWriter.WriteAsync(data, 0, available, true, cancellationToken);
await serverStream.WriteAsync(data, 0, available, cancellationToken);
await serverStream.FlushAsync(cancellationToken);
} }
finally finally
{ {
...@@ -124,9 +121,12 @@ namespace Titanium.Web.Proxy ...@@ -124,9 +121,12 @@ namespace Titanium.Web.Proxy
} }
} }
await TcpHelper.SendRaw(clientStream, serverStream, BufferPool, BufferSize, if (!clientStream.IsClosed && !connection.Stream.IsClosed)
{
await TcpHelper.SendRaw(clientStream, connection.Stream, BufferPool, BufferSize,
null, null, cancellationTokenSource, ExceptionFunc); null, null, cancellationTokenSource, ExceptionFunc);
} }
}
finally finally
{ {
await tcpConnectionFactory.Release(connection, true); await tcpConnectionFactory.Release(connection, true);
......
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