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
f3ab526d
Unverified
Commit
f3ab526d
authored
Nov 30, 2019
by
honfika
Committed by
GitHub
Nov 30, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #686 from justcoding121/master
beta
parents
51e83bae
4bdf8f38
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
105 additions
and
26 deletions
+105
-26
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+1
-1
LimitedStream.cs
src/Titanium.Web.Proxy/EventArguments/LimitedStream.cs
+93
-2
HttpStream.cs
src/Titanium.Web.Proxy/Helpers/HttpStream.cs
+3
-3
HeaderParser.cs
src/Titanium.Web.Proxy/Http/HeaderParser.cs
+0
-12
SslTools.cs
src/Titanium.Web.Proxy/StreamExtended/SslTools.cs
+1
-1
Titanium.Web.Proxy.Mono.csproj
src/Titanium.Web.Proxy/Titanium.Web.Proxy.Mono.csproj
+1
-1
Titanium.Web.Proxy.NetCore.csproj
src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj
+1
-1
Titanium.Web.Proxy.csproj
src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+1
-1
Titanium.Web.Proxy.nuspec
src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec
+4
-4
No files found.
examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
f3ab526d
...
...
@@ -151,7 +151,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
return
Task
.
FromResult
(
false
);
}
// intecept & cancel redirect or update requests
// inte
r
cept & cancel redirect or update requests
private
async
Task
onRequest
(
object
sender
,
SessionEventArgs
e
)
{
await
writeToConsole
(
"Active Client Connections:"
+
((
ProxyServer
)
sender
).
ClientConnectionCount
);
...
...
src/Titanium.Web.Proxy/EventArguments/LimitedStream.cs
View file @
f3ab526d
using
System
;
using
System.Globalization
;
using
System.IO
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Exceptions
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.StreamExtended.BufferPool
;
using
Titanium.Web.Proxy.StreamExtended.Network
;
...
...
@@ -51,11 +51,22 @@ namespace Titanium.Web.Proxy.EventArguments
{
// read the chunk trail of the previous chunk
string
?
s
=
baseReader
.
ReadLineAsync
().
Result
;
if
(
s
==
null
)
{
bytesRemaining
=
-
1
;
return
;
}
}
readChunkTrail
=
true
;
string
?
chunkHead
=
baseReader
.
ReadLineAsync
().
Result
!;
string
?
chunkHead
=
baseReader
.
ReadLineAsync
().
Result
;
if
(
chunkHead
==
null
)
{
bytesRemaining
=
-
1
;
return
;
}
int
idx
=
chunkHead
.
IndexOf
(
";"
,
StringComparison
.
Ordinal
);
if
(
idx
>=
0
)
{
...
...
@@ -80,6 +91,50 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
private
async
Task
getNextChunkAsync
()
{
if
(
readChunkTrail
)
{
// read the chunk trail of the previous chunk
string
?
s
=
await
baseReader
.
ReadLineAsync
();
if
(
s
==
null
)
{
bytesRemaining
=
-
1
;
return
;
}
}
readChunkTrail
=
true
;
string
?
chunkHead
=
await
baseReader
.
ReadLineAsync
();
if
(
chunkHead
==
null
)
{
bytesRemaining
=
-
1
;
return
;
}
int
idx
=
chunkHead
.
IndexOf
(
";"
,
StringComparison
.
Ordinal
);
if
(
idx
>=
0
)
{
chunkHead
=
chunkHead
.
Substring
(
0
,
idx
);
}
if
(!
int
.
TryParse
(
chunkHead
,
NumberStyles
.
HexNumber
,
null
,
out
int
chunkSize
))
{
throw
new
ProxyHttpException
(
$"Invalid chunk length: '
{
chunkHead
}
'"
,
null
,
null
);
}
bytesRemaining
=
chunkSize
;
if
(
chunkSize
==
0
)
{
bytesRemaining
=
-
1
;
// chunk trail
await
baseReader
.
ReadLineAsync
();
}
}
public
override
void
Flush
()
{
throw
new
NotSupportedException
();
...
...
@@ -131,6 +186,42 @@ namespace Titanium.Web.Proxy.EventArguments
return
res
;
}
public
override
async
Task
<
int
>
ReadAsync
(
byte
[]
buffer
,
int
offset
,
int
count
,
CancellationToken
cancellationToken
)
{
if
(
bytesRemaining
==
-
1
)
{
return
0
;
}
if
(
bytesRemaining
==
0
)
{
if
(
isChunked
)
{
await
getNextChunkAsync
();
}
else
{
bytesRemaining
=
-
1
;
}
}
if
(
bytesRemaining
==
-
1
)
{
return
0
;
}
int
toRead
=
(
int
)
Math
.
Min
(
count
,
bytesRemaining
);
int
res
=
await
baseReader
.
ReadAsync
(
buffer
,
offset
,
toRead
,
cancellationToken
);
bytesRemaining
-=
res
;
if
(
res
==
0
)
{
bytesRemaining
=
-
1
;
}
return
res
;
}
public
async
Task
Finish
()
{
if
(
bytesRemaining
!=
-
1
)
...
...
src/Titanium.Web.Proxy/Helpers/HttpStream.cs
View file @
f3ab526d
...
...
@@ -650,7 +650,7 @@ namespace Titanium.Web.Proxy.Helpers
if
(
bufferDataLength
==
buffer
.
Length
)
{
R
esizeBuffer
(
ref
buffer
,
bufferDataLength
*
2
);
r
esizeBuffer
(
ref
buffer
,
bufferDataLength
*
2
);
}
}
}
...
...
@@ -683,7 +683,7 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary>
/// <param name="buffer"></param>
/// <param name="size"></param>
private
static
void
R
esizeBuffer
(
ref
byte
[]
buffer
,
long
size
)
private
static
void
r
esizeBuffer
(
ref
byte
[]
buffer
,
long
size
)
{
var
newBuffer
=
new
byte
[
size
];
Buffer
.
BlockCopy
(
buffer
,
0
,
newBuffer
,
0
,
buffer
.
Length
);
...
...
@@ -889,7 +889,7 @@ namespace Titanium.Web.Proxy.Helpers
string
?
contentEncoding
=
useOriginalHeaderValues
?
requestResponse
.
OriginalContentEncoding
:
requestResponse
.
ContentEncoding
;
Stream
s
=
limitedStream
=
new
LimitedStream
(
this
,
bufferPool
,
isChunked
,
contentLength
);
if
(
transformation
==
TransformationMode
.
Uncompress
&&
contentEncoding
!=
null
)
{
s
=
decompressStream
=
DecompressionFactory
.
Create
(
CompressionUtil
.
CompressionNameToEnum
(
contentEncoding
),
s
);
...
...
src/Titanium.Web.Proxy/Http/HeaderParser.cs
View file @
f3ab526d
...
...
@@ -24,17 +24,5 @@ namespace Titanium.Web.Proxy.Http
headerCollection
.
AddHeader
(
headerName
,
headerValue
);
}
}
/// <summary>
/// Increase size of buffer and copy existing content to new buffer
/// </summary>
/// <param name="buffer"></param>
/// <param name="size"></param>
private
static
void
resizeBuffer
(
ref
byte
[]
buffer
,
long
size
)
{
var
newBuffer
=
new
byte
[
size
];
Buffer
.
BlockCopy
(
buffer
,
0
,
newBuffer
,
0
,
buffer
.
Length
);
buffer
=
newBuffer
;
}
}
}
src/Titanium.Web.Proxy/StreamExtended/SslTools.cs
View file @
f3ab526d
...
...
@@ -216,7 +216,7 @@ namespace Titanium.Web.Proxy.StreamExtended
int
recordLength
=
((
recordType
&
0x7f
)
<<
8
)
+
peekStream
.
ReadByte
();
if
(
recordLength
<
38
)
{
// Message body too short.
// Message body too short.
return
null
;
}
...
...
src/Titanium.Web.Proxy/Titanium.Web.Proxy.Mono.csproj
View file @
f3ab526d
...
...
@@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="BrotliSharpLib" Version="0.3.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5
.2
" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
</ItemGroup>
...
...
src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj
View file @
f3ab526d
...
...
@@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="BrotliSharpLib" Version="0.3.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5
.2
" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
</ItemGroup>
...
...
src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
f3ab526d
...
...
@@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="BrotliSharpLib" Version="0.3.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5
.2
" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.1'">
...
...
src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec
View file @
f3ab526d
...
...
@@ -16,14 +16,14 @@
<dependencies>
<group
targetFramework=
"net45"
>
<dependency
id=
"BrotliSharpLib"
version=
"0.3.3"
/>
<dependency
id=
"Portable.BouncyCastle"
version=
"1.8.5
.2
"
/>
<dependency
id=
"Portable.BouncyCastle"
version=
"1.8.5"
/>
<dependency
id=
"System.Buffers"
version=
"4.5.0"
/>
<dependency
id=
"System.Memory"
version=
"4.5.3"
/>
<dependency
id=
"System.Threading.Tasks.Extensions"
version=
"4.5.3"
/>
</group>
<group
targetFramework=
"net461"
>
<dependency
id=
"BrotliSharpLib"
version=
"0.3.3"
/>
<dependency
id=
"Portable.BouncyCastle"
version=
"1.8.5
.2
"
/>
<dependency
id=
"Portable.BouncyCastle"
version=
"1.8.5"
/>
<dependency
id=
"Microsoft.Win32.Registry"
version=
"4.6.0"
/>
<dependency
id=
"System.Buffers"
version=
"4.5.0"
/>
<dependency
id=
"System.Memory"
version=
"4.5.3"
/>
...
...
@@ -32,7 +32,7 @@
</group>
<group
targetFramework=
"netstandard2.0"
>
<dependency
id=
"BrotliSharpLib"
version=
"0.3.3"
/>
<dependency
id=
"Portable.BouncyCastle"
version=
"1.8.5
.2
"
/>
<dependency
id=
"Portable.BouncyCastle"
version=
"1.8.5"
/>
<dependency
id=
"Microsoft.Win32.Registry"
version=
"4.6.0"
/>
<dependency
id=
"System.Buffers"
version=
"4.5.0"
/>
<dependency
id=
"System.Memory"
version=
"4.5.3"
/>
...
...
@@ -41,7 +41,7 @@
</group>
<group
targetFramework=
"netstandard2.1"
>
<dependency
id=
"BrotliSharpLib"
version=
"0.3.3"
/>
<dependency
id=
"Portable.BouncyCastle"
version=
"1.8.5
.2
"
/>
<dependency
id=
"Portable.BouncyCastle"
version=
"1.8.5"
/>
<dependency
id=
"Microsoft.Win32.Registry"
version=
"4.6.0"
/>
<dependency
id=
"System.Security.Principal.Windows"
version=
"4.6.0"
/>
</group>
...
...
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