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
6cb2ed4f
Commit
6cb2ed4f
authored
Jul 12, 2015
by
titanium007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add inline comments
parent
0381ef56
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
57 deletions
+52
-57
NetFramework.cs
Titanium.Web.Proxy/Helpers/NetFramework.cs
+1
-0
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+6
-7
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+36
-33
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+9
-17
No files found.
Titanium.Web.Proxy/Helpers/NetFramework.cs
View file @
6cb2ed4f
...
@@ -8,6 +8,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -8,6 +8,7 @@ namespace Titanium.Web.Proxy.Helpers
{
{
public
class
NetFrameworkHelper
public
class
NetFrameworkHelper
{
{
//http://stackoverflow.com/questions/856885/httpwebrequest-to-url-with-dot-at-the-end
public
static
void
URLPeriodFix
()
public
static
void
URLPeriodFix
()
{
{
MethodInfo
getSyntax
=
typeof
(
UriParser
).
GetMethod
(
"GetSyntax"
,
System
.
Reflection
.
BindingFlags
.
Static
|
System
.
Reflection
.
BindingFlags
.
NonPublic
);
MethodInfo
getSyntax
=
typeof
(
UriParser
).
GetMethod
(
"GetSyntax"
,
System
.
Reflection
.
BindingFlags
.
Static
|
System
.
Reflection
.
BindingFlags
.
NonPublic
);
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
6cb2ed4f
...
@@ -74,6 +74,7 @@ namespace Titanium.Web.Proxy
...
@@ -74,6 +74,7 @@ namespace Titanium.Web.Proxy
ServicePointManager
.
DnsRefreshTimeout
=
3
*
60
*
1000
;
//3 minutes
ServicePointManager
.
DnsRefreshTimeout
=
3
*
60
*
1000
;
//3 minutes
ServicePointManager
.
MaxServicePointIdleTime
=
3
*
60
*
1000
;
ServicePointManager
.
MaxServicePointIdleTime
=
3
*
60
*
1000
;
//HttpWebRequest certificate validation callback
ServicePointManager
.
ServerCertificateValidationCallback
=
delegate
(
object
s
,
X509Certificate
certificate
,
X509Chain
chain
,
SslPolicyErrors
sslPolicyErrors
)
ServicePointManager
.
ServerCertificateValidationCallback
=
delegate
(
object
s
,
X509Certificate
certificate
,
X509Chain
chain
,
SslPolicyErrors
sslPolicyErrors
)
{
{
if
(
sslPolicyErrors
==
SslPolicyErrors
.
None
)
return
true
;
if
(
sslPolicyErrors
==
SslPolicyErrors
.
None
)
return
true
;
...
@@ -81,6 +82,7 @@ namespace Titanium.Web.Proxy
...
@@ -81,6 +82,7 @@ namespace Titanium.Web.Proxy
return
false
;
return
false
;
};
};
//Fix a bug in .NET 4.0
NetFrameworkHelper
.
URLPeriodFix
();
NetFrameworkHelper
.
URLPeriodFix
();
}
}
...
@@ -107,6 +109,7 @@ namespace Titanium.Web.Proxy
...
@@ -107,6 +109,7 @@ namespace Titanium.Web.Proxy
RootCertificateName
=
RootCertificateName
==
null
?
"Titanium_Proxy_Test_Root"
:
RootCertificateName
;
RootCertificateName
=
RootCertificateName
==
null
?
"Titanium_Proxy_Test_Root"
:
RootCertificateName
;
bool
certTrusted
=
CertManager
.
CreateTrustedRootCertificate
();
bool
certTrusted
=
CertManager
.
CreateTrustedRootCertificate
();
//If certificate was trusted by the machine
if
(
certTrusted
)
if
(
certTrusted
)
{
{
SystemProxyHelper
.
EnableProxyHTTPS
(
"localhost"
,
ListeningPort
);
SystemProxyHelper
.
EnableProxyHTTPS
(
"localhost"
,
ListeningPort
);
...
@@ -150,11 +153,7 @@ namespace Titanium.Web.Proxy
...
@@ -150,11 +153,7 @@ namespace Titanium.Web.Proxy
}
}
}
}
catch
(
ThreadInterruptedException
)
{
}
catch
(
ThreadInterruptedException
)
{
}
catch
(
SocketException
)
catch
(
SocketException
)
{
}
{
}
}
}
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
6cb2ed4f
This diff is collapsed.
Click to expand it.
Titanium.Web.Proxy/ResponseHandler.cs
View file @
6cb2ed4f
...
@@ -17,6 +17,7 @@ namespace Titanium.Web.Proxy
...
@@ -17,6 +17,7 @@ namespace Titanium.Web.Proxy
{
{
partial
class
ProxyServer
partial
class
ProxyServer
{
{
//Called asynchronously when a request was successfully and we received the response
private
static
void
HandleHttpSessionResponse
(
IAsyncResult
AsynchronousResult
)
private
static
void
HandleHttpSessionResponse
(
IAsyncResult
AsynchronousResult
)
{
{
...
@@ -27,7 +28,8 @@ namespace Titanium.Web.Proxy
...
@@ -27,7 +28,8 @@ namespace Titanium.Web.Proxy
}
}
catch
(
WebException
webEx
)
catch
(
WebException
webEx
)
{
{
args
.
ProxyRequest
.
KeepAlive
=
false
;
//Things line 404, 500 etc
//args.ProxyRequest.KeepAlive = false;
args
.
ServerResponse
=
webEx
.
Response
as
HttpWebResponse
;
args
.
ServerResponse
=
webEx
.
Response
as
HttpWebResponse
;
}
}
...
@@ -109,35 +111,25 @@ namespace Titanium.Web.Proxy
...
@@ -109,35 +111,25 @@ namespace Titanium.Web.Proxy
}
}
catch
(
IOException
ex
)
catch
(
IOException
)
{
{
args
.
ProxyRequest
.
KeepAlive
=
false
;
args
.
ProxyRequest
.
KeepAlive
=
false
;
Debug
.
WriteLine
(
ex
.
Message
);
}
}
catch
(
SocketException
ex
)
catch
(
SocketException
ex
)
{
{
args
.
ProxyRequest
.
KeepAlive
=
false
;
args
.
ProxyRequest
.
KeepAlive
=
false
;
Debug
.
WriteLine
(
ex
.
Message
);
}
}
catch
(
ArgumentException
ex
)
catch
(
ArgumentException
)
{
{
args
.
ProxyRequest
.
KeepAlive
=
false
;
args
.
ProxyRequest
.
KeepAlive
=
false
;
Debug
.
WriteLine
(
ex
.
Message
);
}
}
catch
(
WebException
ex
)
catch
(
WebException
)
{
{
args
.
ProxyRequest
.
KeepAlive
=
false
;
args
.
ProxyRequest
.
KeepAlive
=
false
;
Debug
.
WriteLine
(
ex
.
Message
);
}
}
finally
finally
{
{
//Close this HttpWebRequest session
if
(
args
.
ProxyRequest
!=
null
)
args
.
ProxyRequest
.
Abort
();
if
(
args
.
ProxyRequest
!=
null
)
args
.
ProxyRequest
.
Abort
();
if
(
args
.
ServerResponseStream
!=
null
)
args
.
ServerResponseStream
.
Close
();
if
(
args
.
ServerResponseStream
!=
null
)
args
.
ServerResponseStream
.
Close
();
...
@@ -146,6 +138,7 @@ namespace Titanium.Web.Proxy
...
@@ -146,6 +138,7 @@ namespace Titanium.Web.Proxy
}
}
//If this is false then terminate the tcp client
if
(
args
.
ProxyRequest
.
KeepAlive
==
false
)
if
(
args
.
ProxyRequest
.
KeepAlive
==
false
)
{
{
if
(
responseWriter
!=
null
)
if
(
responseWriter
!=
null
)
...
@@ -245,6 +238,7 @@ namespace Titanium.Web.Proxy
...
@@ -245,6 +238,7 @@ namespace Titanium.Web.Proxy
}
}
}
}
//Send chunked response
public
static
void
SendChunked
(
Stream
InStream
,
Stream
OutStream
)
public
static
void
SendChunked
(
Stream
InStream
,
Stream
OutStream
)
{
{
...
@@ -274,8 +268,6 @@ namespace Titanium.Web.Proxy
...
@@ -274,8 +268,6 @@ namespace Titanium.Web.Proxy
var
ChunkTrail
=
Encoding
.
ASCII
.
GetBytes
(
Environment
.
NewLine
);
var
ChunkTrail
=
Encoding
.
ASCII
.
GetBytes
(
Environment
.
NewLine
);
var
ChunkHead
=
Encoding
.
ASCII
.
GetBytes
(
Data
.
Length
.
ToString
(
"x2"
));
var
ChunkHead
=
Encoding
.
ASCII
.
GetBytes
(
Data
.
Length
.
ToString
(
"x2"
));
OutStream
.
Write
(
ChunkHead
,
0
,
ChunkHead
.
Length
);
OutStream
.
Write
(
ChunkHead
,
0
,
ChunkHead
.
Length
);
OutStream
.
Write
(
ChunkTrail
,
0
,
ChunkTrail
.
Length
);
OutStream
.
Write
(
ChunkTrail
,
0
,
ChunkTrail
.
Length
);
...
...
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