@@ -291,13 +291,50 @@ async Task StepHeadersAsync (CancellationToken cancellationToken)
291
291
await OnHeadersEndAsync ( headerBlockBegin , headersBeginLineNumber , headerBlockEnd , lineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
292
292
}
293
293
294
- bool SkipBoundaryMarker ( bool endBoundary )
294
+ async Task < bool > SkipBoundaryMarkerAsync ( string boundary , bool endBoundary , CancellationToken cancellationToken )
295
295
{
296
+ long beginOffset = GetOffset ( inputIndex ) ;
297
+ int beginLineNumber = lineNumber ;
298
+ int startIndex = inputIndex ;
299
+ bool result ;
300
+
301
+ if ( endBoundary )
302
+ await OnMultipartEndBoundaryBeginAsync ( beginOffset , beginLineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
303
+ else
304
+ await OnMultipartBoundaryBeginAsync ( beginOffset , beginLineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
305
+
296
306
unsafe {
297
307
fixed ( byte * inbuf = input ) {
298
- return SkipBoundaryMarker ( inbuf , endBoundary ) ;
308
+ result = SkipBoundaryMarkerInternal ( inbuf , endBoundary ) ;
299
309
}
300
310
}
311
+
312
+ int count = inputIndex - startIndex ;
313
+
314
+ if ( endBoundary )
315
+ await OnMultipartEndBoundaryReadAsync ( input , startIndex , count , beginOffset , beginLineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
316
+ else
317
+ await OnMultipartBoundaryReadAsync ( input , startIndex , count , beginOffset , beginLineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
318
+
319
+ long endOffset = GetOffset ( inputIndex ) ;
320
+
321
+ if ( endBoundary ) {
322
+ await OnMultipartEndBoundaryEndAsync ( beginOffset , beginLineNumber , endOffset , cancellationToken ) . ConfigureAwait ( false ) ;
323
+
324
+ #pragma warning disable 618
325
+ // Obsolete
326
+ await OnMultipartEndBoundaryAsync ( boundary , beginOffset , endOffset , beginLineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
327
+ #pragma warning restore 618
328
+ } else {
329
+ await OnMultipartBoundaryEndAsync ( beginOffset , beginLineNumber , endOffset , cancellationToken ) . ConfigureAwait ( false ) ;
330
+
331
+ #pragma warning disable 618
332
+ // Obsolete
333
+ await OnMultipartBoundaryAsync ( boundary , beginOffset , endOffset , beginLineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
334
+ #pragma warning restore 618
335
+ }
336
+
337
+ return result ;
301
338
}
302
339
303
340
async Task < MimeParserState > StepAsync ( CancellationToken cancellationToken )
@@ -497,18 +534,13 @@ async Task MultipartScanEpilogueAsync (CancellationToken cancellationToken)
497
534
498
535
async Task MultipartScanSubpartsAsync ( ContentType multipartContentType , int depth , CancellationToken cancellationToken )
499
536
{
500
- var boundaryOffset = GetOffset ( inputIndex ) ;
501
-
502
537
do {
503
538
// skip over the boundary marker
504
- if ( ! SkipBoundaryMarker ( endBoundary : false ) ) {
505
- await OnMultipartBoundaryAsync ( multipartContentType . Boundary , boundaryOffset , GetOffset ( inputIndex ) , lineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
539
+ if ( ! await SkipBoundaryMarkerAsync ( multipartContentType . Boundary , endBoundary : false , cancellationToken ) . ConfigureAwait ( false ) ) {
506
540
boundary = BoundaryType . Eos ;
507
541
return ;
508
542
}
509
543
510
- await OnMultipartBoundaryAsync ( multipartContentType . Boundary , boundaryOffset , GetOffset ( inputIndex ) , lineNumber - 1 , cancellationToken ) . ConfigureAwait ( false ) ;
511
-
512
544
var beginLineNumber = lineNumber ;
513
545
514
546
// Note: When parsing non-toplevel parts, the header parser will never result in the Error state.
@@ -517,10 +549,9 @@ async Task MultipartScanSubpartsAsync (ContentType multipartContentType, int dep
517
549
518
550
if ( state == MimeParserState . Boundary ) {
519
551
if ( headerCount == 0 ) {
520
- if ( boundary == BoundaryType . ImmediateBoundary ) {
521
- //beginOffset = GetOffset (inputIndex);
552
+ if ( boundary == BoundaryType . ImmediateBoundary )
522
553
continue ;
523
- }
554
+
524
555
return ;
525
556
}
526
557
@@ -565,8 +596,6 @@ async Task MultipartScanSubpartsAsync (ContentType multipartContentType, int dep
565
596
await OnMimePartEndAsync ( type , currentBeginOffset , beginLineNumber , currentHeadersEndOffset , endOffset , lines , cancellationToken ) . ConfigureAwait ( false ) ;
566
597
break ;
567
598
}
568
-
569
- boundaryOffset = endOffset ;
570
599
} while ( boundary == BoundaryType . ImmediateBoundary ) ;
571
600
}
572
601
@@ -598,14 +627,7 @@ async Task<int> ConstructMultipartAsync (ContentType contentType, int depth, Can
598
627
599
628
if ( boundary == BoundaryType . ImmediateEndBoundary ) {
600
629
// consume the end boundary and read the epilogue (if there is one)
601
- // FIXME: multipart.WriteEndBoundary = true;
602
-
603
- var boundaryOffset = GetOffset ( inputIndex ) ;
604
- var boundaryLineNumber = lineNumber ;
605
-
606
- SkipBoundaryMarker ( endBoundary : true ) ;
607
-
608
- await OnMultipartEndBoundaryAsync ( marker , boundaryOffset , GetOffset ( inputIndex ) , boundaryLineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
630
+ await SkipBoundaryMarkerAsync ( marker , endBoundary : true , cancellationToken ) . ConfigureAwait ( false ) ;
609
631
610
632
PopBoundary ( ) ;
611
633
@@ -616,8 +638,6 @@ async Task<int> ConstructMultipartAsync (ContentType contentType, int depth, Can
616
638
return GetLineCount ( beginLineNumber , beginOffset , endOffset ) ;
617
639
}
618
640
619
- // FIXME: multipart.WriteEndBoundary = false;
620
-
621
641
// We either found the end of the stream or we found a parent's boundary
622
642
PopBoundary ( ) ;
623
643
0 commit comments