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
dee6d59f
Commit
dee6d59f
authored
Mar 02, 2016
by
titanium007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add comments
parent
4b830b57
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
108 additions
and
5 deletions
+108
-5
ProxyClient.cs
Titanium.Web.Proxy/EventArguments/ProxyClient.cs
+37
-0
BodyNotFoundException.cs
Titanium.Web.Proxy/Exceptions/BodyNotFoundException.cs
+3
-0
HttpWebRequestExtensions.cs
Titanium.Web.Proxy/Extensions/HttpWebRequestExtensions.cs
+8
-0
Compression.cs
Titanium.Web.Proxy/Helpers/Compression.cs
+36
-5
CustomBinaryReader.cs
Titanium.Web.Proxy/Helpers/CustomBinaryReader.cs
+13
-0
Firefox.cs
Titanium.Web.Proxy/Helpers/Firefox.cs
+3
-0
HttpHeader.cs
Titanium.Web.Proxy/Models/HttpHeader.cs
+7
-0
Titanium.Web.Proxy.csproj
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+1
-0
No files found.
Titanium.Web.Proxy/EventArguments/ProxyClient.cs
0 → 100644
View file @
dee6d59f
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Net.Sockets
;
using
System.Text
;
using
Titanium.Web.Proxy.Helpers
;
namespace
Titanium.Web.Proxy.EventArguments
{
/// <summary>
/// This class wraps Tcp connection to Server
/// </summary>
public
class
ProxyClient
{
/// <summary>
/// TcpClient used to communicate with server
/// </summary>
internal
TcpClient
TcpClient
{
get
;
set
;
}
/// <summary>
/// holds the stream to server
/// </summary>
internal
Stream
ClientStream
{
get
;
set
;
}
/// <summary>
/// Used to read line by line from server
/// </summary>
internal
CustomBinaryReader
ClientStreamReader
{
get
;
set
;
}
/// <summary>
/// used to write line by line to server
/// </summary>
internal
StreamWriter
ClientStreamWriter
{
get
;
set
;
}
}
}
Titanium.Web.Proxy/Exceptions/BodyNotFoundException.cs
View file @
dee6d59f
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
namespace
Titanium.Web.Proxy.Exceptions
namespace
Titanium.Web.Proxy.Exceptions
{
{
/// <summary>
/// An expception thrown when body is unexpectedly empty
/// </summary>
public
class
BodyNotFoundException
:
Exception
public
class
BodyNotFoundException
:
Exception
{
{
public
BodyNotFoundException
(
string
message
)
public
BodyNotFoundException
(
string
message
)
...
...
Titanium.Web.Proxy/Extensions/HttpWebRequestExtensions.cs
View file @
dee6d59f
...
@@ -4,14 +4,20 @@ using Titanium.Web.Proxy.Network;
...
@@ -4,14 +4,20 @@ using Titanium.Web.Proxy.Network;
namespace
Titanium.Web.Proxy.Extensions
namespace
Titanium.Web.Proxy.Extensions
{
{
/// <summary>
/// Extensions on HttpWebSession object
/// </summary>
public
static
class
HttpWebRequestExtensions
public
static
class
HttpWebRequestExtensions
{
{
//Get encoding of the HTTP request
public
static
Encoding
GetEncoding
(
this
HttpWebSession
request
)
public
static
Encoding
GetEncoding
(
this
HttpWebSession
request
)
{
{
try
try
{
{
//return default if not specified
if
(
request
.
Request
.
ContentType
==
null
)
return
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
if
(
request
.
Request
.
ContentType
==
null
)
return
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
//extract the encoding by finding the charset
var
contentTypes
=
request
.
Request
.
ContentType
.
Split
(
';'
);
var
contentTypes
=
request
.
Request
.
ContentType
.
Split
(
';'
);
foreach
(
var
contentType
in
contentTypes
)
foreach
(
var
contentType
in
contentTypes
)
{
{
...
@@ -24,9 +30,11 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -24,9 +30,11 @@ namespace Titanium.Web.Proxy.Extensions
}
}
catch
catch
{
{
//parsing errors
// ignored
// ignored
}
}
//return default if not specified
return
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
return
Encoding
.
GetEncoding
(
"ISO-8859-1"
);
}
}
}
}
...
...
Titanium.Web.Proxy/Helpers/Compression.cs
View file @
dee6d59f
...
@@ -4,10 +4,16 @@ using Ionic.Zlib;
...
@@ -4,10 +4,16 @@ using Ionic.Zlib;
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
{
{
/// <summary>
/// A helper to handle compression/decompression (gzip, zlib & deflate)
/// </summary>
public
class
CompressionHelper
public
class
CompressionHelper
{
{
private
const
int
BufferSize
=
8192
;
/// <summary>
/// compress the given bytes using zlib compression
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
[
SuppressMessage
(
"Microsoft.Usage"
,
"CA2202:Do not dispose objects multiple times"
)]
[
SuppressMessage
(
"Microsoft.Usage"
,
"CA2202:Do not dispose objects multiple times"
)]
public
static
byte
[]
CompressZlib
(
byte
[]
bytes
)
public
static
byte
[]
CompressZlib
(
byte
[]
bytes
)
{
{
...
@@ -22,6 +28,11 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -22,6 +28,11 @@ namespace Titanium.Web.Proxy.Helpers
}
}
}
}
/// <summary>
/// compress the given bytes using deflate compression
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
[
SuppressMessage
(
"Microsoft.Usage"
,
"CA2202:Do not dispose objects multiple times"
)]
[
SuppressMessage
(
"Microsoft.Usage"
,
"CA2202:Do not dispose objects multiple times"
)]
public
static
byte
[]
CompressDeflate
(
byte
[]
bytes
)
public
static
byte
[]
CompressDeflate
(
byte
[]
bytes
)
{
{
...
@@ -36,6 +47,11 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -36,6 +47,11 @@ namespace Titanium.Web.Proxy.Helpers
}
}
}
}
/// <summary>
/// compress the given bytes using gzip compression
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
[
SuppressMessage
(
"Microsoft.Usage"
,
"CA2202:Do not dispose objects multiple times"
)]
[
SuppressMessage
(
"Microsoft.Usage"
,
"CA2202:Do not dispose objects multiple times"
)]
public
static
byte
[]
CompressGzip
(
byte
[]
bytes
)
public
static
byte
[]
CompressGzip
(
byte
[]
bytes
)
{
{
...
@@ -50,12 +66,17 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -50,12 +66,17 @@ namespace Titanium.Web.Proxy.Helpers
}
}
}
}
/// <summary>
/// decompression the gzip compressed byte array
/// </summary>
/// <param name="gzip"></param>
/// <returns></returns>
//identify why passing stream instead of bytes returns empty result
//identify why passing stream instead of bytes returns empty result
public
static
byte
[]
DecompressGzip
(
byte
[]
gzip
)
public
static
byte
[]
DecompressGzip
(
byte
[]
gzip
)
{
{
using
(
var
decompressor
=
new
System
.
IO
.
Compression
.
GZipStream
(
new
MemoryStream
(
gzip
),
System
.
IO
.
Compression
.
CompressionMode
.
Decompress
))
using
(
var
decompressor
=
new
System
.
IO
.
Compression
.
GZipStream
(
new
MemoryStream
(
gzip
),
System
.
IO
.
Compression
.
CompressionMode
.
Decompress
))
{
{
var
buffer
=
new
byte
[
BufferSize
];
var
buffer
=
new
byte
[
ProxyServer
.
BUFFER_SIZE
];
using
(
var
output
=
new
MemoryStream
())
using
(
var
output
=
new
MemoryStream
())
{
{
...
@@ -69,11 +90,16 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -69,11 +90,16 @@ namespace Titanium.Web.Proxy.Helpers
}
}
}
}
/// <summary>
/// decompress the deflate byte stream
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public
static
byte
[]
DecompressDeflate
(
Stream
input
)
public
static
byte
[]
DecompressDeflate
(
Stream
input
)
{
{
using
(
var
decompressor
=
new
DeflateStream
(
input
,
CompressionMode
.
Decompress
))
using
(
var
decompressor
=
new
DeflateStream
(
input
,
CompressionMode
.
Decompress
))
{
{
var
buffer
=
new
byte
[
BufferSize
];
var
buffer
=
new
byte
[
ProxyServer
.
BUFFER_SIZE
];
using
(
var
output
=
new
MemoryStream
())
using
(
var
output
=
new
MemoryStream
())
{
{
...
@@ -87,11 +113,16 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -87,11 +113,16 @@ namespace Titanium.Web.Proxy.Helpers
}
}
}
}
/// <summary>
/// decompress the zlib byte stream
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public
static
byte
[]
DecompressZlib
(
Stream
input
)
public
static
byte
[]
DecompressZlib
(
Stream
input
)
{
{
using
(
var
decompressor
=
new
ZlibStream
(
input
,
CompressionMode
.
Decompress
))
using
(
var
decompressor
=
new
ZlibStream
(
input
,
CompressionMode
.
Decompress
))
{
{
var
buffer
=
new
byte
[
BufferSize
];
var
buffer
=
new
byte
[
ProxyServer
.
BUFFER_SIZE
];
using
(
var
output
=
new
MemoryStream
())
using
(
var
output
=
new
MemoryStream
())
{
{
...
...
Titanium.Web.Proxy/Helpers/CustomBinaryReader.cs
View file @
dee6d59f
...
@@ -5,6 +5,11 @@ using System.Text;
...
@@ -5,6 +5,11 @@ using System.Text;
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
{
{
/// <summary>
/// A custom binary reader that would allo us to read string line by line
/// using the specified encoding
/// as well as to read bytes as required
/// </summary>
public
class
CustomBinaryReader
:
BinaryReader
public
class
CustomBinaryReader
:
BinaryReader
{
{
internal
CustomBinaryReader
(
Stream
stream
,
Encoding
encoding
)
internal
CustomBinaryReader
(
Stream
stream
,
Encoding
encoding
)
...
@@ -12,6 +17,10 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -12,6 +17,10 @@ namespace Titanium.Web.Proxy.Helpers
{
{
}
}
/// <summary>
/// Read a line from the byte stream
/// </summary>
/// <returns></returns>
internal
string
ReadLine
()
internal
string
ReadLine
()
{
{
var
readBuffer
=
new
StringBuilder
();
var
readBuffer
=
new
StringBuilder
();
...
@@ -43,6 +52,10 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -43,6 +52,10 @@ namespace Titanium.Web.Proxy.Helpers
}
}
}
}
/// <summary>
/// Read until the last new line
/// </summary>
/// <returns></returns>
internal
List
<
string
>
ReadAllLines
()
internal
List
<
string
>
ReadAllLines
()
{
{
string
tmpLine
;
string
tmpLine
;
...
...
Titanium.Web.Proxy/Helpers/Firefox.cs
View file @
dee6d59f
...
@@ -3,6 +3,9 @@ using System.IO;
...
@@ -3,6 +3,9 @@ using System.IO;
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
{
{
/// <summary>
/// A helper class to set proxy settings for firefox
/// </summary>
public
class
FireFoxHelper
public
class
FireFoxHelper
{
{
public
static
void
AddFirefox
()
public
static
void
AddFirefox
()
...
...
Titanium.Web.Proxy/Models/HttpHeader.cs
View file @
dee6d59f
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
namespace
Titanium.Web.Proxy.Models
namespace
Titanium.Web.Proxy.Models
{
{
/// <summary>
/// Http Header object used by proxy
/// </summary>
public
class
HttpHeader
public
class
HttpHeader
{
{
public
HttpHeader
(
string
name
,
string
value
)
public
HttpHeader
(
string
name
,
string
value
)
...
@@ -15,6 +18,10 @@ namespace Titanium.Web.Proxy.Models
...
@@ -15,6 +18,10 @@ namespace Titanium.Web.Proxy.Models
public
string
Name
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
string
Value
{
get
;
set
;
}
public
string
Value
{
get
;
set
;
}
/// <summary>
/// Returns header as a valid header string
/// </summary>
/// <returns></returns>
public
override
string
ToString
()
public
override
string
ToString
()
{
{
return
string
.
Format
(
"{0}: {1}"
,
Name
,
Value
);
return
string
.
Format
(
"{0}: {1}"
,
Name
,
Value
);
...
...
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
dee6d59f
...
@@ -80,6 +80,7 @@
...
@@ -80,6 +80,7 @@
<Reference
Include=
"System.Xml"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Compile
Include=
"EventArguments\ProxyClient.cs"
/>
<Compile
Include=
"Exceptions\BodyNotFoundException.cs"
/>
<Compile
Include=
"Exceptions\BodyNotFoundException.cs"
/>
<Compile
Include=
"Extensions\HttpWebResponseExtensions.cs"
/>
<Compile
Include=
"Extensions\HttpWebResponseExtensions.cs"
/>
<Compile
Include=
"Extensions\HttpWebRequestExtensions.cs"
/>
<Compile
Include=
"Extensions\HttpWebRequestExtensions.cs"
/>
...
...
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