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
87eb8c78
Commit
87eb8c78
authored
Apr 17, 2016
by
justcoding121
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #64 from justcoding121/pr/62
Pr/62
parents
cd254be9
82dac792
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
396 additions
and
116 deletions
+396
-116
App.config
Titanium.Web.Proxy.Test/App.config
+7
-8
ProxyTestController.cs
Titanium.Web.Proxy.Test/ProxyTestController.cs
+18
-7
Titanium.Web.Proxy.Test.csproj
Titanium.Web.Proxy.Test/Titanium.Web.Proxy.Test.csproj
+13
-8
CompressionFactory.cs
Titanium.Web.Proxy/Compression/CompressionFactory.cs
+20
-0
DeflateCompression.cs
Titanium.Web.Proxy/Compression/DeflateCompression.cs
+21
-0
GZipCompression.cs
Titanium.Web.Proxy/Compression/GZipCompression.cs
+21
-0
ICompression.cs
Titanium.Web.Proxy/Compression/ICompression.cs
+7
-0
ZlibCompression.cs
Titanium.Web.Proxy/Compression/ZlibCompression.cs
+21
-0
DecompressionFactory.cs
Titanium.Web.Proxy/Decompression/DecompressionFactory.cs
+20
-0
DefaultDecompression.cs
Titanium.Web.Proxy/Decompression/DefaultDecompression.cs
+10
-0
DeflateDecompression.cs
Titanium.Web.Proxy/Decompression/DeflateDecompression.cs
+29
-0
GZipDecompression.cs
Titanium.Web.Proxy/Decompression/GZipDecompression.cs
+25
-0
IDecompression.cs
Titanium.Web.Proxy/Decompression/IDecompression.cs
+9
-0
ZlibDecompression.cs
Titanium.Web.Proxy/Decompression/ZlibDecompression.cs
+28
-0
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+28
-51
TcpExtensions.cs
Titanium.Web.Proxy/Extensions/TcpExtensions.cs
+1
-1
HttpWebClient.cs
Titanium.Web.Proxy/Network/HttpWebClient.cs
+17
-6
TcpConnectionManager.cs
Titanium.Web.Proxy/Network/TcpConnectionManager.cs
+1
-0
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+20
-15
OkResponse.cs
Titanium.Web.Proxy/Responses/OkResponse.cs
+21
-0
RedirectResponse.cs
Titanium.Web.Proxy/Responses/RedirectResponse.cs
+15
-0
Titanium.Web.Proxy.csproj
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+39
-18
packages-Net45.config
Titanium.Web.Proxy/packages-Net45.config
+4
-0
packages.config
Titanium.Web.Proxy/packages.config
+1
-2
No files found.
Titanium.Web.Proxy.Test/App.config
View file @
87eb8c78
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
configuration
>
<
startup
>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.
0,Profile=Client"
/>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.
5"
/>
</
startup
>
<
runtime
>
<
assemblyBinding
xmlns
=
"urn:schemas-microsoft-com:asm.v1"
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"System.Runtime"
publicKeyToken
=
"b03f5f7f11d50a3a"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-2.6.10.0"
newVersion
=
"2.6.10.0"
/>
<
assemblyIdentity
name
=
"System.Runtime"
publicKeyToken
=
"b03f5f7f11d50a3a"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-2.6.10.0"
newVersion
=
"2.6.10.0"
/>
</
dependentAssembly
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"System.Threading.Tasks"
publicKeyToken
=
"b03f5f7f11d50a3a"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-2.6.10.0"
newVersion
=
"2.6.10.0"
/>
<
assemblyIdentity
name
=
"System.Threading.Tasks"
publicKeyToken
=
"b03f5f7f11d50a3a"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-2.6.10.0"
newVersion
=
"2.6.10.0"
/>
</
dependentAssembly
>
</
assemblyBinding
>
</
runtime
>
...
...
Titanium.Web.Proxy.Test/ProxyTestController.cs
View file @
87eb8c78
...
...
@@ -46,9 +46,6 @@ namespace Titanium.Web.Proxy.Test
Console
.
WriteLine
(
"Listening on '{0}' endpoint at Ip {1} and port: {2} "
,
endPoint
.
GetType
().
Name
,
endPoint
.
IpAddress
,
endPoint
.
Port
);
//You can also add/remove end points after proxy has been started
ProxyServer
.
RemoveEndPoint
(
transparentEndPoint
);
//Only explicit proxies can be set as system proxy!
ProxyServer
.
SetAsSystemHttpProxy
(
explicitEndPoint
);
ProxyServer
.
SetAsSystemHttpsProxy
(
explicitEndPoint
);
...
...
@@ -85,10 +82,20 @@ namespace Titanium.Web.Proxy.Test
//To cancel a request with a custom HTML content
//Filter URL
if
(
e
.
ProxySession
.
Request
.
RequestUri
.
AbsoluteUri
.
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>"
);
}
//Redirect example
if
(
e
.
ProxySession
.
Request
.
RequestUri
.
AbsoluteUri
.
Contains
(
"wikipedia.org"
))
{
e
.
Redirect
(
"https://www.paypal.com"
);
}
}
...
...
@@ -107,7 +114,11 @@ namespace Titanium.Web.Proxy.Test
{
if
(
e
.
ProxySession
.
Response
.
ContentType
.
Trim
().
ToLower
().
Contains
(
"text/html"
))
{
byte
[]
bodyBytes
=
e
.
GetResponseBody
();
e
.
SetResponseBody
(
bodyBytes
);
string
body
=
e
.
GetResponseBodyAsString
();
e
.
SetResponseBodyString
(
body
);
}
}
}
...
...
Titanium.Web.Proxy.Test/Titanium.Web.Proxy.Test.csproj
View file @
87eb8c78
...
...
@@ -11,25 +11,28 @@
<RootNamespace>
Titanium.Web.Proxy.Test
</RootNamespace>
<AssemblyName>
Titanium.Web.Proxy.Test
</AssemblyName>
<FileAlignment>
512
</FileAlignment>
<TargetFrameworkProfile
/>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<DefineConstants>
TRACE;DEBUG;NET40
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<TargetFrameworkVersion>
v4.0
</TargetFrameworkVersion>
<Prefer32Bit>
false
</Prefer32Bit>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<DefineConstants>
TRACE
;NET40
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<TargetFrameworkVersion>
v4.0
</TargetFrameworkVersion>
<Prefer32Bit>
false
</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject
/>
...
...
@@ -37,22 +40,24 @@
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'Debug-Net45|AnyCPU'"
>
<DebugSymbols>
true
</DebugSymbols>
<OutputPath>
bin\Debug-Net45\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<DefineConstants>
TRACE;DEBUG;NET45
</DefineConstants>
<DebugType>
full
</DebugType>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<ErrorReport>
prompt
</ErrorReport>
<CodeAnalysisRuleSet>
MinimumRecommendedRules.ruleset
</CodeAnalysisRuleSet>
<TargetFrameworkVersion>
v4.5
</TargetFrameworkVersion>
<Prefer32Bit>
true
</Prefer32Bit>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'Release-Net45|AnyCPU'"
>
<OutputPath>
bin\Release-Net45\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<DefineConstants>
TRACE
;NET45
</DefineConstants>
<Optimize>
true
</Optimize>
<DebugType>
pdbonly
</DebugType>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<ErrorReport>
prompt
</ErrorReport>
<CodeAnalysisRuleSet>
MinimumRecommendedRules.ruleset
</CodeAnalysisRuleSet>
<TargetFrameworkVersion>
v4.5
</TargetFrameworkVersion>
<Prefer32Bit>
true
</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"System"
/>
...
...
Titanium.Web.Proxy/Compression/CompressionFactory.cs
0 → 100644
View file @
87eb8c78
namespace
Titanium.Web.Proxy.Compression
{
class
CompressionFactory
{
public
ICompression
Create
(
string
type
)
{
switch
(
type
)
{
case
"gzip"
:
return
new
GZipCompression
();
case
"deflate"
:
return
new
DeflateCompression
();
case
"zlib"
:
return
new
ZlibCompression
();
default
:
return
null
;
}
}
}
}
Titanium.Web.Proxy/Compression/DeflateCompression.cs
0 → 100644
View file @
87eb8c78
using
System.IO
;
using
System.IO.Compression
;
namespace
Titanium.Web.Proxy.Compression
{
class
DeflateCompression
:
ICompression
{
public
byte
[]
Compress
(
byte
[]
responseBody
)
{
using
(
var
ms
=
new
MemoryStream
())
{
using
(
var
zip
=
new
DeflateStream
(
ms
,
CompressionMode
.
Compress
,
true
))
{
zip
.
Write
(
responseBody
,
0
,
responseBody
.
Length
);
}
return
ms
.
ToArray
();
}
}
}
}
Titanium.Web.Proxy/Compression/GZipCompression.cs
0 → 100644
View file @
87eb8c78
using
Ionic.Zlib
;
using
System.IO
;
namespace
Titanium.Web.Proxy.Compression
{
class
GZipCompression
:
ICompression
{
public
byte
[]
Compress
(
byte
[]
responseBody
)
{
using
(
var
ms
=
new
MemoryStream
())
{
using
(
var
zip
=
new
GZipStream
(
ms
,
CompressionMode
.
Compress
,
true
))
{
zip
.
Write
(
responseBody
,
0
,
responseBody
.
Length
);
}
return
ms
.
ToArray
();
}
}
}
}
Titanium.Web.Proxy/Compression/ICompression.cs
0 → 100644
View file @
87eb8c78
namespace
Titanium.Web.Proxy.Compression
{
interface
ICompression
{
byte
[]
Compress
(
byte
[]
responseBody
);
}
}
Titanium.Web.Proxy/Compression/ZlibCompression.cs
0 → 100644
View file @
87eb8c78
using
Ionic.Zlib
;
using
System.IO
;
namespace
Titanium.Web.Proxy.Compression
{
class
ZlibCompression
:
ICompression
{
public
byte
[]
Compress
(
byte
[]
responseBody
)
{
using
(
var
ms
=
new
MemoryStream
())
{
using
(
var
zip
=
new
ZlibStream
(
ms
,
CompressionMode
.
Compress
,
true
))
{
zip
.
Write
(
responseBody
,
0
,
responseBody
.
Length
);
}
return
ms
.
ToArray
();
}
}
}
}
Titanium.Web.Proxy/Decompression/DecompressionFactory.cs
0 → 100644
View file @
87eb8c78
namespace
Titanium.Web.Proxy.Decompression
{
class
DecompressionFactory
{
public
IDecompression
Create
(
string
type
)
{
switch
(
type
)
{
case
"gzip"
:
return
new
GZipDecompression
();
case
"deflate"
:
return
new
DeflateDecompression
();
case
"zlib"
:
return
new
ZlibDecompression
();
default
:
return
new
DefaultDecompression
();
}
}
}
}
Titanium.Web.Proxy/Decompression/DefaultDecompression.cs
0 → 100644
View file @
87eb8c78
namespace
Titanium.Web.Proxy.Decompression
{
class
DefaultDecompression
:
IDecompression
{
public
byte
[]
Decompress
(
byte
[]
compressedArray
)
{
return
compressedArray
;
}
}
}
Titanium.Web.Proxy/Decompression/DeflateDecompression.cs
0 → 100644
View file @
87eb8c78
using
Ionic.Zlib
;
using
System.IO
;
namespace
Titanium.Web.Proxy.Decompression
{
class
DeflateDecompression
:
IDecompression
{
public
byte
[]
Decompress
(
byte
[]
compressedArray
)
{
var
stream
=
new
MemoryStream
(
compressedArray
);
using
(
var
decompressor
=
new
DeflateStream
(
stream
,
CompressionMode
.
Decompress
))
{
var
buffer
=
new
byte
[
ProxyServer
.
BUFFER_SIZE
];
using
(
var
output
=
new
MemoryStream
())
{
int
read
;
while
((
read
=
decompressor
.
Read
(
buffer
,
0
,
buffer
.
Length
))
>
0
)
{
output
.
Write
(
buffer
,
0
,
read
);
}
return
output
.
ToArray
();
}
}
}
}
}
Titanium.Web.Proxy/Decompression/GZipDecompression.cs
0 → 100644
View file @
87eb8c78
using
System.IO
;
using
System.IO.Compression
;
namespace
Titanium.Web.Proxy.Decompression
{
class
GZipDecompression
:
IDecompression
{
public
byte
[]
Decompress
(
byte
[]
compressedArray
)
{
using
(
var
decompressor
=
new
GZipStream
(
new
MemoryStream
(
compressedArray
),
CompressionMode
.
Decompress
))
{
var
buffer
=
new
byte
[
ProxyServer
.
BUFFER_SIZE
];
using
(
var
output
=
new
MemoryStream
())
{
int
read
;
while
((
read
=
decompressor
.
Read
(
buffer
,
0
,
buffer
.
Length
))
>
0
)
{
output
.
Write
(
buffer
,
0
,
read
);
}
return
output
.
ToArray
();
}
}
}
}
}
Titanium.Web.Proxy/Decompression/IDecompression.cs
0 → 100644
View file @
87eb8c78
using
System.IO
;
namespace
Titanium.Web.Proxy.Decompression
{
interface
IDecompression
{
byte
[]
Decompress
(
byte
[]
compressedArray
);
}
}
Titanium.Web.Proxy/Decompression/ZlibDecompression.cs
0 → 100644
View file @
87eb8c78
using
Ionic.Zlib
;
using
System.IO
;
namespace
Titanium.Web.Proxy.Decompression
{
class
ZlibDecompression
:
IDecompression
{
public
byte
[]
Decompress
(
byte
[]
compressedArray
)
{
var
memoryStream
=
new
MemoryStream
(
compressedArray
);
using
(
var
decompressor
=
new
ZlibStream
(
memoryStream
,
CompressionMode
.
Decompress
))
{
var
buffer
=
new
byte
[
ProxyServer
.
BUFFER_SIZE
];
using
(
var
output
=
new
MemoryStream
())
{
int
read
;
while
((
read
=
decompressor
.
Read
(
buffer
,
0
,
buffer
.
Length
))
>
0
)
{
output
.
Write
(
buffer
,
0
,
read
);
}
return
output
.
ToArray
();
}
}
}
}
}
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
87eb8c78
using
System
;
using
System.Collections.Generic
;
using
System.Globalization
;
using
System.IO
;
using
System.Linq
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.Text
;
using
Titanium.Web.Proxy.Exceptions
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Network
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Responses
;
using
Titanium.Web.Proxy.Decompression
;
namespace
Titanium.Web.Proxy.EventArguments
{
/// <summary>
/// Holds info related to a single proxy session (single request/response sequence)
/// A proxy session is bounded to a single connection from client
...
...
@@ -22,13 +18,11 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
public
class
SessionEventArgs
:
EventArgs
,
IDisposable
{
/// <summary>
/// Constructor to initialize the proxy
/// </summary>
internal
SessionEventArgs
()
{
Client
=
new
ProxyClient
();
ProxySession
=
new
HttpWebSession
();
}
...
...
@@ -38,7 +32,6 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
internal
ProxyClient
Client
{
get
;
set
;
}
/// <summary>
/// Does this session uses SSL
/// </summary>
...
...
@@ -50,7 +43,6 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
public
HttpWebSession
ProxySession
{
get
;
set
;
}
/// <summary>
/// A shortcut to get the request content length
/// </summary>
...
...
@@ -165,22 +157,7 @@ namespace Titanium.Web.Proxy.EventArguments
try
{
//decompress
switch
(
requestContentEncoding
)
{
case
"gzip"
:
ProxySession
.
Request
.
RequestBody
=
CompressionHelper
.
DecompressGzip
(
requestBodyStream
.
ToArray
());
break
;
case
"deflate"
:
ProxySession
.
Request
.
RequestBody
=
CompressionHelper
.
DecompressDeflate
(
requestBodyStream
);
break
;
case
"zlib"
:
ProxySession
.
Request
.
RequestBody
=
CompressionHelper
.
DecompressZlib
(
requestBodyStream
);
break
;
default
:
ProxySession
.
Request
.
RequestBody
=
requestBodyStream
.
ToArray
();
break
;
}
ProxySession
.
Request
.
RequestBody
=
GetDecompressedResponseBody
(
requestContentEncoding
,
requestBodyStream
.
ToArray
());
}
catch
{
...
...
@@ -235,22 +212,9 @@ namespace Titanium.Web.Proxy.EventArguments
var
buffer
=
ProxySession
.
ProxyClient
.
ServerStreamReader
.
ReadBytes
(
ProxySession
.
Response
.
ContentLength
);
responseBodyStream
.
Write
(
buffer
,
0
,
buffer
.
Length
);
}
//decompress
switch
(
ProxySession
.
Response
.
ContentEncoding
)
{
case
"gzip"
:
ProxySession
.
Response
.
ResponseBody
=
CompressionHelper
.
DecompressGzip
(
responseBodyStream
.
ToArray
());
break
;
case
"deflate"
:
ProxySession
.
Response
.
ResponseBody
=
CompressionHelper
.
DecompressDeflate
(
responseBodyStream
);
break
;
case
"zlib"
:
ProxySession
.
Response
.
ResponseBody
=
CompressionHelper
.
DecompressZlib
(
responseBodyStream
);
break
;
default
:
ProxySession
.
Response
.
ResponseBody
=
responseBodyStream
.
ToArray
();
break
;
}
ProxySession
.
Response
.
ResponseBody
=
GetDecompressedResponseBody
(
ProxySession
.
Response
.
ContentEncoding
,
responseBodyStream
.
ToArray
());
}
//set this to true for caching
ProxySession
.
Response
.
ResponseBodyRead
=
true
;
...
...
@@ -379,6 +343,14 @@ namespace Titanium.Web.Proxy.EventArguments
SetResponseBody
(
bodyBytes
);
}
private
byte
[]
GetDecompressedResponseBody
(
string
encodingType
,
byte
[]
responseBodyStream
)
{
var
decompressionFactory
=
new
DecompressionFactory
();
var
decompressor
=
decompressionFactory
.
Create
(
encodingType
);
return
decompressor
.
Decompress
(
responseBodyStream
);
}
/// <summary>
/// Before request is made to server
...
...
@@ -406,20 +378,23 @@ namespace Titanium.Web.Proxy.EventArguments
/// <param name="body"></param>
public
void
Ok
(
byte
[]
result
)
{
var
response
=
new
Response
();
var
response
=
new
Ok
Response
();
response
.
HttpVersion
=
ProxySession
.
Request
.
HttpVersion
;
response
.
ResponseStatusCode
=
"200"
;
response
.
ResponseStatusDescription
=
"Ok"
;
response
.
ResponseBody
=
result
;
response
.
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Timestamp"
,
DateTime
.
Now
.
ToString
())
);
Respond
(
response
);
response
.
ResponseHeaders
.
Add
(
new
HttpHeader
(
"content-length"
,
DateTime
.
Now
.
ToString
()));
response
.
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Cache-Control"
,
"no-cache, no-store, must-revalidate"
));
response
.
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Pragma"
,
"no-cache"
));
response
.
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Expires"
,
"0"
));
ProxySession
.
Request
.
CancelRequest
=
true
;
}
response
.
ResponseBody
=
result
;
public
void
Redirect
(
string
url
)
{
var
response
=
new
RedirectResponse
();
response
.
HttpVersion
=
ProxySession
.
Request
.
HttpVersion
;
response
.
ResponseHeaders
.
Add
(
new
Models
.
HttpHeader
(
"Location"
,
url
));
response
.
ResponseBody
=
Encoding
.
ASCII
.
GetBytes
(
string
.
Empty
);
Respond
(
response
);
...
...
@@ -435,7 +410,9 @@ namespace Titanium.Web.Proxy.EventArguments
response
.
ResponseBodyRead
=
true
;
ProxySession
.
Response
=
response
;
ProxyServer
.
HandleHttpSessionResponse
(
this
);
}
}
}
\ No newline at end of file
Titanium.Web.Proxy/
Network
/TcpExtensions.cs
→
Titanium.Web.Proxy/
Extensions
/TcpExtensions.cs
View file @
87eb8c78
...
...
@@ -7,7 +7,7 @@ using System.Text;
using
System.Threading.Tasks
;
namespace
Titanium.Web.Proxy.
Network
namespace
Titanium.Web.Proxy.
Extensions
{
internal
static
class
TcpExtensions
...
...
Titanium.Web.Proxy/Network/HttpWebClient.cs
View file @
87eb8c78
...
...
@@ -100,7 +100,9 @@ namespace Titanium.Web.Proxy.Network
public
string
Url
{
get
{
return
RequestUri
.
OriginalString
;
}
}
internal
Encoding
Encoding
{
get
{
return
this
.
GetEncoding
();
}
}
/// <summary>
/// Terminates the underlying Tcp Connection to client after current request
/// </summary>
internal
bool
CancelRequest
{
get
;
set
;
}
internal
byte
[]
RequestBody
{
get
;
set
;
}
...
...
@@ -248,7 +250,7 @@ namespace Titanium.Web.Proxy.Network
internal
string
ResponseBodyString
{
get
;
set
;
}
internal
bool
ResponseBodyRead
{
get
;
set
;
}
internal
bool
ResponseLocked
{
get
;
set
;
}
public
bool
Is100Continue
{
get
;
internal
set
;
}
public
Response
()
{
...
...
@@ -272,6 +274,7 @@ namespace Titanium.Web.Proxy.Network
public
Response
Response
{
get
;
set
;
}
internal
TcpConnection
ProxyClient
{
get
;
set
;
}
public
void
SetConnection
(
TcpConnection
Connection
)
{
Connection
.
LastAccess
=
DateTime
.
Now
;
...
...
@@ -322,11 +325,19 @@ namespace Titanium.Web.Proxy.Network
var
s
=
ProxyClient
.
ServerStreamReader
.
ReadLine
();
}
this
.
Response
.
HttpVersion
=
httpResult
[
0
];
this
.
Response
.
ResponseStatusCode
=
httpResult
[
1
];
string
status
=
httpResult
[
2
]
;
this
.
Response
.
HttpVersion
=
httpResult
[
0
]
.
Trim
()
;
this
.
Response
.
ResponseStatusCode
=
httpResult
[
1
]
.
Trim
()
;
this
.
Response
.
ResponseStatusDescription
=
httpResult
[
2
].
Trim
()
;
this
.
Response
.
ResponseStatusDescription
=
status
;
if
(
this
.
Response
.
ResponseStatusCode
.
Equals
(
"100"
)
&&
this
.
Response
.
ResponseStatusDescription
.
ToLower
().
Equals
(
"continue"
))
{
this
.
Response
.
Is100Continue
=
true
;
this
.
Response
.
ResponseStatusCode
=
null
;
ProxyClient
.
ServerStreamReader
.
ReadLine
();
ReceiveResponse
();
return
;
}
List
<
string
>
responseLines
=
ProxyClient
.
ServerStreamReader
.
ReadAllLines
();
...
...
Titanium.Web.Proxy/Network/TcpConnectionManager.cs
View file @
87eb8c78
...
...
@@ -10,6 +10,7 @@ using System.Net.Security;
using
Titanium.Web.Proxy.Helpers
;
using
System.Threading
;
using
System.Security.Authentication
;
using
Titanium.Web.Proxy.Extensions
;
namespace
Titanium.Web.Proxy.Network
{
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
87eb8c78
...
...
@@ -12,6 +12,7 @@ using Titanium.Web.Proxy.Extensions;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Network
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Compression
;
namespace
Titanium.Web.Proxy
{
...
...
@@ -35,35 +36,32 @@ namespace Titanium.Web.Proxy
args
.
ProxySession
.
Response
.
ResponseLocked
=
true
;
if
(
args
.
ProxySession
.
Response
.
Is100Continue
)
{
WriteResponseStatus
(
args
.
ProxySession
.
Response
.
HttpVersion
,
"100"
,
"Continue"
,
args
.
Client
.
ClientStreamWriter
);
args
.
Client
.
ClientStreamWriter
.
WriteLine
();
}
WriteResponseStatus
(
args
.
ProxySession
.
Response
.
HttpVersion
,
args
.
ProxySession
.
Response
.
ResponseStatusCode
,
args
.
ProxySession
.
Response
.
ResponseStatusDescription
,
args
.
Client
.
ClientStreamWriter
);
if
(
args
.
ProxySession
.
Response
.
ResponseBodyRead
)
{
var
isChunked
=
args
.
ProxySession
.
Response
.
IsChunked
;
var
contentEncoding
=
args
.
ProxySession
.
Response
.
ContentEncoding
;
if
(
contentEncoding
!=
null
)
switch
(
contentEncoding
)
if
(
contentEncoding
!=
null
)
{
case
"gzip"
:
args
.
ProxySession
.
Response
.
ResponseBody
=
CompressionHelper
.
CompressGzip
(
args
.
ProxySession
.
Response
.
ResponseBody
);
break
;
case
"deflate"
:
args
.
ProxySession
.
Response
.
ResponseBody
=
CompressionHelper
.
CompressDeflate
(
args
.
ProxySession
.
Response
.
ResponseBody
);
break
;
case
"zlib"
:
args
.
ProxySession
.
Response
.
ResponseBody
=
CompressionHelper
.
CompressZlib
(
args
.
ProxySession
.
Response
.
ResponseBody
);
break
;
args
.
ProxySession
.
Response
.
ResponseBody
=
GetCompressedResponseBody
(
contentEncoding
,
args
.
ProxySession
.
Response
.
ResponseBody
);
}
WriteResponseStatus
(
args
.
ProxySession
.
Response
.
HttpVersion
,
args
.
ProxySession
.
Response
.
ResponseStatusCode
,
args
.
ProxySession
.
Response
.
ResponseStatusDescription
,
args
.
Client
.
ClientStreamWriter
);
WriteResponseHeaders
(
args
.
Client
.
ClientStreamWriter
,
args
.
ProxySession
.
Response
.
ResponseHeaders
,
args
.
ProxySession
.
Response
.
ResponseBody
.
Length
,
isChunked
);
WriteResponseBody
(
args
.
Client
.
ClientStream
,
args
.
ProxySession
.
Response
.
ResponseBody
,
isChunked
);
}
else
{
WriteResponseStatus
(
args
.
ProxySession
.
Response
.
HttpVersion
,
args
.
ProxySession
.
Response
.
ResponseStatusCode
,
args
.
ProxySession
.
Response
.
ResponseStatusDescription
,
args
.
Client
.
ClientStreamWriter
);
WriteResponseHeaders
(
args
.
Client
.
ClientStreamWriter
,
args
.
ProxySession
.
Response
.
ResponseHeaders
);
if
(
args
.
ProxySession
.
Response
.
IsChunked
||
args
.
ProxySession
.
Response
.
ContentLength
>
0
)
...
...
@@ -83,6 +81,13 @@ namespace Titanium.Web.Proxy
}
}
private
static
byte
[]
GetCompressedResponseBody
(
string
encodingType
,
byte
[]
responseBodyStream
)
{
var
compressionFactory
=
new
CompressionFactory
();
var
compressor
=
compressionFactory
.
Create
(
encodingType
);
return
compressor
.
Compress
(
responseBodyStream
);
}
private
static
void
WriteResponseStatus
(
string
version
,
string
code
,
string
description
,
StreamWriter
responseWriter
)
...
...
Titanium.Web.Proxy/Responses/OkResponse.cs
0 → 100644
View file @
87eb8c78
using
System
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network
;
namespace
Titanium.Web.Proxy.Responses
{
public
class
OkResponse
:
Response
{
public
OkResponse
()
{
ResponseStatusCode
=
"200"
;
ResponseStatusDescription
=
"Ok"
;
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Timestamp"
,
DateTime
.
Now
.
ToString
()));
ResponseHeaders
.
Add
(
new
HttpHeader
(
"content-length"
,
DateTime
.
Now
.
ToString
()));
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Cache-Control"
,
"no-cache, no-store, must-revalidate"
));
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Pragma"
,
"no-cache"
));
ResponseHeaders
.
Add
(
new
HttpHeader
(
"Expires"
,
"0"
));
}
}
}
Titanium.Web.Proxy/Responses/RedirectResponse.cs
0 → 100644
View file @
87eb8c78
using
System
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network
;
namespace
Titanium.Web.Proxy.Responses
{
public
class
RedirectResponse
:
Response
{
public
RedirectResponse
()
{
ResponseStatusCode
=
"302"
;
ResponseStatusDescription
=
"Found"
;
}
}
}
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
87eb8c78
...
...
@@ -46,11 +46,7 @@
<TargetFrameworkVersion>
v4.5
</TargetFrameworkVersion>
<DefineConstants>
NET45
</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"Ionic.Zip, Version=1.9.7.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL"
>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
..\packages\DotNetZip.1.9.7\lib\net20\Ionic.Zip.dll
</HintPath>
</Reference>
<ItemGroup
Condition=
"'$(Configuration)' == 'Debug' Or '$(Configuration)' == 'Release'"
>
<Reference
Include=
"Microsoft.Threading.Tasks"
>
<HintPath>
..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll
</HintPath>
</Reference>
...
...
@@ -60,19 +56,25 @@
<Reference
Include=
"Microsoft.Threading.Tasks.Extensions.Desktop"
>
<HintPath>
..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll
</HintPath>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.configuration"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.IO"
>
<HintPath>
..\packages\Microsoft.Bcl.1.1.10\lib\net40\System.IO.dll
</HintPath>
</Reference>
<Reference
Include=
"System.Net"
/>
<Reference
Include=
"System.Runtime"
>
<HintPath>
..\packages\Microsoft.Bcl.1.1.10\lib\net40\System.Runtime.dll
</HintPath>
</Reference>
<Reference
Include=
"System.Threading.Tasks"
>
<HintPath>
..\packages\Microsoft.Bcl.1.1.10\lib\net40\System.Threading.Tasks.dll
</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference
Include=
"Ionic.Zip, Version=1.9.8.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL"
>
<HintPath>
..\packages\DotNetZip.1.9.8\lib\net20\Ionic.Zip.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Net"
/>
<Reference
Include=
"System.configuration"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Xml.Linq"
/>
<Reference
Include=
"System.Data.DataSetExtensions"
/>
<Reference
Include=
"Microsoft.CSharp"
/>
...
...
@@ -80,6 +82,17 @@
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"Compression\CompressionFactory.cs"
/>
<Compile
Include=
"Compression\DeflateCompression.cs"
/>
<Compile
Include=
"Compression\GZipCompression.cs"
/>
<Compile
Include=
"Compression\ICompression.cs"
/>
<Compile
Include=
"Compression\ZlibCompression.cs"
/>
<Compile
Include=
"Decompression\DecompressionFactory.cs"
/>
<Compile
Include=
"Decompression\DefaultDecompression.cs"
/>
<Compile
Include=
"Decompression\DeflateDecompression.cs"
/>
<Compile
Include=
"Decompression\GZipDecompression.cs"
/>
<Compile
Include=
"Decompression\IDecompression.cs"
/>
<Compile
Include=
"Decompression\ZlibDecompression.cs"
/>
<Compile
Include=
"EventArguments\ProxyClient.cs"
/>
<Compile
Include=
"Exceptions\BodyNotFoundException.cs"
/>
<Compile
Include=
"Extensions\HttpWebResponseExtensions.cs"
/>
...
...
@@ -88,7 +101,7 @@
<Compile
Include=
"Helpers\Firefox.cs"
/>
<Compile
Include=
"Helpers\SystemProxy.cs"
/>
<Compile
Include=
"Models\EndPoint.cs"
/>
<Compile
Include=
"
Network
\TcpExtensions.cs"
/>
<Compile
Include=
"
Extensions
\TcpExtensions.cs"
/>
<Compile
Include=
"Network\TcpConnectionManager.cs"
/>
<Compile
Include=
"Models\HttpHeader.cs"
/>
<Compile
Include=
"Network\HttpWebClient.cs"
/>
...
...
@@ -96,16 +109,24 @@
<Compile
Include=
"RequestHandler.cs"
/>
<Compile
Include=
"ResponseHandler.cs"
/>
<Compile
Include=
"Helpers\CustomBinaryReader.cs"
/>
<Compile
Include=
"Helpers\Compression.cs"
/>
<Compile
Include=
"ProxyServer.cs"
/>
<Compile
Include=
"EventArguments\SessionEventArgs.cs"
/>
<Compile
Include=
"Helpers\Tcp.cs"
/>
<Compile
Include=
"Extensions\StreamExtensions.cs"
/>
<Compile
Include=
"Responses\OkResponse.cs"
/>
<Compile
Include=
"Responses\RedirectResponse.cs"
/>
</ItemGroup>
<ItemGroup
/>
<ItemGroup>
<None
Include=
"app.config"
/>
<None
Include=
"packages.config"
/>
</ItemGroup>
<ItemGroup
Condition=
"'$(Configuration)' == 'Debug' Or '$(Configuration)' == 'Release'"
>
<None
Include=
"packages.config"
>
<SubType>
Designer
</SubType>
</None>
</ItemGroup>
<ItemGroup
Condition=
"'$(Configuration)' == 'Debug-Net45' Or '$(Configuration)' == 'Release-Net45'"
>
<None
Include=
"packages-Net45.config"
/>
</ItemGroup>
<ItemGroup>
<None
Include=
"makecert.exe"
>
...
...
Titanium.Web.Proxy/packages-Net45.config
0 → 100644
View file @
87eb8c78
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
package
id
=
"DotNetZip"
version
=
"1.9.8"
targetFramework
=
"net45"
/>
</
packages
>
\ No newline at end of file
Titanium.Web.Proxy/packages.config
View file @
87eb8c78
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
package
id
=
"DotNetZip"
version
=
"1.9.7"
targetFramework
=
"net40"
/>
<
package
id
=
"DotNetZip"
version
=
"1.9.7"
targetFramework
=
"net45"
/>
<
package
id
=
"DotNetZip"
version
=
"1.9.8"
targetFramework
=
"net40"
/>
<
package
id
=
"Microsoft.Bcl"
version
=
"1.1.10"
targetFramework
=
"net40"
/>
<
package
id
=
"Microsoft.Bcl.Async"
version
=
"1.0.168"
targetFramework
=
"net40"
/>
<
package
id
=
"Microsoft.Bcl.Build"
version
=
"1.0.14"
targetFramework
=
"net40"
/>
...
...
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