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
2b176472
Commit
2b176472
authored
Mar 06, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move help method to Helper class; remove for loop
parent
94715243
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
50 deletions
+47
-50
HttpHelper.cs
Titanium.Web.Proxy/Helpers/HttpHelper.cs
+43
-1
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+4
-49
No files found.
Titanium.Web.Proxy/Helpers/HttpHelper.cs
View file @
2b176472
using
System
;
using
StreamExtended.Network
;
using
System
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Shared
;
...
...
@@ -113,5 +115,45 @@ namespace Titanium.Web.Proxy.Helpers
//return as it is
return
hostname
;
}
/// <summary>
/// Determines whether is connect method.
/// </summary>
/// <param name="clientStream">The client stream.</param>
/// <returns>1: when CONNECT, 0: when valid HTTP method, -1: otherwise</returns>
internal
static
async
Task
<
int
>
IsConnectMethod
(
CustomBufferedStream
clientStream
)
{
bool
isConnect
=
true
;
int
legthToCheck
=
10
;
for
(
int
i
=
0
;
i
<
legthToCheck
;
i
++)
{
int
b
=
await
clientStream
.
PeekByteAsync
(
i
);
if
(
b
==
-
1
)
{
return
-
1
;
}
if
(
b
==
' '
&&
i
>
2
)
{
// at least 3 letters and a space
return
isConnect
?
1
:
0
;
}
char
ch
=
(
char
)
b
;
if
(!
char
.
IsLetter
(
ch
))
{
// non letter or too short
return
-
1
;
}
if
(
i
>
6
||
ch
!=
"CONNECT"
[
i
])
{
isConnect
=
false
;
}
}
// only letters
return
isConnect
?
1
:
0
;
}
}
}
Titanium.Web.Proxy/RequestHandler.cs
View file @
2b176472
...
...
@@ -50,7 +50,7 @@ namespace Titanium.Web.Proxy
ConnectRequest
connectRequest
=
null
;
//Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
if
(
await
IsConnectMethod
(
clientStream
)
==
1
)
if
(
await
HttpHelper
.
IsConnectMethod
(
clientStream
)
==
1
)
{
//read the first line HTTP command
string
httpCmd
=
await
clientStreamReader
.
ReadLineAsync
();
...
...
@@ -155,7 +155,7 @@ namespace Titanium.Web.Proxy
return
;
}
if
(
await
IsConnectMethod
(
clientStream
)
==
-
1
)
if
(
await
HttpHelper
.
IsConnectMethod
(
clientStream
)
==
-
1
)
{
// It can be for example some Google (Cloude Messaging for Chrome) magic
excluded
=
true
;
...
...
@@ -228,45 +228,6 @@ namespace Titanium.Web.Proxy
}
}
/// <summary>
/// Determines whether is connect method.
/// </summary>
/// <param name="clientStream">The client stream.</param>
/// <returns>1: when CONNECT, 0: when valid HTTP method, -1: otherwise</returns>
private
async
Task
<
int
>
IsConnectMethod
(
CustomBufferedStream
clientStream
)
{
bool
isConnect
=
true
;
int
legthToCheck
=
10
;
for
(
int
i
=
0
;
i
<
legthToCheck
;
i
++)
{
int
b
=
await
clientStream
.
PeekByteAsync
(
i
);
if
(
b
==
-
1
)
{
return
-
1
;
}
if
(
b
==
' '
&&
i
>
2
)
{
// at least 3 letters and a space
return
isConnect
?
1
:
0
;
}
char
ch
=
(
char
)
b
;
if
(!
char
.
IsLetter
(
ch
))
{
// non letter or too short
return
-
1
;
}
if
(
i
>
6
||
ch
!=
"CONNECT"
[
i
])
{
isConnect
=
false
;
}
}
// only letters
return
isConnect
?
1
:
0
;
}
/// <summary>
/// This is called when this proxy acts as a reverse proxy (like a real http server)
...
...
@@ -640,15 +601,9 @@ namespace Titanium.Web.Proxy
/// <param name="requestHeaders"></param>
private
void
PrepareRequestHeaders
(
HeaderCollection
requestHeaders
)
{
foreach
(
var
header
in
requestHeaders
)
if
(
requestHeaders
.
HeaderExists
(
KnownHeaders
.
AcceptEncoding
)
)
{
switch
(
header
.
Name
.
ToLower
())
{
//these are the only encoding this proxy can read
case
KnownHeaders
.
AcceptEncoding
:
header
.
Value
=
"gzip,deflate"
;
break
;
}
requestHeaders
.
SetOrAddHeaderValue
(
KnownHeaders
.
AcceptEncoding
,
"gzip,deflate"
);
}
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