Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
5cb49c70
Commit
5cb49c70
authored
Feb 13, 2019
by
jmh76
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master'
parents
9570acbb
771ccfb4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
11 deletions
+63
-11
ExplicitClientHandler.cs
src/Titanium.Web.Proxy/ExplicitClientHandler.cs
+1
-1
RequestHandler.cs
src/Titanium.Web.Proxy/RequestHandler.cs
+6
-3
TestHelper.cs
...Titanium.Web.Proxy.IntegrationTests/Helpers/TestHelper.cs
+10
-5
NestedProxyTests.cs
...s/Titanium.Web.Proxy.IntegrationTests/NestedProxyTests.cs
+44
-0
TestSuite.cs
tests/Titanium.Web.Proxy.IntegrationTests/Setup/TestSuite.cs
+2
-2
No files found.
src/Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
5cb49c70
...
...
@@ -321,7 +321,7 @@ namespace Titanium.Web.Proxy
calledRequestHandler
=
true
;
// Now create the request
await
handleHttpSessionRequest
(
endPoint
,
clientConnection
,
clientStream
,
clientStreamWriter
,
cancellationTokenSource
,
connectHostname
,
connectArgs
?.
HttpClient
.
ConnectRequest
,
prefetchConnectionTask
);
cancellationTokenSource
,
connectHostname
,
connectArgs
,
prefetchConnectionTask
);
}
catch
(
ProxyException
e
)
{
...
...
src/Titanium.Web.Proxy/RequestHandler.cs
View file @
5cb49c70
...
...
@@ -47,9 +47,11 @@ namespace Titanium.Web.Proxy
/// <param name="prefetchConnectionTask">Prefetched server connection for current client using Connect/SNI headers.</param>
private
async
Task
handleHttpSessionRequest
(
ProxyEndPoint
endPoint
,
TcpClientConnection
clientConnection
,
CustomBufferedStream
clientStream
,
HttpResponseWriter
clientStreamWriter
,
CancellationTokenSource
cancellationTokenSource
,
string
httpsConnectHostname
,
ConnectRequest
connectRequest
,
CancellationTokenSource
cancellationTokenSource
,
string
httpsConnectHostname
,
TunnelConnectSessionEventArgs
connectArgs
,
Task
<
TcpServerConnection
>
prefetchConnectionTask
=
null
)
{
var
connectRequest
=
connectArgs
?.
HttpClient
.
ConnectRequest
;
var
prefetchTask
=
prefetchConnectionTask
;
TcpServerConnection
connection
=
null
;
bool
closeServerConnection
=
false
;
...
...
@@ -73,7 +75,8 @@ namespace Titanium.Web.Proxy
var
args
=
new
SessionEventArgs
(
this
,
endPoint
,
cancellationTokenSource
)
{
ProxyClient
=
{
Connection
=
clientConnection
},
HttpClient
=
{
ConnectRequest
=
connectRequest
}
HttpClient
=
{
ConnectRequest
=
connectRequest
},
UserData
=
connectArgs
?.
UserData
};
try
...
...
@@ -204,7 +207,7 @@ namespace Titanium.Web.Proxy
//update connection to latest used
connection
=
result
.
LatestConnection
;
closeServerConnection
=
!
result
.
Continue
;
closeServerConnection
=
!
result
.
Continue
;
//throw if exception happened
if
(!
result
.
IsSuccess
)
...
...
tests/Titanium.Web.Proxy.IntegrationTests/Helpers/TestHelper.cs
View file @
5cb49c70
...
...
@@ -6,14 +6,15 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers
{
public
static
class
TestHelper
{
public
static
HttpClient
GetHttpClient
(
int
localProxyPort
)
public
static
HttpClient
GetHttpClient
(
int
localProxyPort
,
bool
enableBasicProxyAuthorization
=
false
)
{
var
proxy
=
new
TestProxy
(
$"http://localhost:
{
localProxyPort
}
"
);
var
proxy
=
new
TestProxy
(
$"http://localhost:
{
localProxyPort
}
"
,
enableBasicProxyAuthorization
);
var
handler
=
new
HttpClientHandler
{
Proxy
=
proxy
,
UseProxy
=
true
UseProxy
=
true
};
return
new
HttpClient
(
handler
);
...
...
@@ -29,12 +30,16 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers
public
Uri
ProxyUri
{
get
;
set
;
}
public
ICredentials
Credentials
{
get
;
set
;
}
public
TestProxy
(
string
proxyUri
)
public
TestProxy
(
string
proxyUri
,
bool
enableAuthorization
)
:
this
(
new
Uri
(
proxyUri
))
{
if
(
enableAuthorization
)
{
Credentials
=
new
NetworkCredential
(
"test"
,
"Test56"
);
}
}
p
ublic
TestProxy
(
Uri
proxyUri
)
p
rivate
TestProxy
(
Uri
proxyUri
)
{
this
.
ProxyUri
=
proxyUri
;
}
...
...
tests/Titanium.Web.Proxy.IntegrationTests/NestedProxyTests.cs
View file @
5cb49c70
...
...
@@ -3,6 +3,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using
System
;
using
System.Net
;
using
System.Net.Http
;
using
System.Net.Http.Headers
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Titanium.Web.Proxy.IntegrationTests
...
...
@@ -35,5 +37,47 @@ namespace Titanium.Web.Proxy.IntegrationTests
Assert
.
AreEqual
(
"I am server. I received your greetings."
,
body
);
}
[
TestMethod
]
public
async
Task
Smoke_Test_Nested_Proxy_UserData
()
{
var
testSuite
=
new
TestSuite
();
var
server
=
testSuite
.
GetServer
();
server
.
HandleRequest
((
context
)
=>
{
return
context
.
Response
.
WriteAsync
(
"I am server. I received your greetings."
);
});
var
proxy1
=
testSuite
.
GetProxy
();
proxy1
.
ProxyBasicAuthenticateFunc
=
async
(
session
,
username
,
password
)
=>
{
session
.
UserData
=
"Test"
;
return
await
Task
.
FromResult
(
true
);
};
var
proxy2
=
testSuite
.
GetProxy
();
proxy1
.
GetCustomUpStreamProxyFunc
=
async
(
session
)
=>
{
Assert
.
AreEqual
(
"Test"
,
session
.
UserData
);
return
await
Task
.
FromResult
(
new
Models
.
ExternalProxy
()
{
HostName
=
"localhost"
,
Port
=
proxy2
.
ProxyEndPoints
[
0
].
Port
});
};
var
client
=
testSuite
.
GetClient
(
proxy1
,
true
);
var
response
=
await
client
.
PostAsync
(
new
Uri
(
server
.
ListeningHttpsUrl
),
new
StringContent
(
"hello server. I am a client."
));
Assert
.
AreEqual
(
HttpStatusCode
.
OK
,
response
.
StatusCode
);
var
body
=
await
response
.
Content
.
ReadAsStringAsync
();
Assert
.
AreEqual
(
"I am server. I received your greetings."
,
body
);
}
}
}
tests/Titanium.Web.Proxy.IntegrationTests/Setup/TestSuite.cs
View file @
5cb49c70
...
...
@@ -43,9 +43,9 @@ namespace Titanium.Web.Proxy.IntegrationTests
return
new
TestProxyServer
(
true
).
ProxyServer
;
}
public
HttpClient
GetClient
(
ProxyServer
proxyServer
)
public
HttpClient
GetClient
(
ProxyServer
proxyServer
,
bool
enableBasicProxyAuthorization
=
false
)
{
return
TestHelper
.
GetHttpClient
(
proxyServer
.
ProxyEndPoints
[
0
].
Port
);
return
TestHelper
.
GetHttpClient
(
proxyServer
.
ProxyEndPoints
[
0
].
Port
,
enableBasicProxyAuthorization
);
}
public
HttpClient
GetReverseProxyClient
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment