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

Commit

Permalink
Merge pull request #709 from justcoding121/master
Browse files Browse the repository at this point in the history
Add property for client local endoint  (not the lsitening endpoint, t…
  • Loading branch information
honfika authored Dec 23, 2019
2 parents 0bd4ec9 + 4c6a8f5 commit 312dca6
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 26 deletions.
2 changes: 1 addition & 1 deletion examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<GridViewColumn Header="Process" DisplayMemberBinding="{Binding Process}" />
<GridViewColumn Header="SentBytes" DisplayMemberBinding="{Binding SentDataCount}" />
<GridViewColumn Header="ReceivedBytes" DisplayMemberBinding="{Binding ReceivedDataCount}" />
<GridViewColumn Header="ClientEndPoint" DisplayMemberBinding="{Binding ClientEndPoint}" />
<GridViewColumn Header="ClientRemoteEndPoint" DisplayMemberBinding="{Binding ClientRemoteEndPoint}" />
<GridViewColumn Header="ClientConnectionId" DisplayMemberBinding="{Binding ClientConnectionId}" />
<GridViewColumn Header="ServerConnectionId" DisplayMemberBinding="{Binding ServerConnectionId}" />
</GridView>
Expand Down
3 changes: 2 additions & 1 deletion examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ private SessionListItem createSessionListItem(SessionEventArgsBase e)
ClientConnectionId = e.ClientConnectionId,
ServerConnectionId = e.ServerConnectionId,
HttpClient = e.HttpClient,
ClientEndPoint = e.ClientEndPoint,
ClientRemoteEndPoint = e.ClientRemoteEndPoint,
ClientLocalEndPoint = e.ClientLocalEndPoint,
IsTunnelConnect = isTunnelConnect
};

Expand Down
4 changes: 3 additions & 1 deletion examples/Titanium.Web.Proxy.Examples.Wpf/SessionListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public Guid ServerConnectionId

public HttpWebClient HttpClient { get; set; }

public IPEndPoint ClientEndPoint { get; set; }
public IPEndPoint ClientLocalEndPoint { get; set; }

public IPEndPoint ClientRemoteEndPoint { get; set; }

public bool IsTunnelConnect { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SessionEventArgs : SessionEventArgsBase
/// </summary>
private bool reRequest;

private WebSocketDecoder webSocketDecoder;
private WebSocketDecoder? webSocketDecoder;

/// <summary>
/// Is this session a HTTP/2 promise?
Expand Down Expand Up @@ -221,7 +221,7 @@ internal async Task SyphonOutBodyAsync(bool isRequest, CancellationToken cancell

var reader = isRequest ? (HttpStream)ClientStream : HttpClient.Connection.Stream;

await reader.CopyBodyAsync(requestResponse, true, new NullWriter(), TransformationMode.None, null, cancellationToken);
await reader.CopyBodyAsync(requestResponse, true, NullWriter.Instance, TransformationMode.None, null, cancellationToken);
}

/// <summary>
Expand Down
9 changes: 7 additions & 2 deletions src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,14 @@ public bool EnableWinAuth
public bool IsHttps => HttpClient.Request.IsHttps;

/// <summary>
/// Client End Point.
/// Client Local End Point.
/// </summary>
public IPEndPoint ClientEndPoint => (IPEndPoint)ClientConnection.RemoteEndPoint;
public IPEndPoint ClientLocalEndPoint => (IPEndPoint)ClientConnection.LocalEndPoint;

/// <summary>
/// Client Remote End Point.
/// </summary>
public IPEndPoint ClientRemoteEndPoint => (IPEndPoint)ClientConnection.RemoteEndPoint;

/// <summary>
/// The web client used to communicate with server for this session.
Expand Down
11 changes: 4 additions & 7 deletions src/Titanium.Web.Proxy/ExplicitClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnect

Task<TcpServerConnection>? prefetchConnectionTask = null;
bool closeServerConnection = false;
bool calledRequestHandler = false;

try
{
Expand Down Expand Up @@ -375,10 +374,11 @@ await Http2Helper.SendHttp2(clientStream, connection.Stream,
}
}

calledRequestHandler = true;
var prefetchTask = prefetchConnectionTask;
prefetchConnectionTask = null;

// Now create the request
await handleHttpSessionRequest(endPoint, clientStream, cancellationTokenSource, connectArgs, prefetchConnectionTask);
await handleHttpSessionRequest(endPoint, clientStream, cancellationTokenSource, connectArgs, prefetchTask);
}
catch (ProxyException e)
{
Expand Down Expand Up @@ -407,10 +407,7 @@ await Http2Helper.SendHttp2(clientStream, connection.Stream,
cancellationTokenSource.Cancel();
}

if (!calledRequestHandler)
{
await tcpConnectionFactory.Release(prefetchConnectionTask, closeServerConnection);
}
await tcpConnectionFactory.Release(prefetchConnectionTask, closeServerConnection);

clientStream.Dispose();
}
Expand Down
4 changes: 4 additions & 0 deletions src/Titanium.Web.Proxy/Helpers/NullWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ internal class NullWriter : IHttpStreamWriter
{
public static NullWriter Instance { get; } = new NullWriter();

private NullWriter()
{
}

public void Write(byte[] buffer, int offset, int count)
{
}
Expand Down
26 changes: 14 additions & 12 deletions src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,20 +580,22 @@ internal async Task Release(TcpServerConnection connection, bool close = false)

internal async Task Release(Task<TcpServerConnection>? connectionCreateTask, bool closeServerConnection)
{
if (connectionCreateTask != null)
if (connectionCreateTask == null)
{
TcpServerConnection? connection = null;
try
{
connection = await connectionCreateTask;
}
catch { }
finally
return;
}

TcpServerConnection? connection = null;
try
{
connection = await connectionCreateTask;
}
catch { }
finally
{
if (connection != null)
{
if (connection != null)
{
await Release(connection, closeServerConnection);
}
await Release(connection, closeServerConnection);
}
}
}
Expand Down

0 comments on commit 312dca6

Please sign in to comment.