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
a013e311
Commit
a013e311
authored
May 06, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#428 Fix incorrect compression relay
parent
b06dd785
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
45 deletions
+44
-45
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+21
-40
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+23
-5
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
a013e311
...
...
@@ -18,21 +18,8 @@ namespace Titanium.Web.Proxy.Examples.Basic
private
readonly
ProxyServer
proxyServer
;
// keep track of request headers
private
readonly
IDictionary
<
Guid
,
HeaderCollection
>
requestHeaderHistory
=
new
ConcurrentDictionary
<
Guid
,
HeaderCollection
>();
// keep track of response headers
private
readonly
IDictionary
<
Guid
,
HeaderCollection
>
responseHeaderHistory
=
new
ConcurrentDictionary
<
Guid
,
HeaderCollection
>();
private
ExplicitProxyEndPoint
explicitEndPoint
;
// share requestBody outside handlers
// Using a dictionary is not a good idea since it can cause memory overflow
// ideally the data should be moved out of memory
// private readonly IDictionary<Guid, string> requestBodyHistory = new ConcurrentDictionary<Guid, string>();
public
ProxyTestController
()
{
proxyServer
=
new
ProxyServer
();
...
...
@@ -164,12 +151,14 @@ namespace Titanium.Web.Proxy.Examples.Basic
WriteToConsole
(
"Active Client Connections:"
+
((
ProxyServer
)
sender
).
ClientConnectionCount
);
WriteToConsole
(
e
.
WebSession
.
Request
.
Url
);
//
create custom id for the request and
store it in the UserData property
// store it in the UserData property
// It can be a simple integer, Guid, or any type
e
.
UserData
=
Guid
.
NewGuid
();
// read request headers
requestHeaderHistory
[(
Guid
)
e
.
UserData
]
=
e
.
WebSession
.
Request
.
Headers
;
//e.UserData = new CustomUserData()
//{
// RequestHeaders = e.WebSession.Request.Headers,
// RequestBody = e.WebSession.Request.HasBody ? e.WebSession.Request.Body:null,
// RequestBodyString = e.WebSession.Request.HasBody? e.WebSession.Request.BodyString:null
//};
////This sample shows how to get the multipart form data headers
//if (e.WebSession.Request.Host == "mail.yahoo.com" && e.WebSession.Request.IsMultipartFormData)
...
...
@@ -177,19 +166,6 @@ namespace Titanium.Web.Proxy.Examples.Basic
// e.MultipartRequestPartSent += MultipartRequestPartSent;
//}
//if (e.WebSession.Request.HasBody)
//{
// // Get/Set request body bytes
// var bodyBytes = await e.GetRequestBody();
// await e.SetRequestBody(bodyBytes);
// // Get/Set request body as string
// string bodyString = await e.GetRequestBodyAsString();
// await e.SetRequestBodyString(bodyString);
// //requestBodyHistory[e.Id] = bodyString;
//}
// To cancel a request with a custom HTML content
// Filter URL
//if (e.WebSession.Request.RequestUri.AbsoluteUri.Contains("yahoo.com"))
...
...
@@ -227,6 +203,9 @@ namespace Titanium.Web.Proxy.Examples.Basic
string
ext
=
System
.
IO
.
Path
.
GetExtension
(
e
.
WebSession
.
Request
.
RequestUri
.
AbsolutePath
);
//access user data set in request to do something with it
//var userData = e.WebSession.UserData as CustomUserData;
//if (ext == ".gif" || ext == ".png" || ext == ".jpg")
//{
// byte[] btBody = Encoding.UTF8.GetBytes("<!DOCTYPE html>" +
...
...
@@ -243,15 +222,6 @@ namespace Titanium.Web.Proxy.Examples.Basic
// e.Respond(response);
// e.TerminateServerConnection();
//}
//if (requestBodyHistory.ContainsKey(e.Id))
//{
// // access request body by looking up the shared dictionary using requestId
// var requestBody = requestBodyHistory[e.Id];
//}
////read response headers
//responseHeaderHistory[e.Id] = e.WebSession.Response.Headers;
//// print out process id of current session
////WriteToConsole($"PID: {e.WebSession.ProcessId.Value}");
...
...
@@ -308,5 +278,16 @@ namespace Titanium.Web.Proxy.Examples.Basic
Console
.
WriteLine
(
message
);
}
}
///// <summary>
///// User data object as defined by user.
///// User data can be set to each SessionEventArgs.WebSession.UserData property
///// </summary>
//public class CustomUserData
//{
// public HeaderCollection RequestHeaders { get; set; }
// public byte[] RequestBody { get; set; }
// public string RequestBodyString { get; set; }
//}
}
}
Titanium.Web.Proxy/RequestHandler.cs
View file @
a013e311
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Net
;
using
System.
Net.Security
;
using
System.
Text
;
using
System.Text.RegularExpressions
;
using
System.Threading
;
using
System.Threading.Tasks
;
...
...
@@ -24,9 +25,15 @@ namespace Titanium.Web.Proxy
private
static
readonly
Regex
uriSchemeRegex
=
new
Regex
(
"^[a-z]*://"
,
RegexOptions
.
IgnoreCase
|
RegexOptions
.
Compiled
);
private
static
readonly
HashSet
<
string
>
proxySupportedCompressions
=
new
HashSet
<
string
>(
StringComparer
.
OrdinalIgnoreCase
)
{
"gzip"
,
"deflate"
};
private
bool
isWindowsAuthenticationEnabledAndSupported
=>
EnableWinAuth
&&
RunTime
.
IsWindows
&&
!
RunTime
.
IsRunningOnMono
;
/// <summary>
/// This is the core request handler method for a particular connection from client.
/// Will create new session (request/response) sequence until
...
...
@@ -404,12 +411,23 @@ namespace Titanium.Web.Proxy
/// <summary>
/// Prepare the request headers so that we can avoid encodings not parsable by this proxy
/// </summary>
/// <param name="requestHeaders"></param>
private
void
PrepareRequestHeaders
(
HeaderCollection
requestHeaders
)
{
if
(
requestHeaders
.
HeaderExists
(
KnownHeaders
.
AcceptEncoding
))
var
acceptEncoding
=
requestHeaders
.
GetHeaderValueOrNull
(
KnownHeaders
.
AcceptEncoding
);
if
(
acceptEncoding
!=
null
)
{
requestHeaders
.
SetOrAddHeaderValue
(
KnownHeaders
.
AcceptEncoding
,
"gzip,deflate"
);
var
supporedAcceptEncoding
=
new
List
<
string
>();
//only allow proxy supported compressions
supporedAcceptEncoding
.
AddRange
(
acceptEncoding
.
Split
(
','
)
.
Select
(
x
=>
x
.
Trim
())
.
Where
(
x
=>
proxySupportedCompressions
.
Contains
(
x
)));
//uncompressed is always supported by proxy
supporedAcceptEncoding
.
Add
(
"identity"
);
requestHeaders
.
SetOrAddHeaderValue
(
KnownHeaders
.
AcceptEncoding
,
string
.
Join
(
","
,
supporedAcceptEncoding
));
}
requestHeaders
.
FixProxyHeaders
();
...
...
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