Skip to content

Commit 589a22b

Browse files
committed
Merge branch 'release/4.3.1'
2 parents 497c8f2 + c18f4dd commit 589a22b

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using Xunit;
6+
7+
namespace HttpMultipartParser.UnitTests.ParserScenarios
8+
{
9+
public class MjpegStream
10+
{
11+
private static readonly string _testData = TestUtil.TrimAllLines(
12+
@"--MOBOTIX_Fast_Serverpush
13+
Content-Type: image/jpeg
14+
15+
<jpeg bytes>
16+
--MOBOTIX_Fast_Serverpush
17+
Content-Type: image/jpeg
18+
19+
<jpeg bytes>
20+
--MOBOTIX_Fast_Serverpush
21+
Content-Type: image/jpeg
22+
23+
... and so on ...
24+
--MOBOTIX_Fast_Serverpush--"
25+
);
26+
27+
/// <summary>
28+
/// Test case for mjpeg stream.
29+
/// </summary>
30+
private static readonly TestData _testCase = new TestData(
31+
_testData,
32+
new List<ParameterPart> { },
33+
new List<FilePart> {
34+
new FilePart(null, null, TestUtil.StringToStreamNoBom("<jpeg bytes>"), "image/jpeg", "form-data"),
35+
new FilePart(null, null, TestUtil.StringToStreamNoBom("<jpeg bytes>"), "image/jpeg", "form-data"),
36+
new FilePart(null, null, TestUtil.StringToStreamNoBom("... and so on ..."), "image/jpeg", "form-data")
37+
}
38+
);
39+
40+
/// <summary>
41+
/// Initializes the test data before each run, this primarily
42+
/// consists of resetting data stream positions.
43+
/// </summary>
44+
public MjpegStream()
45+
{
46+
foreach (var filePart in _testCase.ExpectedFileData)
47+
{
48+
filePart.Data.Position = 0;
49+
}
50+
}
51+
52+
[Fact]
53+
public void MjpegStreamTest()
54+
{
55+
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
56+
{
57+
var parser = MultipartFormDataParser.Parse(stream, "MOBOTIX_Fast_Serverpush", Encoding.UTF8, 32);
58+
Assert.True(_testCase.Validate(parser));
59+
}
60+
}
61+
62+
[Fact]
63+
public async Task MjpegStreamTest_Async()
64+
{
65+
using (Stream stream = TestUtil.StringToStream(_testCase.Request, Encoding.UTF8))
66+
{
67+
var parser = await MultipartFormDataParser.ParseAsync(stream, "MOBOTIX_Fast_Serverpush", Encoding.UTF8, 32).ConfigureAwait(false);
68+
Assert.True(_testCase.Validate(parser));
69+
}
70+
}
71+
}
72+
}

Source/HttpMultipartParser/FilePart.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public FilePart(string name, string fileName, Stream data)
7575
public FilePart(string name, string fileName, Stream data, string contentType, string contentDisposition)
7676
{
7777
Name = name;
78-
FileName = fileName.Split(Path.GetInvalidFileNameChars()).Last();
78+
FileName = fileName?.Split(Path.GetInvalidFileNameChars()).Last();
7979
Data = data;
8080
ContentType = contentType;
8181
ContentDisposition = contentDisposition;

0 commit comments

Comments
 (0)