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
929f8627
Commit
929f8627
authored
Jan 05, 2016
by
titanium007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup
parent
44b4d4b7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
153 deletions
+48
-153
ProxyTestController.cs
Titanium.Web.Proxy.Test/ProxyTestController.cs
+19
-18
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+1
-8
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+5
-1
TcpConnectionManager.cs
Titanium.Web.Proxy/Http/TcpConnectionManager.cs
+1
-39
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+15
-83
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+7
-4
No files found.
Titanium.Web.Proxy.Test/ProxyTestController.cs
View file @
929f8627
using
System
;
using
System
;
using
System.Text.RegularExpressions
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.EventArguments
;
namespace
Titanium.Web.Proxy.Test
namespace
Titanium.Web.Proxy.Test
...
@@ -46,27 +47,27 @@ namespace Titanium.Web.Proxy.Test
...
@@ -46,27 +47,27 @@ namespace Titanium.Web.Proxy.Test
Console
.
WriteLine
(
e
.
ProxySession
.
Request
.
RequestUrl
);
Console
.
WriteLine
(
e
.
ProxySession
.
Request
.
RequestUrl
);
////read request headers
////read request headers
//var requestHeaders = e
.RequestHeaders;
var
requestHeaders
=
e
.
ProxySession
.
Request
.
RequestHeaders
;
//
if ((e.RequestMethod.ToUpper() == "POST" || e.RequestMethod.ToUpper() == "PUT"))
if
((
e
.
RequestMethod
.
ToUpper
()
==
"POST"
||
e
.
RequestMethod
.
ToUpper
()
==
"PUT"
))
//
{
{
//
//Get/Set request body bytes
//Get/Set request body bytes
//
byte[] bodyBytes = e.GetRequestBody();
byte
[]
bodyBytes
=
e
.
GetRequestBody
();
//
e.SetRequestBody(bodyBytes);
e
.
SetRequestBody
(
bodyBytes
);
//
//Get/Set request body as string
//Get/Set request body as string
//
string bodyString = e.GetRequestBodyAsString();
string
bodyString
=
e
.
GetRequestBodyAsString
();
//
e.SetRequestBodyString(bodyString);
e
.
SetRequestBodyString
(
bodyString
);
//
}
}
//
//
To cancel a request with a custom HTML content
//To cancel a request with a custom HTML content
//
//
Filter URL
//Filter URL
//if (e.RequestURL
.Contains("google.com"))
if
(
e
.
ProxySession
.
Request
.
RequestUrl
.
Contains
(
"google.com"
))
//
{
{
//
e.Ok("<!DOCTYPE html><html><body><h1>Website Blocked</h1><p>Blocked by titanium web proxy.</p></body></html>");
e
.
Ok
(
"<!DOCTYPE html><html><body><h1>Website Blocked</h1><p>Blocked by titanium web proxy.</p></body></html>"
);
//
}
}
}
}
//Test script injection
//Test script injection
...
@@ -74,10 +75,10 @@ namespace Titanium.Web.Proxy.Test
...
@@ -74,10 +75,10 @@ namespace Titanium.Web.Proxy.Test
public
void
OnResponse
(
object
sender
,
SessionEventArgs
e
)
public
void
OnResponse
(
object
sender
,
SessionEventArgs
e
)
{
{
////read response headers
////read response headers
//var responseHeaders =
e.ResponseHeaders;
var
responseHeaders
=
e
.
ProxySession
.
Respons
e
.
ResponseHeaders
;
//if (e.ResponseStatusCode ==
HttpStatusCode.OK
)
//if (e.ResponseStatusCode ==
"200"
)
//{
//{
// if (e.ResponseContentType.Trim().ToLower().Contains("text/html"))
// if (e.ResponseContentType.Trim().ToLower().Contains("text/html"))
// {
// {
...
...
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
929f8627
...
@@ -79,14 +79,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -79,14 +79,7 @@ namespace Titanium.Web.Proxy.EventArguments
public
void
Dispose
()
public
void
Dispose
()
{
{
//if (ProxyRequest != null)
// ProxyRequest.Abort();
//if (ResponseStream != null)
// ResponseStream.Dispose();
//if (ServerResponse != null)
// ServerResponse.Close();
}
}
private
void
ReadRequestBody
()
private
void
ReadRequestBody
()
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
929f8627
...
@@ -35,6 +35,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -35,6 +35,7 @@ namespace Titanium.Web.Proxy.Http
internal
byte
[]
RequestBody
{
get
;
set
;
}
internal
byte
[]
RequestBody
{
get
;
set
;
}
internal
string
RequestBodyString
{
get
;
set
;
}
internal
string
RequestBodyString
{
get
;
set
;
}
internal
bool
RequestBodyRead
{
get
;
set
;
}
internal
bool
RequestBodyRead
{
get
;
set
;
}
public
bool
UpgradeToWebSocket
{
get
;
set
;
}
public
List
<
HttpHeader
>
RequestHeaders
{
get
;
internal
set
;
}
public
List
<
HttpHeader
>
RequestHeaders
{
get
;
internal
set
;
}
internal
bool
RequestLocked
{
get
;
set
;
}
internal
bool
RequestLocked
{
get
;
set
;
}
...
@@ -42,6 +43,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -42,6 +43,7 @@ namespace Titanium.Web.Proxy.Http
{
{
this
.
RequestHeaders
=
new
List
<
HttpHeader
>();
this
.
RequestHeaders
=
new
List
<
HttpHeader
>();
}
}
}
}
public
class
Response
public
class
Response
...
@@ -62,15 +64,17 @@ namespace Titanium.Web.Proxy.Http
...
@@ -62,15 +64,17 @@ namespace Titanium.Web.Proxy.Http
public
bool
ResponseKeepAlive
{
get
;
set
;
}
public
bool
ResponseKeepAlive
{
get
;
set
;
}
public
string
ResponseContentType
{
get
;
set
;
}
public
string
ResponseContentType
{
get
;
set
;
}
public
int
ContentLength
{
get
;
set
;
}
public
int
ContentLength
{
get
;
set
;
}
public
bool
IsChunked
{
get
;
set
;
}
public
Response
()
public
Response
()
{
{
this
.
ResponseHeaders
=
new
List
<
HttpHeader
>();
this
.
ResponseHeaders
=
new
List
<
HttpHeader
>();
this
.
ResponseKeepAlive
=
true
;
}
}
public
bool
IsChunked
{
get
;
set
;
}
}
}
public
class
HttpWebSession
public
class
HttpWebSession
...
...
Titanium.Web.Proxy/Http/TcpConnectionManager.cs
View file @
929f8627
...
@@ -20,28 +20,10 @@ namespace Titanium.Web.Proxy.Http
...
@@ -20,28 +20,10 @@ namespace Titanium.Web.Proxy.Http
internal
class
TcpConnectionManager
internal
class
TcpConnectionManager
{
{
static
Dictionary
<
string
,
Stack
<
TcpConnection
>>
ConnectionCache
=
new
Dictionary
<
string
,
Stack
<
TcpConnection
>>();
public
static
TcpConnection
GetClient
(
string
Hostname
,
int
port
,
bool
IsSecure
)
public
static
TcpConnection
GetClient
(
string
Hostname
,
int
port
,
bool
IsSecure
)
{
{
//var key = string.Concat(Hostname, ":", port, ":", IsSecure);
return
CreateClient
(
Hostname
,
port
,
IsSecure
);
//TcpConnection client;
//lock (ConnectionCache)
//{
// Stack<TcpConnection> connections;
// if (!ConnectionCache.TryGetValue(key, out connections))
// {
// return CreateClient(Hostname, port, IsSecure);
// }
// if (connections.Count > 0)
// {
// client = connections.Pop();
// }
// else
return
CreateClient
(
Hostname
,
port
,
IsSecure
);
//}
//return client;
}
}
private
static
TcpConnection
CreateClient
(
string
Hostname
,
int
port
,
bool
IsSecure
)
private
static
TcpConnection
CreateClient
(
string
Hostname
,
int
port
,
bool
IsSecure
)
...
@@ -69,25 +51,5 @@ namespace Titanium.Web.Proxy.Http
...
@@ -69,25 +51,5 @@ namespace Titanium.Web.Proxy.Http
return
new
TcpConnection
()
{
Client
=
client
,
ServerStreamReader
=
new
CustomBinaryReader
(
stream
,
Encoding
.
ASCII
),
Stream
=
stream
};
return
new
TcpConnection
()
{
Client
=
client
,
ServerStreamReader
=
new
CustomBinaryReader
(
stream
,
Encoding
.
ASCII
),
Stream
=
stream
};
}
}
public
static
void
AddClient
(
string
Hostname
,
int
port
,
bool
IsSecure
,
TcpConnection
Client
)
{
var
key
=
string
.
Concat
(
Hostname
,
":"
,
port
,
":"
,
IsSecure
);
lock
(
ConnectionCache
)
{
Stack
<
TcpConnection
>
connections
;
if
(!
ConnectionCache
.
TryGetValue
(
key
,
out
connections
))
{
connections
=
new
Stack
<
TcpConnection
>();
connections
.
Push
(
Client
);
ConnectionCache
.
Add
(
key
,
connections
);
}
connections
.
Push
(
Client
);
}
}
}
}
}
}
Titanium.Web.Proxy/RequestHandler.cs
View file @
929f8627
This diff is collapsed.
Click to expand it.
Titanium.Web.Proxy/ResponseHandler.cs
View file @
929f8627
...
@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy
...
@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy
if
(
args
.
ProxySession
.
Response
.
ResponseBodyRead
)
if
(
args
.
ProxySession
.
Response
.
ResponseBodyRead
)
{
{
var
isChunked
=
args
.
ProxySession
.
Response
.
ResponseHeaders
.
Any
(
x
=>
x
.
Name
.
ToLower
()
==
"transfer-encoding"
&&
x
.
Value
.
ToLower
().
Contains
(
"chunked"
))
;
var
isChunked
=
args
.
ProxySession
.
Response
.
IsChunked
;
var
contentEncoding
=
args
.
ProxySession
.
Response
.
ResponseContentEncoding
;
var
contentEncoding
=
args
.
ProxySession
.
Response
.
ResponseContentEncoding
;
switch
(
contentEncoding
.
ToLower
())
switch
(
contentEncoding
.
ToLower
())
...
@@ -105,14 +105,17 @@ namespace Titanium.Web.Proxy
...
@@ -105,14 +105,17 @@ namespace Titanium.Web.Proxy
response
.
Response
.
ResponseCharacterSet
=
response
.
Response
.
ResponseHeaders
[
i
].
Value
.
Split
(
';'
)[
1
].
ToLower
().
Replace
(
"charset="
,
string
.
Empty
).
Trim
();
response
.
Response
.
ResponseCharacterSet
=
response
.
Response
.
ResponseHeaders
[
i
].
Value
.
Split
(
';'
)[
1
].
ToLower
().
Replace
(
"charset="
,
string
.
Empty
).
Trim
();
}
}
else
else
response
.
Response
.
ResponseContentType
=
response
.
Response
.
ResponseHeaders
[
i
].
Value
.
Trim
();
response
.
Response
.
ResponseContentType
=
response
.
Response
.
ResponseHeaders
[
i
].
Value
.
T
oLower
().
T
rim
();
break
;
break
;
case
"transfer-encoding"
:
case
"transfer-encoding"
:
if
(
response
.
Response
.
ResponseHeaders
[
i
].
Value
.
Contains
(
"chunked"
))
if
(
response
.
Response
.
ResponseHeaders
[
i
].
Value
.
ToLower
().
Contains
(
"chunked"
))
response
.
Response
.
IsChunked
=
true
;
response
.
Response
.
IsChunked
=
true
;
break
;
break
;
case
"connection"
:
if
(
response
.
Response
.
ResponseHeaders
[
i
].
Value
.
ToLower
().
Contains
(
"close"
))
response
.
Response
.
ResponseKeepAlive
=
false
;
break
;
default
:
default
:
break
;
break
;
}
}
...
...
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