Skip to content

Commit 911398a

Browse files
Arno JanssenJericho
authored andcommitted
Ensure not null values
1 parent eba916d commit 911398a

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

Source/HttpMultipartParser.UnitTests/StreamingMultipartFormDataParserUnitTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,21 @@ public async Task CanHandleNullDelegatesAsync()
6363
await parser.RunAsync(TestContext.Current.CancellationToken);
6464
}
6565
}
66+
67+
[Fact]
68+
public void CanHandleDefaultOptions()
69+
{
70+
using (Stream stream = TestUtil.StringToStream(_testData))
71+
{
72+
var parser = new StreamingMultipartFormDataParser(stream);
73+
74+
// Intentionally setting these handlers to null to verify that we can parse the stream despite missing handlers
75+
// See: https://github.com/Http-Multipart-Data-Parser/Http-Multipart-Data-Parser/issues/121
76+
parser.ParameterHandler = null;
77+
parser.FileHandler = null;
78+
79+
parser.Run();
80+
}
81+
}
6682
}
6783
}

Source/HttpMultipartParser/StreamingMultipartFormDataParser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ public StreamingMultipartFormDataParser(Stream stream, string boundary = null, E
106106
_options = new ParserOptions
107107
{
108108
Boundary = boundary,
109-
Encoding = encoding,
109+
Encoding = encoding ?? Constants.DefaultEncoding,
110110
BinaryBufferSize = binaryBufferSize,
111-
BinaryMimeTypes = binaryMimeTypes,
111+
BinaryMimeTypes = binaryMimeTypes ?? Constants.DefaultBinaryMimeTypes,
112112
IgnoreInvalidParts = ignoreInvalidParts
113113
};
114114

@@ -180,12 +180,12 @@ public async Task RunAsync(CancellationToken cancellationToken = default)
180180
/// <summary>
181181
/// Gets the binary buffer size.
182182
/// </summary>
183-
public int BinaryBufferSize { get; private set; }
183+
public int BinaryBufferSize => _options.BinaryBufferSize;
184184

185185
/// <summary>
186186
/// Gets the encoding.
187187
/// </summary>
188-
public Encoding Encoding { get; private set; }
188+
public Encoding Encoding => _options.Encoding;
189189

190190
/// <summary>
191191
/// Gets or sets the FileHandler. Delegates attached to this property will receive sequential file stream data from this parser.

0 commit comments

Comments
 (0)