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
c6150bf9
Unverified
Commit
c6150bf9
authored
Oct 16, 2019
by
honfika
Committed by
GitHub
Oct 16, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #650 from justcoding121/master
beta
parents
43e2988d
16cccdc5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
18 deletions
+74
-18
SessionEventArgsBase.cs
...Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
+1
-1
RunTime.cs
src/Titanium.Web.Proxy/Helpers/RunTime.cs
+59
-1
TcpConnectionFactory.cs
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+2
-5
TcpServerConnection.cs
src/Titanium.Web.Proxy/Network/Tcp/TcpServerConnection.cs
+5
-3
ProxyServer.cs
src/Titanium.Web.Proxy/ProxyServer.cs
+7
-8
No files found.
src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
View file @
c6150bf9
...
...
@@ -22,7 +22,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
private
static
bool
isWindowsAuthenticationSupported
=>
RunTime
.
IsWindows
;
internal
readonly
CancellationTokenSource
CancellationTokenSource
;
internal
readonly
CancellationTokenSource
?
CancellationTokenSource
;
internal
TcpServerConnection
ServerConnection
=>
HttpClient
.
Connection
;
...
...
src/Titanium.Web.Proxy/Helpers/RunTime.cs
View file @
c6150bf9
using
System
;
using
System
;
using
System.Reflection
;
using
System.Text
;
using
System.Runtime.InteropServices
;
using
System.Runtime.Versioning
;
namespace
Titanium.Web.Proxy.Helpers
{
...
...
@@ -41,6 +43,62 @@ namespace Titanium.Web.Proxy.Helpers
public
static
bool
IsUwpOnWindows
=>
IsWindows
&&
UwpHelper
.
IsRunningAsUwp
();
public
static
bool
IsMac
=>
isRunningOnMac
;
/// <summary>
/// Is socket reuse available to use?
/// </summary>
public
static
bool
IsSocketReuseAvailable
=>
isSocketReuseAvailable
();
private
static
bool
?
_isSocketReuseAvailable
;
private
static
bool
isSocketReuseAvailable
()
{
// use the cached value if we have one
if
(
_isSocketReuseAvailable
!=
null
)
return
_isSocketReuseAvailable
.
Value
;
try
{
if
(
IsWindows
)
{
// since we are on windows just return true
// store the result in our static object so we don't have to be bothered going through all this more than once
_isSocketReuseAvailable
=
true
;
return
true
;
}
// get the currently running framework name and version (EX: .NETFramework,Version=v4.5.1) (Ex: .NETCoreApp,Version=v2.0)
string
ver
=
Assembly
.
GetEntryAssembly
()?.
GetCustomAttribute
<
TargetFrameworkAttribute
>()?.
FrameworkName
;
if
(
ver
==
null
)
return
false
;
// play it safe if we can not figure out what the framework is
// make sure we are on .NETCoreApp
ver
=
ver
.
ToLower
();
// make everything lowercase to simplify comparison
if
(
ver
.
Contains
(
".netcoreapp"
))
{
var
versionString
=
ver
.
Replace
(
".netcoreapp,version=v"
,
""
);
var
versionArr
=
versionString
.
Split
(
'.'
);
var
majorVersion
=
Convert
.
ToInt32
(
versionArr
[
0
]);
var
result
=
majorVersion
>=
3
;
// version 3 and up supports socket reuse
// store the result in our static object so we don't have to be bothered going through all this more than once
_isSocketReuseAvailable
=
result
;
return
result
;
}
// store the result in our static object so we don't have to be bothered going through all this more than once
_isSocketReuseAvailable
=
false
;
return
false
;
}
catch
{
// store the result in our static object so we don't have to be bothered going through all this more than once
_isSocketReuseAvailable
=
false
;
return
false
;
}
}
// https://github.com/qmatteoq/DesktopBridgeHelpers/blob/master/DesktopBridge.Helpers/Helpers.cs
private
class
UwpHelper
...
...
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
c6150bf9
...
...
@@ -315,8 +315,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
tcpClient
.
SendTimeout
=
proxyServer
.
ConnectionTimeOutSeconds
*
1000
;
tcpClient
.
LingerState
=
new
LingerOption
(
true
,
proxyServer
.
TcpTimeWaitSeconds
);
// linux has a bug with socket reuse in .net core.
if
(
proxyServer
.
ReuseSocket
&&
RunTime
.
IsWindows
)
if
(
proxyServer
.
ReuseSocket
&&
RunTime
.
IsSocketReuseAvailable
)
{
tcpClient
.
Client
.
SetSocketOption
(
SocketOptionLevel
.
Socket
,
SocketOptionName
.
ReuseAddress
,
true
);
}
...
...
@@ -417,7 +416,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
throw
;
}
return
new
TcpServerConnection
(
proxyServer
,
tcpClient
)
return
new
TcpServerConnection
(
proxyServer
,
tcpClient
,
stream
)
{
UpStreamProxy
=
externalProxy
,
UpStreamEndPoint
=
upStreamEndPoint
,
...
...
@@ -426,8 +425,6 @@ namespace Titanium.Web.Proxy.Network.Tcp
IsHttps
=
isHttps
,
NegotiatedApplicationProtocol
=
negotiatedApplicationProtocol
,
UseUpstreamProxy
=
useUpstreamProxy
,
StreamWriter
=
new
HttpRequestWriter
(
stream
,
proxyServer
.
BufferPool
),
Stream
=
stream
,
Version
=
httpVersion
};
}
...
...
src/Titanium.Web.Proxy/Network/Tcp/TcpServerConnection.cs
View file @
c6150bf9
...
...
@@ -15,12 +15,14 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// </summary>
internal
class
TcpServerConnection
:
IDisposable
{
internal
TcpServerConnection
(
ProxyServer
proxyServer
,
TcpClient
tcpClient
)
internal
TcpServerConnection
(
ProxyServer
proxyServer
,
TcpClient
tcpClient
,
CustomBufferedStream
stream
)
{
this
.
tcpClient
=
tcpClient
;
LastAccess
=
DateTime
.
Now
;
this
.
proxyServer
=
proxyServer
;
this
.
proxyServer
.
UpdateServerConnectionCount
(
true
);
StreamWriter
=
new
HttpRequestWriter
(
stream
,
proxyServer
.
BufferPool
);
Stream
=
stream
;
}
private
ProxyServer
proxyServer
{
get
;
}
...
...
@@ -59,12 +61,12 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <summary>
/// Used to write lines to server
/// </summary>
internal
HttpRequestWriter
?
StreamWriter
{
get
;
s
et
;
}
internal
HttpRequestWriter
StreamWriter
{
g
et
;
}
/// <summary>
/// Server stream
/// </summary>
internal
CustomBufferedStream
?
Stream
{
get
;
s
et
;
}
internal
CustomBufferedStream
Stream
{
g
et
;
}
/// <summary>
/// Last time this connection was used
...
...
src/Titanium.Web.Proxy/ProxyServer.cs
View file @
c6150bf9
...
...
@@ -55,7 +55,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// Upstream proxy manager.
/// </summary>
private
WinHttpWebProxyFinder
systemProxyResolver
;
private
WinHttpWebProxyFinder
?
systemProxyResolver
;
/// <inheritdoc />
...
...
@@ -421,7 +421,7 @@ namespace Titanium.Web.Proxy
/// <param name="protocolType">The proxy protocol type.</param>
public
void
SetAsSystemProxy
(
ExplicitProxyEndPoint
endPoint
,
ProxyProtocolType
protocolType
)
{
if
(
!
RunTime
.
IsWindows
)
if
(
systemProxySettingsManager
==
null
)
{
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."
);
...
...
@@ -515,7 +515,7 @@ namespace Titanium.Web.Proxy
/// </summary>
public
void
RestoreOriginalProxySettings
()
{
if
(
!
RunTime
.
IsWindows
)
if
(
systemProxySettingsManager
==
null
)
{
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."
);
...
...
@@ -529,7 +529,7 @@ namespace Titanium.Web.Proxy
/// </summary>
public
void
DisableSystemProxy
(
ProxyProtocolType
protocolType
)
{
if
(
!
RunTime
.
IsWindows
)
if
(
systemProxySettingsManager
==
null
)
{
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."
);
...
...
@@ -543,7 +543,7 @@ namespace Titanium.Web.Proxy
/// </summary>
public
void
DisableAllSystemProxies
()
{
if
(
!
RunTime
.
IsWindows
)
if
(
systemProxySettingsManager
==
null
)
{
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."
);
...
...
@@ -622,7 +622,7 @@ namespace Titanium.Web.Proxy
throw
new
Exception
(
"Proxy is not running."
);
}
if
(
RunTime
.
IsWindows
&&
!
RunTime
.
IsUwpOnWindows
)
if
(
systemProxySettingsManager
!=
null
)
{
bool
setAsSystemProxy
=
ProxyEndPoints
.
OfType
<
ExplicitProxyEndPoint
>()
.
Any
(
x
=>
x
.
IsSystemHttpProxy
||
x
.
IsSystemHttpsProxy
);
...
...
@@ -654,8 +654,7 @@ namespace Titanium.Web.Proxy
{
endPoint
.
Listener
=
new
TcpListener
(
endPoint
.
IpAddress
,
endPoint
.
Port
);
// linux/macOS has a bug with socket reuse in .net core.
if
(
ReuseSocket
&&
RunTime
.
IsWindows
)
if
(
ReuseSocket
&&
RunTime
.
IsSocketReuseAvailable
)
{
endPoint
.
Listener
.
Server
.
SetSocketOption
(
SocketOptionLevel
.
Socket
,
SocketOptionName
.
ReuseAddress
,
true
);
}
...
...
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