@@ -76,10 +76,10 @@ internal string GetConnectionCacheKey(string remoteHostName, int remotePort,
76
76
/// <summary>
77
77
/// Gets the connection cache key.
78
78
/// </summary>
79
- /// <param name="args ">The session event arguments.</param>
79
+ /// <param name="session ">The session event arguments.</param>
80
80
/// <param name="applicationProtocol"></param>
81
81
/// <returns></returns>
82
- internal async Task < string > GetConnectionCacheKey ( ProxyServer server , SessionEventArgsBase args ,
82
+ internal async Task < string > GetConnectionCacheKey ( ProxyServer server , SessionEventArgsBase session ,
83
83
SslApplicationProtocol applicationProtocol )
84
84
{
85
85
List < SslApplicationProtocol > applicationProtocols = null ;
@@ -90,32 +90,32 @@ internal async Task<string> GetConnectionCacheKey(ProxyServer server, SessionEve
90
90
91
91
ExternalProxy customUpStreamProxy = null ;
92
92
93
- bool isHttps = args . IsHttps ;
93
+ bool isHttps = session . IsHttps ;
94
94
if ( server . GetCustomUpStreamProxyFunc != null )
95
95
{
96
- customUpStreamProxy = await server . GetCustomUpStreamProxyFunc ( args ) ;
96
+ customUpStreamProxy = await server . GetCustomUpStreamProxyFunc ( session ) ;
97
97
}
98
98
99
- args . CustomUpStreamProxyUsed = customUpStreamProxy ;
99
+ session . CustomUpStreamProxyUsed = customUpStreamProxy ;
100
100
101
101
return GetConnectionCacheKey (
102
- args . WebSession . Request . RequestUri . Host ,
103
- args . WebSession . Request . RequestUri . Port ,
102
+ session . WebSession . Request . RequestUri . Host ,
103
+ session . WebSession . Request . RequestUri . Port ,
104
104
isHttps , applicationProtocols ,
105
- server , args . WebSession . UpStreamEndPoint ?? server . UpStreamEndPoint ,
105
+ server , session . WebSession . UpStreamEndPoint ?? server . UpStreamEndPoint ,
106
106
customUpStreamProxy ?? ( isHttps ? server . UpStreamHttpsProxy : server . UpStreamHttpProxy ) ) ;
107
107
}
108
108
109
109
110
110
/// <summary>
111
111
/// Create a server connection.
112
112
/// </summary>
113
- /// <param name="args ">The session event arguments.</param>
113
+ /// <param name="session ">The session event arguments.</param>
114
114
/// <param name="isConnect">Is this a CONNECT request.</param>
115
115
/// <param name="applicationProtocol"></param>
116
116
/// <param name="cancellationToken">The cancellation token for this async task.</param>
117
117
/// <returns></returns>
118
- internal Task < TcpServerConnection > GetServerConnection ( ProxyServer server , SessionEventArgsBase args , bool isConnect ,
118
+ internal Task < TcpServerConnection > GetServerConnection ( ProxyServer server , SessionEventArgsBase session , bool isConnect ,
119
119
SslApplicationProtocol applicationProtocol , bool noCache , CancellationToken cancellationToken )
120
120
{
121
121
List < SslApplicationProtocol > applicationProtocols = null ;
@@ -124,36 +124,36 @@ internal Task<TcpServerConnection> GetServerConnection(ProxyServer server, Sessi
124
124
applicationProtocols = new List < SslApplicationProtocol > { applicationProtocol } ;
125
125
}
126
126
127
- return GetServerConnection ( server , args , isConnect , applicationProtocols , noCache , cancellationToken ) ;
127
+ return GetServerConnection ( server , session , isConnect , applicationProtocols , noCache , cancellationToken ) ;
128
128
}
129
129
130
130
/// <summary>
131
131
/// Create a server connection.
132
132
/// </summary>
133
- /// <param name="args ">The session event arguments.</param>
133
+ /// <param name="session ">The session event arguments.</param>
134
134
/// <param name="isConnect">Is this a CONNECT request.</param>
135
135
/// <param name="applicationProtocols"></param>
136
136
/// <param name="cancellationToken">The cancellation token for this async task.</param>
137
137
/// <returns></returns>
138
- internal async Task < TcpServerConnection > GetServerConnection ( ProxyServer server , SessionEventArgsBase args , bool isConnect ,
138
+ internal async Task < TcpServerConnection > GetServerConnection ( ProxyServer server , SessionEventArgsBase session , bool isConnect ,
139
139
List < SslApplicationProtocol > applicationProtocols , bool noCache , CancellationToken cancellationToken )
140
140
{
141
141
ExternalProxy customUpStreamProxy = null ;
142
142
143
- bool isHttps = args . IsHttps ;
143
+ bool isHttps = session . IsHttps ;
144
144
if ( server . GetCustomUpStreamProxyFunc != null )
145
145
{
146
- customUpStreamProxy = await server . GetCustomUpStreamProxyFunc ( args ) ;
146
+ customUpStreamProxy = await server . GetCustomUpStreamProxyFunc ( session ) ;
147
147
}
148
148
149
- args . CustomUpStreamProxyUsed = customUpStreamProxy ;
149
+ session . CustomUpStreamProxyUsed = customUpStreamProxy ;
150
150
151
151
return await GetServerConnection (
152
- args . WebSession . Request . RequestUri . Host ,
153
- args . WebSession . Request . RequestUri . Port ,
154
- args . WebSession . Request . HttpVersion ,
152
+ session . WebSession . Request . RequestUri . Host ,
153
+ session . WebSession . Request . RequestUri . Port ,
154
+ session . WebSession . Request . HttpVersion ,
155
155
isHttps , applicationProtocols , isConnect ,
156
- server , args . WebSession . UpStreamEndPoint ?? server . UpStreamEndPoint ,
156
+ server , session , session . WebSession . UpStreamEndPoint ?? server . UpStreamEndPoint ,
157
157
customUpStreamProxy ?? ( isHttps ? server . UpStreamHttpsProxy : server . UpStreamHttpProxy ) ,
158
158
noCache , cancellationToken ) ;
159
159
}
@@ -174,7 +174,7 @@ internal async Task<TcpServerConnection> GetServerConnection(ProxyServer server,
174
174
/// <returns></returns>
175
175
internal async Task < TcpServerConnection > GetServerConnection ( string remoteHostName , int remotePort ,
176
176
Version httpVersion , bool isHttps , List < SslApplicationProtocol > applicationProtocols , bool isConnect ,
177
- ProxyServer proxyServer , IPEndPoint upStreamEndPoint , ExternalProxy externalProxy ,
177
+ ProxyServer proxyServer , SessionEventArgsBase session , IPEndPoint upStreamEndPoint , ExternalProxy externalProxy ,
178
178
bool noCache , CancellationToken cancellationToken )
179
179
{
180
180
var cacheKey = GetConnectionCacheKey ( remoteHostName , remotePort ,
@@ -205,7 +205,7 @@ internal async Task<TcpServerConnection> GetServerConnection(string remoteHostNa
205
205
}
206
206
207
207
var connection = await createServerConnection ( remoteHostName , remotePort , httpVersion , isHttps ,
208
- applicationProtocols , isConnect , proxyServer , upStreamEndPoint , externalProxy , cancellationToken ) ;
208
+ applicationProtocols , isConnect , proxyServer , session , upStreamEndPoint , externalProxy , cancellationToken ) ;
209
209
210
210
connection . CacheKey = cacheKey ;
211
211
@@ -222,13 +222,14 @@ internal async Task<TcpServerConnection> GetServerConnection(string remoteHostNa
222
222
/// <param name="applicationProtocols">The list of HTTPS application level protocol to negotiate if needed.</param>
223
223
/// <param name="isConnect">Is this a CONNECT request.</param>
224
224
/// <param name="proxyServer">The current ProxyServer instance.</param>
225
+ /// <param name="session">The http session.</param>
225
226
/// <param name="upStreamEndPoint">The local upstream endpoint to make request via.</param>
226
227
/// <param name="externalProxy">The external proxy to make request via.</param>
227
228
/// <param name="cancellationToken">The cancellation token for this async task.</param>
228
229
/// <returns></returns>
229
230
private async Task < TcpServerConnection > createServerConnection ( string remoteHostName , int remotePort ,
230
231
Version httpVersion , bool isHttps , List < SslApplicationProtocol > applicationProtocols , bool isConnect ,
231
- ProxyServer proxyServer , IPEndPoint upStreamEndPoint , ExternalProxy externalProxy ,
232
+ ProxyServer proxyServer , SessionEventArgsBase session , IPEndPoint upStreamEndPoint , ExternalProxy externalProxy ,
232
233
CancellationToken cancellationToken )
233
234
{
234
235
//deny connection to proxy end points to avoid infinite connection loop.
@@ -288,14 +289,14 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
288
289
var port = useUpstreamProxy ? externalProxy . Port : remotePort ;
289
290
290
291
var ipHostEntry = await Dns . GetHostEntryAsync ( hostname ) ;
291
-
292
292
if ( ipHostEntry == null || ipHostEntry . AddressList . Length == 0 )
293
293
{
294
294
throw new Exception ( $ "Could not resolve the hostname { hostname } ") ;
295
295
}
296
296
297
+ session . TimeLine [ "Dns Resolved" ] = DateTime . Now ;
298
+
297
299
var ipAddresses = ipHostEntry . AddressList . OrderBy ( x => rnd . Next ( ) ) . ToArray ( ) ;
298
-
299
300
300
301
for ( int i = 0 ; i < ipAddresses . Length ; i ++ )
301
302
{
@@ -308,11 +309,13 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
308
309
{
309
310
if ( i == ipAddresses . Length - 1 )
310
311
{
311
- throw new Exception ( $ "Could not resolve the hostname { hostname } ", e ) ;
312
+ throw new Exception ( $ "Could not establish connection to { hostname } ", e ) ;
312
313
}
313
314
}
314
315
}
315
316
317
+ session . TimeLine [ "Connection Established" ] = DateTime . Now ;
318
+
316
319
await proxyServer . InvokeConnectionCreateEvent ( tcpClient , false ) ;
317
320
318
321
stream = new CustomBufferedStream ( tcpClient . GetStream ( ) , proxyServer . BufferPool , proxyServer . BufferSize ) ;
@@ -368,6 +371,7 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
368
371
#if NETCOREAPP2_1
369
372
negotiatedApplicationProtocol = sslStream . NegotiatedApplicationProtocol ;
370
373
#endif
374
+ session . TimeLine [ "HTTPS Established" ] = DateTime . Now ;
371
375
}
372
376
}
373
377
catch ( Exception )
0 commit comments