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
57667e1b
Commit
57667e1b
authored
Dec 31, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
StreamExtended updated
parent
01e06028
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
31 deletions
+29
-31
Titanium.Web.Proxy.Examples.Wpf.csproj
...Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj
+2
-2
packages.config
Examples/Titanium.Web.Proxy.Examples.Wpf/packages.config
+1
-1
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+1
-1
StreamExtensions.cs
Titanium.Web.Proxy/Extensions/StreamExtensions.cs
+0
-2
HttpWriter.cs
Titanium.Web.Proxy/Helpers/HttpWriter.cs
+9
-12
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+14
-11
Titanium.Web.Proxy.csproj
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+2
-2
No files found.
Examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj
View file @
57667e1b
...
@@ -51,8 +51,8 @@
...
@@ -51,8 +51,8 @@
<WarningLevel>
4
</WarningLevel>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<Reference
Include=
"StreamExtended, Version=1.0.1
15
.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL"
>
<Reference
Include=
"StreamExtended, Version=1.0.1
24
.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL"
>
<HintPath>
..\..\packages\StreamExtended.1.0.1
15
-beta\lib\net45\StreamExtended.dll
</HintPath>
<HintPath>
..\..\packages\StreamExtended.1.0.1
24
-beta\lib\net45\StreamExtended.dll
</HintPath>
</Reference>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Data"
/>
...
...
Examples/Titanium.Web.Proxy.Examples.Wpf/packages.config
View file @
57667e1b
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
packages
>
<
package
id
=
"StreamExtended"
version
=
"1.0.1
15
-beta"
targetFramework
=
"net45"
/>
<
package
id
=
"StreamExtended"
version
=
"1.0.1
24
-beta"
targetFramework
=
"net45"
/>
</
packages
>
</
packages
>
\ No newline at end of file
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
57667e1b
...
@@ -41,7 +41,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -41,7 +41,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary>
/// <summary>
/// Holds a reference to client
/// Holds a reference to client
/// </summary>
/// </summary>
internal
ProxyClient
ProxyClient
{
get
;
set
;
}
internal
ProxyClient
ProxyClient
{
get
;
}
internal
bool
HasMulipartEventSubscribers
=>
MultipartRequestPartSent
!=
null
;
internal
bool
HasMulipartEventSubscribers
=>
MultipartRequestPartSent
!=
null
;
...
...
Titanium.Web.Proxy/Extensions/StreamExtensions.cs
View file @
57667e1b
using
System
;
using
System
;
using
System.Globalization
;
using
System.IO
;
using
System.IO
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended.Network
;
namespace
Titanium.Web.Proxy.Extensions
namespace
Titanium.Web.Proxy.Extensions
{
{
...
...
Titanium.Web.Proxy/Helpers/HttpWriter.cs
View file @
57667e1b
...
@@ -10,25 +10,22 @@ using Titanium.Web.Proxy.Shared;
...
@@ -10,25 +10,22 @@ using Titanium.Web.Proxy.Shared;
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
{
{
internal
class
HttpWriter
internal
class
HttpWriter
:
CustomBinaryWriter
{
{
public
int
BufferSize
{
get
;
}
public
int
BufferSize
{
get
;
}
private
readonly
Stream
stream
;
private
readonly
char
[]
charBuffer
;
private
readonly
char
[]
charBuffer
;
private
static
readonly
byte
[]
newLine
=
ProxyConstants
.
NewLine
;
private
static
readonly
byte
[]
newLine
=
ProxyConstants
.
NewLine
;
private
static
readonly
Encoder
encoder
=
Encoding
.
ASCII
.
GetEncoder
();
private
static
readonly
Encoder
encoder
=
Encoding
.
ASCII
.
GetEncoder
();
internal
HttpWriter
(
Stream
stream
,
int
bufferSize
)
internal
HttpWriter
(
Stream
stream
,
int
bufferSize
)
:
base
(
stream
)
{
{
BufferSize
=
bufferSize
;
BufferSize
=
bufferSize
;
// ASCII encoder max byte count is char count + 1
// ASCII encoder max byte count is char count + 1
charBuffer
=
new
char
[
BufferSize
-
1
];
charBuffer
=
new
char
[
BufferSize
-
1
];
this
.
stream
=
stream
;
}
}
public
Task
WriteLineAsync
()
public
Task
WriteLineAsync
()
...
@@ -88,27 +85,27 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -88,27 +85,27 @@ namespace Titanium.Web.Proxy.Helpers
if
(
flush
)
if
(
flush
)
{
{
// flush the stream
// flush the stream
await
stream
.
FlushAsync
();
await
FlushAsync
();
}
}
}
}
public
async
Task
WriteAsync
(
byte
[]
data
,
bool
flush
=
false
)
public
async
Task
WriteAsync
(
byte
[]
data
,
bool
flush
=
false
)
{
{
await
stream
.
WriteAsync
(
data
,
0
,
data
.
Length
);
await
WriteAsync
(
data
,
0
,
data
.
Length
);
if
(
flush
)
if
(
flush
)
{
{
// flush the stream
// flush the stream
await
stream
.
FlushAsync
();
await
FlushAsync
();
}
}
}
}
public
async
Task
WriteAsync
(
byte
[]
data
,
int
offset
,
int
count
,
bool
flush
=
false
)
public
async
Task
WriteAsync
(
byte
[]
data
,
int
offset
,
int
count
,
bool
flush
)
{
{
await
stream
.
WriteAsync
(
data
,
offset
,
count
);
await
WriteAsync
(
data
,
offset
,
count
);
if
(
flush
)
if
(
flush
)
{
{
// flush the stream
// flush the stream
await
stream
.
FlushAsync
();
await
FlushAsync
();
}
}
}
}
...
@@ -240,7 +237,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -240,7 +237,7 @@ namespace Titanium.Web.Proxy.Helpers
remainingBytes
-=
bytesRead
;
remainingBytes
-=
bytesRead
;
await
stream
.
WriteAsync
(
buffer
,
0
,
bytesRead
);
await
WriteAsync
(
buffer
,
0
,
bytesRead
);
}
}
}
}
}
}
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
57667e1b
...
@@ -614,17 +614,19 @@ namespace Titanium.Web.Proxy
...
@@ -614,17 +614,19 @@ namespace Titanium.Web.Proxy
{
{
// End the operation
// End the operation
var
request
=
args
.
WebSession
.
Request
;
var
request
=
args
.
WebSession
.
Request
;
var
reader
=
args
.
ProxyClient
.
ClientStreamReader
;
var
writer
=
args
.
WebSession
.
ServerConnection
.
StreamWriter
;
//send the request body bytes to server
//send the request body bytes to server
if
(
request
.
ContentLength
>
0
&&
args
.
HasMulipartEventSubscribers
&&
request
.
IsMultipartFormData
)
if
(
request
.
ContentLength
>
0
&&
args
.
HasMulipartEventSubscribers
&&
request
.
IsMultipartFormData
)
{
{
var
inputStream
=
args
.
ProxyClient
.
ClientStream
;
string
boundary
=
HttpHelper
.
GetBoundaryFromContentType
(
request
.
ContentType
);
string
boundary
=
HttpHelper
.
GetBoundaryFromContentType
(
request
.
ContentType
);
long
bytesToSend
=
request
.
ContentLength
;
long
bytesToSend
=
request
.
ContentLength
;
while
(
bytesToSend
>
0
)
while
(
bytesToSend
>
0
)
{
{
var
outputStream
=
args
.
WebSession
.
ServerConnection
.
StreamWriter
;
long
read
=
await
SendUntilBoundaryAsync
(
reader
,
writer
,
bytesToSend
,
boundary
);
long
read
=
await
SendUntilBoundaryAsync
(
args
.
ProxyClient
.
ClientStream
,
outputStream
,
bytesToSend
,
boundary
);
if
(
read
==
0
)
if
(
read
==
0
)
{
{
break
;
break
;
...
@@ -634,7 +636,9 @@ namespace Titanium.Web.Proxy
...
@@ -634,7 +636,9 @@ namespace Titanium.Web.Proxy
if
(
bytesToSend
>
0
)
if
(
bytesToSend
>
0
)
{
{
var
headers
=
new
HeaderCollection
();
var
headers
=
new
HeaderCollection
();
var
stream
=
new
CustomBufferedPeekStream
(
args
.
ProxyClient
.
ClientStream
);
//var stream = new CustomBufferedPeekStream(inputStream);
//await HeaderParser.ReadHeaders(new CustomBinaryReader(stream, BufferSize), headers);
var
stream
=
new
CopyStream
(
reader
,
writer
,
BufferSize
);
await
HeaderParser
.
ReadHeaders
(
new
CustomBinaryReader
(
stream
,
BufferSize
),
headers
);
await
HeaderParser
.
ReadHeaders
(
new
CustomBinaryReader
(
stream
,
BufferSize
),
headers
);
args
.
OnMultipartRequestPartSent
(
boundary
,
headers
);
args
.
OnMultipartRequestPartSent
(
boundary
,
headers
);
}
}
...
@@ -642,8 +646,7 @@ namespace Titanium.Web.Proxy
...
@@ -642,8 +646,7 @@ namespace Titanium.Web.Proxy
}
}
else
else
{
{
await
args
.
WebSession
.
ServerConnection
.
StreamWriter
.
CopyBodyAsync
(
args
.
ProxyClient
.
ClientStreamReader
,
await
writer
.
CopyBodyAsync
(
args
.
ProxyClient
.
ClientStreamReader
,
request
.
IsChunked
,
request
.
ContentLength
,
false
);
request
.
IsChunked
,
request
.
ContentLength
,
false
);
}
}
}
}
...
@@ -651,7 +654,7 @@ namespace Titanium.Web.Proxy
...
@@ -651,7 +654,7 @@ namespace Titanium.Web.Proxy
/// Read a line from the byte stream
/// Read a line from the byte stream
/// </summary>
/// </summary>
/// <returns></returns>
/// <returns></returns>
private
async
Task
<
long
>
SendUntilBoundaryAsync
(
CustomB
ufferedStream
inputStream
,
HttpRequestWriter
outputStream
,
long
totalBytesToRead
,
string
boundary
)
private
async
Task
<
long
>
SendUntilBoundaryAsync
(
CustomB
inaryReader
reader
,
HttpRequestWriter
writer
,
long
totalBytesToRead
,
string
boundary
)
{
{
int
bufferDataLength
=
0
;
int
bufferDataLength
=
0
;
...
@@ -662,9 +665,9 @@ namespace Titanium.Web.Proxy
...
@@ -662,9 +665,9 @@ namespace Titanium.Web.Proxy
int
boundaryLength
=
boundary
.
Length
+
4
;
int
boundaryLength
=
boundary
.
Length
+
4
;
long
bytesRead
=
0
;
long
bytesRead
=
0
;
while
(
bytesRead
<
totalBytesToRead
&&
(
inputStream
.
DataAvailable
||
await
inputStream
.
FillBufferAsync
()))
while
(
bytesRead
<
totalBytesToRead
&&
(
reader
.
DataAvailable
||
await
reader
.
FillBufferAsync
()))
{
{
byte
newChar
=
inputStream
.
ReadByteFromBuffer
();
byte
newChar
=
reader
.
ReadByteFromBuffer
();
buffer
[
bufferDataLength
]
=
newChar
;
buffer
[
bufferDataLength
]
=
newChar
;
bufferDataLength
++;
bufferDataLength
++;
...
@@ -698,7 +701,7 @@ namespace Titanium.Web.Proxy
...
@@ -698,7 +701,7 @@ namespace Titanium.Web.Proxy
{
{
//boundary is not longer than 70 bytes according to the specification, so keeping the last 100 (minimum 74) bytes is enough
//boundary is not longer than 70 bytes according to the specification, so keeping the last 100 (minimum 74) bytes is enough
const
int
bytesToKeep
=
100
;
const
int
bytesToKeep
=
100
;
await
outputStream
.
WriteAsync
(
buffer
,
0
,
buffer
.
Length
-
bytesToKeep
);
await
writer
.
WriteAsync
(
buffer
,
0
,
buffer
.
Length
-
bytesToKeep
);
Buffer
.
BlockCopy
(
buffer
,
buffer
.
Length
-
bytesToKeep
,
buffer
,
0
,
bytesToKeep
);
Buffer
.
BlockCopy
(
buffer
,
buffer
.
Length
-
bytesToKeep
,
buffer
,
0
,
bytesToKeep
);
bufferDataLength
=
bytesToKeep
;
bufferDataLength
=
bytesToKeep
;
}
}
...
@@ -706,7 +709,7 @@ namespace Titanium.Web.Proxy
...
@@ -706,7 +709,7 @@ namespace Titanium.Web.Proxy
if
(
bytesRead
>
0
)
if
(
bytesRead
>
0
)
{
{
await
outputStream
.
WriteAsync
(
buffer
,
0
,
bufferDataLength
);
await
writer
.
WriteAsync
(
buffer
,
0
,
bufferDataLength
);
}
}
return
bytesRead
;
return
bytesRead
;
...
...
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
57667e1b
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
<ItemGroup>
<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.1.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.1.3" />
<PackageReference Include="StreamExtended" Version="1.0.1
15
-beta" />
<PackageReference Include="StreamExtended" Version="1.0.1
24
-beta" />
</ItemGroup>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
<Version>4.4.0</Version>
<Version>4.4.0</Version>
</PackageReference>
</PackageReference>
<PackageReference Include="System.Security.Principal.Windows">
<PackageReference Include="System.Security.Principal.Windows">
<Version>4.4.
0
</Version>
<Version>4.4.
1
</Version>
</PackageReference>
</PackageReference>
</ItemGroup>
</ItemGroup>
...
...
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