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
e946e11c
Commit
e946e11c
authored
Dec 31, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
multipart form data reading fixed
parent
57667e1b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
23 deletions
+14
-23
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
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+10
-19
Titanium.Web.Proxy.csproj
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+1
-1
No files found.
Examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj
View file @
e946e11c
...
@@ -51,8 +51,8 @@
...
@@ -51,8 +51,8 @@
<WarningLevel>
4
</WarningLevel>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<Reference
Include=
"StreamExtended, Version=1.0.12
4
.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL"
>
<Reference
Include=
"StreamExtended, Version=1.0.12
7
.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL"
>
<HintPath>
..\..\packages\StreamExtended.1.0.12
4
-beta\lib\net45\StreamExtended.dll
</HintPath>
<HintPath>
..\..\packages\StreamExtended.1.0.12
7
-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 @
e946e11c
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
packages
>
<
package
id
=
"StreamExtended"
version
=
"1.0.12
4
-beta"
targetFramework
=
"net45"
/>
<
package
id
=
"StreamExtended"
version
=
"1.0.12
7
-beta"
targetFramework
=
"net45"
/>
</
packages
>
</
packages
>
\ No newline at end of file
Titanium.Web.Proxy/RequestHandler.cs
View file @
e946e11c
...
@@ -620,29 +620,28 @@ namespace Titanium.Web.Proxy
...
@@ -620,29 +620,28 @@ namespace Titanium.Web.Proxy
//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
)
var
copyStream
=
new
CopyStream
(
reader
,
writer
,
BufferSize
);
var
copyStreamReader
=
new
CustomBinaryReader
(
copyStream
,
BufferSize
);
while
(
bytesToSend
>
copyStream
.
ReadBytes
)
{
{
long
read
=
await
SendUntilBoundaryAsync
(
reader
,
writ
er
,
bytesToSend
,
boundary
);
long
read
=
await
ReadUntilBoundaryAsync
(
copyStreamRead
er
,
bytesToSend
,
boundary
);
if
(
read
==
0
)
if
(
read
==
0
)
{
{
break
;
break
;
}
}
bytesToSend
-=
read
;
if
(
bytesToSend
>
copyStream
.
ReadBytes
)
if
(
bytesToSend
>
0
)
{
{
var
headers
=
new
HeaderCollection
();
var
headers
=
new
HeaderCollection
();
//var stream = new CustomBufferedPeekStream(inputStream);
await
HeaderParser
.
ReadHeaders
(
copyStreamReader
,
headers
);
//await HeaderParser.ReadHeaders(new CustomBinaryReader(stream, BufferSize), headers);
var
stream
=
new
CopyStream
(
reader
,
writer
,
BufferSize
);
await
HeaderParser
.
ReadHeaders
(
new
CustomBinaryReader
(
stream
,
BufferSize
),
headers
);
args
.
OnMultipartRequestPartSent
(
boundary
,
headers
);
args
.
OnMultipartRequestPartSent
(
boundary
,
headers
);
}
}
}
}
await
copyStream
.
FlushAsync
();
}
}
else
else
{
{
...
@@ -654,11 +653,10 @@ namespace Titanium.Web.Proxy
...
@@ -654,11 +653,10 @@ 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
(
CustomBinaryReader
reader
,
HttpRequestWriter
writ
er
,
long
totalBytesToRead
,
string
boundary
)
private
async
Task
<
long
>
ReadUntilBoundaryAsync
(
CustomBinaryReader
read
er
,
long
totalBytesToRead
,
string
boundary
)
{
{
int
bufferDataLength
=
0
;
int
bufferDataLength
=
0
;
// try to use the thread static buffer
var
buffer
=
BufferPool
.
GetBuffer
(
BufferSize
);
var
buffer
=
BufferPool
.
GetBuffer
(
BufferSize
);
try
try
{
{
...
@@ -676,8 +674,7 @@ namespace Titanium.Web.Proxy
...
@@ -676,8 +674,7 @@ namespace Titanium.Web.Proxy
if
(
bufferDataLength
>=
boundaryLength
)
if
(
bufferDataLength
>=
boundaryLength
)
{
{
int
startIdx
=
bufferDataLength
-
boundaryLength
;
int
startIdx
=
bufferDataLength
-
boundaryLength
;
if
(
buffer
[
startIdx
]
==
'-'
&&
buffer
[
startIdx
+
1
]
==
'-'
if
(
buffer
[
startIdx
]
==
'-'
&&
buffer
[
startIdx
+
1
]
==
'-'
)
&&
buffer
[
bufferDataLength
-
2
]
==
'\r'
&&
buffer
[
bufferDataLength
-
1
]
==
'\n'
)
{
{
startIdx
+=
2
;
startIdx
+=
2
;
bool
ok
=
true
;
bool
ok
=
true
;
...
@@ -701,17 +698,11 @@ namespace Titanium.Web.Proxy
...
@@ -701,17 +698,11 @@ 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
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
;
}
}
}
}
if
(
bytesRead
>
0
)
{
await
writer
.
WriteAsync
(
buffer
,
0
,
bufferDataLength
);
}
return
bytesRead
;
return
bytesRead
;
}
}
finally
finally
...
...
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
e946e11c
...
@@ -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.12
4
-beta" />
<PackageReference Include="StreamExtended" Version="1.0.12
7
-beta" />
</ItemGroup>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
...
...
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