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
583695f3
Commit
583695f3
authored
Dec 27, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code simplified with C# 7 features
parent
4f49c7c9
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
59 additions
and
98 deletions
+59
-98
ConsoleHelper.cs
...itanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs
+1
-2
MainWindow.xaml.cs
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
+9
-13
SessionListItem.cs
Examples/Titanium.Web.Proxy.Examples.Wpf/SessionListItem.cs
+16
-16
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+1
-1
Network.cs
Titanium.Web.Proxy/Helpers/Network.cs
+1
-3
WinHttpWebProxyFinder.cs
Titanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs
+1
-2
HeaderCollection.cs
Titanium.Web.Proxy/Http/HeaderCollection.cs
+2
-4
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+2
-8
Request.cs
Titanium.Web.Proxy/Http/Request.cs
+5
-18
Response.cs
Titanium.Web.Proxy/Http/Response.cs
+1
-2
ExternalProxy.cs
Titanium.Web.Proxy/Models/ExternalProxy.cs
+2
-2
CertificateManager.cs
Titanium.Web.Proxy/Network/CertificateManager.cs
+4
-4
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+11
-11
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+3
-12
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs
View file @
583695f3
...
...
@@ -28,8 +28,7 @@ namespace Titanium.Web.Proxy.Examples.Basic.Helpers
var
consoleHandle
=
GetStdHandle
(
STD_INPUT_HANDLE
);
// get current console mode
uint
consoleMode
;
if
(!
GetConsoleMode
(
consoleHandle
,
out
consoleMode
))
if
(!
GetConsoleMode
(
consoleHandle
,
out
uint
consoleMode
))
{
// ERROR: Unable to get console mode.
return
false
;
...
...
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
View file @
583695f3
...
...
@@ -28,7 +28,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
public
SessionListItem
SelectedSession
{
get
{
return
selectedSession
;
}
get
=>
selectedSession
;
set
{
if
(
value
!=
selectedSession
)
...
...
@@ -44,8 +44,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf
public
int
ClientConnectionCount
{
get
{
return
(
int
)
GetValue
(
ClientConnectionCountProperty
);
}
set
{
SetValue
(
ClientConnectionCountProperty
,
value
);
}
get
=>
(
int
)
GetValue
(
ClientConnectionCountProperty
);
set
=>
SetValue
(
ClientConnectionCountProperty
,
value
);
}
public
static
readonly
DependencyProperty
ServerConnectionCountProperty
=
DependencyProperty
.
Register
(
...
...
@@ -53,8 +53,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf
public
int
ServerConnectionCount
{
get
{
return
(
int
)
GetValue
(
ServerConnectionCountProperty
);
}
set
{
SetValue
(
ServerConnectionCountProperty
,
value
);
}
get
=>
(
int
)
GetValue
(
ServerConnectionCountProperty
);
set
=>
SetValue
(
ServerConnectionCountProperty
,
value
);
}
private
readonly
Dictionary
<
HttpWebClient
,
SessionListItem
>
sessionDictionary
=
new
Dictionary
<
HttpWebClient
,
SessionListItem
>();
...
...
@@ -107,8 +107,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
{
await
Dispatcher
.
InvokeAsync
(()
=>
{
SessionListItem
item
;
if
(
sessionDictionary
.
TryGetValue
(
e
.
WebSession
,
out
item
))
if
(
sessionDictionary
.
TryGetValue
(
e
.
WebSession
,
out
var
item
))
{
item
.
Update
();
}
...
...
@@ -135,8 +134,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
SessionListItem
item
=
null
;
await
Dispatcher
.
InvokeAsync
(()
=>
{
SessionListItem
item2
;
if
(
sessionDictionary
.
TryGetValue
(
e
.
WebSession
,
out
item2
))
if
(
sessionDictionary
.
TryGetValue
(
e
.
WebSession
,
out
var
item2
))
{
item2
.
Update
();
item
=
item2
;
...
...
@@ -177,8 +175,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
e
.
DataReceived
+=
(
sender
,
args
)
=>
{
var
session
=
(
SessionEventArgs
)
sender
;
SessionListItem
li
;
if
(
sessionDictionary
.
TryGetValue
(
session
.
WebSession
,
out
li
))
if
(
sessionDictionary
.
TryGetValue
(
session
.
WebSession
,
out
var
li
))
{
li
.
ReceivedDataCount
+=
args
.
Count
;
}
...
...
@@ -187,8 +184,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
e
.
DataSent
+=
(
sender
,
args
)
=>
{
var
session
=
(
SessionEventArgs
)
sender
;
SessionListItem
li
;
if
(
sessionDictionary
.
TryGetValue
(
session
.
WebSession
,
out
li
))
if
(
sessionDictionary
.
TryGetValue
(
session
.
WebSession
,
out
var
li
))
{
li
.
SentDataCount
+=
args
.
Count
;
}
...
...
Examples/Titanium.Web.Proxy.Examples.Wpf/SessionListItem.cs
View file @
583695f3
...
...
@@ -26,50 +26,50 @@ namespace Titanium.Web.Proxy.Examples.Wpf
public
string
StatusCode
{
get
{
return
statusCode
;
}
set
{
SetField
(
ref
statusCode
,
value
);}
get
=>
statusCode
;
set
=>
SetField
(
ref
statusCode
,
value
);
}
public
string
Protocol
{
get
{
return
protocol
;
}
set
{
SetField
(
ref
protocol
,
value
);
}
get
=>
protocol
;
set
=>
SetField
(
ref
protocol
,
value
);
}
public
string
Host
{
get
{
return
host
;
}
set
{
SetField
(
ref
host
,
value
);
}
get
=>
host
;
set
=>
SetField
(
ref
host
,
value
);
}
public
string
Url
{
get
{
return
url
;
}
set
{
SetField
(
ref
url
,
value
);
}
get
=>
url
;
set
=>
SetField
(
ref
url
,
value
);
}
public
long
BodySize
{
get
{
return
bodySize
;
}
set
{
SetField
(
ref
bodySize
,
value
);
}
get
=>
bodySize
;
set
=>
SetField
(
ref
bodySize
,
value
);
}
public
string
Process
{
get
{
return
process
;
}
set
{
SetField
(
ref
process
,
value
);
}
get
=>
process
;
set
=>
SetField
(
ref
process
,
value
);
}
public
long
ReceivedDataCount
{
get
{
return
receivedDataCount
;
}
set
{
SetField
(
ref
receivedDataCount
,
value
);
}
get
=>
receivedDataCount
;
set
=>
SetField
(
ref
receivedDataCount
,
value
);
}
public
long
SentDataCount
{
get
{
return
sentDataCount
;
}
set
{
SetField
(
ref
sentDataCount
,
value
);
}
get
=>
sentDataCount
;
set
=>
SetField
(
ref
sentDataCount
,
value
);
}
public
event
PropertyChangedEventHandler
PropertyChanged
;
...
...
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
583695f3
...
...
@@ -53,7 +53,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
public
bool
ReRequest
{
get
{
return
reRequest
;
}
get
=>
reRequest
;
set
{
if
(
WebSession
.
Response
.
StatusCode
==
0
)
...
...
Titanium.Web.Proxy/Helpers/Network.cs
View file @
583695f3
...
...
@@ -54,9 +54,7 @@ namespace Titanium.Web.Proxy.Helpers
{
localhost
=
Dns
.
GetHostEntry
(
Dns
.
GetHostName
());
IPAddress
ipAddress
;
if
(
IPAddress
.
TryParse
(
hostName
,
out
ipAddress
))
if
(
IPAddress
.
TryParse
(
hostName
,
out
var
ipAddress
))
isLocalhost
=
localhost
.
AddressList
.
Any
(
x
=>
x
.
Equals
(
ipAddress
));
if
(!
isLocalhost
)
...
...
Titanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs
View file @
583695f3
...
...
@@ -81,8 +81,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
public
ExternalProxy
GetProxy
(
Uri
destination
)
{
IList
<
string
>
proxies
;
if
(
GetAutoProxies
(
destination
,
out
proxies
))
if
(
GetAutoProxies
(
destination
,
out
var
proxies
))
{
if
(
proxies
==
null
)
{
...
...
Titanium.Web.Proxy/Http/HeaderCollection.cs
View file @
583695f3
...
...
@@ -227,8 +227,7 @@ namespace Titanium.Web.Proxy.Http
internal
string
GetHeaderValueOrNull
(
string
headerName
)
{
HttpHeader
header
;
if
(
Headers
.
TryGetValue
(
headerName
,
out
header
))
if
(
Headers
.
TryGetValue
(
headerName
,
out
var
header
))
{
return
header
.
Value
;
}
...
...
@@ -238,8 +237,7 @@ namespace Titanium.Web.Proxy.Http
internal
string
SetOrAddHeaderValue
(
string
headerName
,
string
value
)
{
HttpHeader
header
;
if
(
Headers
.
TryGetValue
(
headerName
,
out
header
))
if
(
Headers
.
TryGetValue
(
headerName
,
out
var
header
))
{
header
.
Value
=
value
;
}
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
583695f3
...
...
@@ -136,10 +136,7 @@ namespace Titanium.Web.Proxy.Http
{
string
httpStatus
=
await
ServerConnection
.
StreamReader
.
ReadLineAsync
();
Version
version
;
int
responseStatusCode
;
string
responseStatusDescription
;
Response
.
ParseResponseLine
(
httpStatus
,
out
version
,
out
responseStatusCode
,
out
responseStatusDescription
);
Response
.
ParseResponseLine
(
httpStatus
,
out
_
,
out
int
responseStatusCode
,
out
string
responseStatusDescription
);
//find if server is willing for expect continue
if
(
responseStatusCode
==
(
int
)
HttpStatusCode
.
Continue
...
...
@@ -180,10 +177,7 @@ namespace Titanium.Web.Proxy.Http
httpStatus
=
await
ServerConnection
.
StreamReader
.
ReadLineAsync
();
}
Version
version
;
int
statusCode
;
string
statusDescription
;
Response
.
ParseResponseLine
(
httpStatus
,
out
version
,
out
statusCode
,
out
statusDescription
);
Response
.
ParseResponseLine
(
httpStatus
,
out
var
version
,
out
int
statusCode
,
out
string
statusDescription
);
Response
.
HttpVersion
=
version
;
Response
.
StatusCode
=
statusCode
;
...
...
Titanium.Web.Proxy/Http/Request.cs
View file @
583695f3
...
...
@@ -66,14 +66,8 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
public
string
Host
{
get
{
return
Headers
.
GetHeaderValueOrNull
(
"host"
);
}
set
{
Headers
.
SetOrAddHeaderValue
(
"host"
,
value
);
}
get
=>
Headers
.
GetHeaderValueOrNull
(
"host"
);
set
=>
Headers
.
SetOrAddHeaderValue
(
"host"
,
value
);
}
/// <summary>
...
...
@@ -95,8 +89,7 @@ namespace Titanium.Web.Proxy.Http
return
-
1
;
}
long
contentLen
;
long
.
TryParse
(
headerValue
,
out
contentLen
);
long
.
TryParse
(
headerValue
,
out
long
contentLen
);
if
(
contentLen
>=
0
)
{
return
contentLen
;
...
...
@@ -123,14 +116,8 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
public
string
ContentType
{
get
{
return
Headers
.
GetHeaderValueOrNull
(
"content-type"
);
}
set
{
Headers
.
SetOrAddHeaderValue
(
"content-type"
,
value
);
}
get
=>
Headers
.
GetHeaderValueOrNull
(
"content-type"
);
set
=>
Headers
.
SetOrAddHeaderValue
(
"content-type"
,
value
);
}
/// <summary>
...
...
Titanium.Web.Proxy/Http/Response.cs
View file @
583695f3
...
...
@@ -118,8 +118,7 @@ namespace Titanium.Web.Proxy.Http
return
-
1
;
}
long
contentLen
;
long
.
TryParse
(
headerValue
,
out
contentLen
);
long
.
TryParse
(
headerValue
,
out
long
contentLen
);
if
(
contentLen
>=
0
)
{
return
contentLen
;
...
...
Titanium.Web.Proxy/Models/ExternalProxy.cs
View file @
583695f3
...
...
@@ -28,7 +28,7 @@ namespace Titanium.Web.Proxy.Models
/// </summary>
public
string
UserName
{
get
{
return
UseDefaultCredentials
?
defaultCredentials
.
Value
.
UserName
:
userName
;
}
get
=>
UseDefaultCredentials
?
defaultCredentials
.
Value
.
UserName
:
userName
;
set
{
userName
=
value
;
...
...
@@ -45,7 +45,7 @@ namespace Titanium.Web.Proxy.Models
/// </summary>
public
string
Password
{
get
{
return
UseDefaultCredentials
?
defaultCredentials
.
Value
.
Password
:
password
;
}
get
=>
UseDefaultCredentials
?
defaultCredentials
.
Value
.
Password
:
password
;
set
{
password
=
value
;
...
...
Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
583695f3
...
...
@@ -36,7 +36,7 @@ namespace Titanium.Web.Proxy.Network
{
internal
CertificateEngine
Engine
{
get
{
return
engine
;
}
get
=>
engine
;
set
{
//For Mono (or Non-Windows) only Bouncy Castle is supported
...
...
@@ -83,7 +83,7 @@ namespace Titanium.Web.Proxy.Network
internal
string
Issuer
{
get
{
return
issuer
??
defaultRootCertificateIssuer
;
}
get
=>
issuer
??
defaultRootCertificateIssuer
;
set
{
issuer
=
value
;
...
...
@@ -93,7 +93,7 @@ namespace Titanium.Web.Proxy.Network
internal
string
RootCertificateName
{
get
{
return
rootCertificateName
??
defaultRootRootCertificateName
;
}
get
=>
rootCertificateName
??
defaultRootRootCertificateName
;
set
{
rootCertificateName
=
value
;
...
...
@@ -103,7 +103,7 @@ namespace Titanium.Web.Proxy.Network
internal
X509Certificate2
RootCertificate
{
get
{
return
rootCertificate
;
}
get
=>
rootCertificate
;
set
{
ClearRootCertificate
();
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
583695f3
...
...
@@ -84,8 +84,8 @@ namespace Titanium.Web.Proxy
/// </summary>
public
X509Certificate2
RootCertificate
{
get
{
return
CertificateManager
.
RootCertificate
;
}
set
{
CertificateManager
.
RootCertificate
=
value
;
}
get
=>
CertificateManager
.
RootCertificate
;
set
=>
CertificateManager
.
RootCertificate
=
value
;
}
/// <summary>
...
...
@@ -94,8 +94,8 @@ namespace Titanium.Web.Proxy
/// </summary>
public
string
RootCertificateIssuerName
{
get
{
return
CertificateManager
.
Issuer
;
}
set
{
CertificateManager
.
Issuer
=
value
;
}
get
=>
CertificateManager
.
Issuer
;
set
=>
CertificateManager
.
Issuer
=
value
;
}
/// <summary>
...
...
@@ -107,8 +107,8 @@ namespace Titanium.Web.Proxy
/// </summary>
public
string
RootCertificateName
{
get
{
return
CertificateManager
.
RootCertificateName
;
}
set
{
CertificateManager
.
RootCertificateName
=
value
;
}
get
=>
CertificateManager
.
RootCertificateName
;
set
=>
CertificateManager
.
RootCertificateName
=
value
;
}
/// <summary>
...
...
@@ -118,7 +118,7 @@ namespace Titanium.Web.Proxy
/// </summary>
public
bool
TrustRootCertificate
{
get
{
return
trustRootCertificate
;
}
get
=>
trustRootCertificate
;
set
{
trustRootCertificate
=
value
;
...
...
@@ -136,8 +136,8 @@ namespace Titanium.Web.Proxy
/// </summary>
public
CertificateEngine
CertificateEngine
{
get
{
return
CertificateManager
.
Engine
;
}
set
{
CertificateManager
.
Engine
=
value
;
}
get
=>
CertificateManager
.
Engine
;
set
=>
CertificateManager
.
Engine
=
value
;
}
/// <summary>
...
...
@@ -242,8 +242,8 @@ namespace Titanium.Web.Proxy
/// </summary>
public
Action
<
Exception
>
ExceptionFunc
{
get
{
return
exceptionFunc
??
defaultExceptionFunc
.
Value
;
}
set
{
exceptionFunc
=
value
;
}
get
=>
exceptionFunc
??
defaultExceptionFunc
.
Value
;
set
=>
exceptionFunc
=
value
;
}
/// <summary>
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
583695f3
...
...
@@ -53,10 +53,7 @@ namespace Titanium.Web.Proxy
return
;
}
string
httpMethod
;
string
httpUrl
;
Version
version
;
Request
.
ParseRequestLine
(
httpCmd
,
out
httpMethod
,
out
httpUrl
,
out
version
);
Request
.
ParseRequestLine
(
httpCmd
,
out
string
httpMethod
,
out
string
httpUrl
,
out
var
version
);
httpRemoteUri
=
httpMethod
==
"CONNECT"
?
new
Uri
(
"http://"
+
httpUrl
)
:
new
Uri
(
httpUrl
);
...
...
@@ -306,10 +303,7 @@ namespace Titanium.Web.Proxy
try
{
string
httpMethod
;
string
httpUrl
;
Version
version
;
Request
.
ParseRequestLine
(
httpCmd
,
out
httpMethod
,
out
httpUrl
,
out
version
);
Request
.
ParseRequestLine
(
httpCmd
,
out
string
httpMethod
,
out
string
httpUrl
,
out
var
version
);
//Read the request headers in to unique and non-unique header collections
await
HeaderParser
.
ReadHeaders
(
clientStreamReader
,
args
.
WebSession
.
Request
.
Headers
);
...
...
@@ -390,10 +384,7 @@ namespace Titanium.Web.Proxy
await
connection
.
Stream
.
WriteAsync
(
requestBytes
,
0
,
requestBytes
.
Length
);
string
httpStatus
=
await
connection
.
StreamReader
.
ReadLineAsync
();
Version
responseVersion
;
int
responseStatusCode
;
string
responseStatusDescription
;
Response
.
ParseResponseLine
(
httpStatus
,
out
responseVersion
,
out
responseStatusCode
,
out
responseStatusDescription
);
Response
.
ParseResponseLine
(
httpStatus
,
out
var
responseVersion
,
out
int
responseStatusCode
,
out
string
responseStatusDescription
);
args
.
WebSession
.
Response
.
HttpVersion
=
responseVersion
;
args
.
WebSession
.
Response
.
StatusCode
=
responseStatusCode
;
args
.
WebSession
.
Response
.
StatusDescription
=
responseStatusDescription
;
...
...
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