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
299d4bad
Commit
299d4bad
authored
Oct 05, 2019
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for #638
parent
b6d73ca5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
13 deletions
+22
-13
HttpHelper.cs
src/Titanium.Web.Proxy/Helpers/HttpHelper.cs
+21
-13
ProxyServer.cs
src/Titanium.Web.Proxy/ProxyServer.cs
+1
-0
No files found.
src/Titanium.Web.Proxy/Helpers/HttpHelper.cs
View file @
299d4bad
...
...
@@ -151,20 +151,28 @@ namespace Titanium.Web.Proxy.Helpers
/// </returns>
private
static
async
Task
<
int
>
startsWith
(
ICustomStreamReader
clientStreamReader
,
IBufferPool
bufferPool
,
string
expectedStart
,
CancellationToken
cancellationToken
=
default
)
{
int
iRet
=
-
1
;
const
int
lengthToCheck
=
10
;
byte
[]
buffer
=
null
;
try
{
buffer
=
bufferPool
.
GetBuffer
(
Math
.
Max
(
bufferPool
.
BufferSize
,
lengthToCheck
));
if
(
bufferPool
.
BufferSize
<
lengthToCheck
)
{
throw
new
Exception
(
$"Buffer is too small. Minimum size is
{
lengthToCheck
}
bytes"
);
}
int
peeked
=
await
clientStreamReader
.
PeekBytesAsync
(
buffer
,
0
,
0
,
lengthToCheck
,
cancellationToken
);
buffer
=
bufferPool
.
GetBuffer
(
bufferPool
.
BufferSize
);
if
(
peeked
>
0
)
bool
isExpected
=
true
;
int
i
=
0
;
while
(
i
<
lengthToCheck
)
{
bool
isExpected
=
true
;
int
peeked
=
await
clientStreamReader
.
PeekBytesAsync
(
buffer
,
i
,
i
,
lengthToCheck
-
i
,
cancellationToken
);
if
(
peeked
==
0
)
return
-
1
;
peeked
+=
i
;
for
(
int
i
=
0
;
i
<
lengthToCheck
;
i
++
)
while
(
i
<
peeked
)
{
int
b
=
buffer
[
i
];
...
...
@@ -173,23 +181,23 @@ namespace Titanium.Web.Proxy.Helpers
else
{
char
ch
=
(
char
)
b
;
if
(
!
char
.
IsLetter
(
ch
))
if
(
ch
<
'A'
||
ch
>
'z'
||
(
ch
>
'Z'
&&
ch
<
'a'
))
// ASCII letter
return
-
1
;
else
if
(
i
>=
expectedStart
.
Length
||
ch
!=
expectedStart
[
i
])
isExpected
=
false
;
isExpected
=
false
;
}
}
// only letters
iRet
=
isExpected
?
1
:
0
;
i
++;
}
}
// only letters
return
0
;
}
finally
{
bufferPool
.
ReturnBuffer
(
buffer
);
buffer
=
null
;
}
return
iRet
;
}
}
}
src/Titanium.Web.Proxy/ProxyServer.cs
View file @
299d4bad
...
...
@@ -235,6 +235,7 @@ namespace Titanium.Web.Proxy
/// The buffer pool used throughout this proxy instance.
/// Set custom implementations by implementing this interface.
/// By default this uses DefaultBufferPool implementation available in StreamExtended library package.
/// Buffer size should be at least 10 bytes.
/// </summary>
public
IBufferPool
BufferPool
{
get
;
set
;
}
...
...
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