Skip to content

Commit 397ebad

Browse files
committed
Merge branch 'release/8.1.0'
2 parents 074d608 + d5980a2 commit 397ebad

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

Source/HttpMultipartParser/MultipartFormBinaryDataParser.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System.Collections.Generic;
2424
using System.IO;
2525
using System.Text;
26+
using System.Threading;
2627
using System.Threading.Tasks;
2728

2829
namespace HttpMultipartParser
@@ -201,12 +202,15 @@ public static MultipartFormBinaryDataParser Parse(Stream stream, string boundary
201202
/// <param name="ignoreInvalidParts">
202203
/// By default the parser will throw an exception if it encounters an invalid part. Set this to true to ignore invalid parts.
203204
/// </param>
205+
/// <param name="cancellationToken">
206+
/// The cancellation token.
207+
/// </param>
204208
/// <returns>
205209
/// A new instance of the <see cref="MultipartFormBinaryDataParser"/> class.
206210
/// </returns>
207-
public static Task<MultipartFormBinaryDataParser> ParseAsync(Stream stream, Encoding encoding, int binaryBufferSize = Constants.DefaultBufferSize, string[] binaryMimeTypes = null, bool ignoreInvalidParts = false)
211+
public static Task<MultipartFormBinaryDataParser> ParseAsync(Stream stream, Encoding encoding, int binaryBufferSize = Constants.DefaultBufferSize, string[] binaryMimeTypes = null, bool ignoreInvalidParts = false, CancellationToken cancellationToken = default)
208212
{
209-
return ParseAsync(stream, null, encoding, binaryBufferSize, binaryMimeTypes, ignoreInvalidParts);
213+
return ParseAsync(stream, null, encoding, binaryBufferSize, binaryMimeTypes, ignoreInvalidParts, cancellationToken);
210214
}
211215

212216
/// <summary>
@@ -233,13 +237,16 @@ public static Task<MultipartFormBinaryDataParser> ParseAsync(Stream stream, Enco
233237
/// <param name="ignoreInvalidParts">
234238
/// By default the parser will throw an exception if it encounters an invalid part. Set this to true to ignore invalid parts.
235239
/// </param>
240+
/// <param name="cancellationToken">
241+
/// The cancellation token.
242+
/// </param>
236243
/// <returns>
237244
/// A new instance of the <see cref="MultipartFormBinaryDataParser"/> class.
238245
/// </returns>
239-
public static async Task<MultipartFormBinaryDataParser> ParseAsync(Stream stream, string boundary = null, Encoding encoding = null, int binaryBufferSize = Constants.DefaultBufferSize, string[] binaryMimeTypes = null, bool ignoreInvalidParts = false)
246+
public static async Task<MultipartFormBinaryDataParser> ParseAsync(Stream stream, string boundary = null, Encoding encoding = null, int binaryBufferSize = Constants.DefaultBufferSize, string[] binaryMimeTypes = null, bool ignoreInvalidParts = false, CancellationToken cancellationToken = default)
240247
{
241248
var parser = new MultipartFormBinaryDataParser();
242-
await parser.ParseStreamAsync(stream, boundary, encoding, binaryBufferSize, binaryMimeTypes, ignoreInvalidParts).ConfigureAwait(false);
249+
await parser.ParseStreamAsync(stream, boundary, encoding, binaryBufferSize, binaryMimeTypes, ignoreInvalidParts, cancellationToken).ConfigureAwait(false);
243250
return parser;
244251
}
245252

@@ -321,7 +328,10 @@ private void ParseStream(Stream stream, string boundary, Encoding encoding, int
321328
/// <param name="ignoreInvalidParts">
322329
/// By default the parser will throw an exception if it encounters an invalid part. Set this to true to ignore invalid parts.
323330
/// </param>
324-
private async Task ParseStreamAsync(Stream stream, string boundary, Encoding encoding, int binaryBufferSize, string[] binaryMimeTypes, bool ignoreInvalidParts)
331+
/// <param name="cancellationToken">
332+
/// The cancellation token.
333+
/// </param>
334+
private async Task ParseStreamAsync(Stream stream, string boundary, Encoding encoding, int binaryBufferSize, string[] binaryMimeTypes, bool ignoreInvalidParts, CancellationToken cancellationToken)
325335
{
326336
var desiredEncoding = encoding ?? Constants.DefaultEncoding;
327337
var streamingParser = new StreamingBinaryMultipartFormDataParser(stream, boundary, desiredEncoding, binaryBufferSize, binaryMimeTypes, ignoreInvalidParts);
@@ -341,7 +351,7 @@ private async Task ParseStreamAsync(Stream stream, string boundary, Encoding enc
341351
Files[Files.Count - 1].Data.Write(buffer, 0, bytes);
342352
};
343353

344-
await streamingParser.RunAsync().ConfigureAwait(false);
354+
await streamingParser.RunAsync(cancellationToken).ConfigureAwait(false);
345355

346356
// Reset all the written memory streams so they can be read.
347357
foreach (var file in Files)

Source/HttpMultipartParser/MultipartFormDataParser.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System.Collections.Generic;
2424
using System.IO;
2525
using System.Text;
26+
using System.Threading;
2627
using System.Threading.Tasks;
2728

2829
namespace HttpMultipartParser
@@ -204,9 +205,12 @@ public static MultipartFormDataParser Parse(Stream stream, string boundary = nul
204205
/// <returns>
205206
/// A new instance of the <see cref="MultipartFormDataParser"/> class.
206207
/// </returns>
207-
public static Task<MultipartFormDataParser> ParseAsync(Stream stream, Encoding encoding, int binaryBufferSize = Constants.DefaultBufferSize, string[] binaryMimeTypes = null, bool ignoreInvalidParts = false)
208+
/// <param name="cancellationToken">
209+
/// The cancellation token.
210+
/// </param>
211+
public static Task<MultipartFormDataParser> ParseAsync(Stream stream, Encoding encoding, int binaryBufferSize = Constants.DefaultBufferSize, string[] binaryMimeTypes = null, bool ignoreInvalidParts = false, CancellationToken cancellationToken = default)
208212
{
209-
return ParseAsync(stream, null, encoding, binaryBufferSize, binaryMimeTypes, ignoreInvalidParts);
213+
return ParseAsync(stream, null, encoding, binaryBufferSize, binaryMimeTypes, ignoreInvalidParts, cancellationToken);
210214
}
211215

212216
/// <summary>
@@ -233,13 +237,16 @@ public static Task<MultipartFormDataParser> ParseAsync(Stream stream, Encoding e
233237
/// <param name="ignoreInvalidParts">
234238
/// By default the parser will throw an exception if it encounters an invalid part. Set this to true to ignore invalid parts.
235239
/// </param>
240+
/// <param name="cancellationToken">
241+
/// The cancellation token.
242+
/// </param>
236243
/// <returns>
237244
/// A new instance of the <see cref="MultipartFormDataParser"/> class.
238245
/// </returns>
239-
public static async Task<MultipartFormDataParser> ParseAsync(Stream stream, string boundary = null, Encoding encoding = null, int binaryBufferSize = Constants.DefaultBufferSize, string[] binaryMimeTypes = null, bool ignoreInvalidParts = false)
246+
public static async Task<MultipartFormDataParser> ParseAsync(Stream stream, string boundary = null, Encoding encoding = null, int binaryBufferSize = Constants.DefaultBufferSize, string[] binaryMimeTypes = null, bool ignoreInvalidParts = false, CancellationToken cancellationToken = default)
240247
{
241248
var parser = new MultipartFormDataParser();
242-
await parser.ParseStreamAsync(stream, boundary, encoding, binaryBufferSize, binaryMimeTypes, ignoreInvalidParts).ConfigureAwait(false);
249+
await parser.ParseStreamAsync(stream, boundary, encoding, binaryBufferSize, binaryMimeTypes, ignoreInvalidParts, cancellationToken).ConfigureAwait(false);
243250
return parser;
244251
}
245252

@@ -319,7 +326,10 @@ private void ParseStream(Stream stream, string boundary, Encoding encoding, int
319326
/// <param name="ignoreInvalidParts">
320327
/// By default the parser will throw an exception if it encounters an invalid part. Set this to true to ignore invalid parts.
321328
/// </param>
322-
private async Task ParseStreamAsync(Stream stream, string boundary, Encoding encoding, int binaryBufferSize, string[] binaryMimeTypes, bool ignoreInvalidParts)
329+
/// <param name="cancellationToken">
330+
/// The cancellation token.
331+
/// </param>
332+
private async Task ParseStreamAsync(Stream stream, string boundary, Encoding encoding, int binaryBufferSize, string[] binaryMimeTypes, bool ignoreInvalidParts, CancellationToken cancellationToken)
323333
{
324334
var desiredEncoding = encoding ?? Constants.DefaultEncoding;
325335
var streamingParser = new StreamingBinaryMultipartFormDataParser(stream, boundary, desiredEncoding, binaryBufferSize, binaryMimeTypes, ignoreInvalidParts);
@@ -336,7 +346,7 @@ private async Task ParseStreamAsync(Stream stream, string boundary, Encoding enc
336346
Files[Files.Count - 1].Data.Write(buffer, 0, bytes);
337347
};
338348

339-
await streamingParser.RunAsync().ConfigureAwait(false);
349+
await streamingParser.RunAsync(cancellationToken).ConfigureAwait(false);
340350

341351
// Reset all the written memory streams so they can be read.
342352
foreach (var file in Files)

build.cake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Install tools.
2-
#tool dotnet:?package=GitVersion.Tool&version=5.11.1
2+
#tool dotnet:?package=GitVersion.Tool&version=5.12.0
33
#tool dotnet:?package=coveralls.net&version=4.0.1
44
#tool nuget:?package=GitReleaseManager&version=0.13.0
5-
#tool nuget:?package=ReportGenerator&version=5.1.13
5+
#tool nuget:?package=ReportGenerator&version=5.1.16
66
#tool nuget:?package=xunit.runner.console&version=2.4.2
77
#tool nuget:?package=Codecov&version=1.13.0
88

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "7.0.100",
3+
"version": "7.0.102",
44
"rollForward": "latestFeature"
55
}
66
}

0 commit comments

Comments
 (0)