@@ -80,7 +80,6 @@ public class MultipartReaderTests
80
80
"<!DOCTYPE html><title>Content of a.html.</title>\r \n " +
81
81
"\r \n " +
82
82
"--9051914041544843365972754266--\r \n " ;
83
-
84
83
private const string TwoPartBodyIncompleteBuffer =
85
84
"--9051914041544843365972754266\r \n " +
86
85
"Content-Disposition: form-data; name=\" text\" \r \n " +
@@ -315,6 +314,43 @@ public void MultipartReader_BufferSizeMustBeLargerThanBoundary_Throws()
315
314
} ) ;
316
315
}
317
316
317
+ [ Fact ]
318
+ public async Task MultipartReader_ReadMultipartBodyWithFilesForDeferredCopy_Success ( )
319
+ {
320
+ var stream = MakeStream ( ThreePartBody ) ;
321
+ var reader = new MultipartReader ( Boundary , stream ) ;
322
+
323
+ await reader . ReadNextSectionAsync ( ) ; // skip text field section
324
+
325
+ var section = await reader . ReadNextSectionAsync ( ) ;
326
+ Assert . NotNull ( section ) ;
327
+ Assert . Equal ( 2 , section . Headers . Count ) ;
328
+ Assert . Equal ( "form-data; name=\" file1\" ; filename=\" a.txt\" " , section . Headers [ "Content-Disposition" ] [ 0 ] ) ;
329
+ Assert . Equal ( "text/plain" , section . Headers [ "Content-Type" ] [ 0 ] ) ;
330
+ var stream1 = section . Body ;
331
+
332
+ section = await reader . ReadNextSectionAsync ( ) ;
333
+ Assert . NotNull ( section ) ;
334
+ Assert . Equal ( 2 , section . Headers . Count ) ;
335
+ Assert . Equal ( "form-data; name=\" file2\" ; filename=\" a.html\" " , section . Headers [ "Content-Disposition" ] [ 0 ] ) ;
336
+ Assert . Equal ( "text/html" , section . Headers [ "Content-Type" ] [ 0 ] ) ;
337
+ var stream2 = section . Body ;
338
+
339
+ Assert . Null ( await reader . ReadNextSectionAsync ( ) ) ;
340
+
341
+ Assert . True ( stream1 . CanSeek ) ;
342
+ Assert . Equal ( 0 , stream1 . Seek ( 0 , SeekOrigin . Begin ) ) ;
343
+ var buffer = new MemoryStream ( ) ;
344
+ await stream1 . CopyToAsync ( buffer ) ;
345
+ Assert . Equal ( "Content of a.txt.\r \n " , Encoding . ASCII . GetString ( buffer . ToArray ( ) ) ) ;
346
+
347
+ Assert . True ( stream2 . CanSeek ) ;
348
+ Assert . Equal ( 0 , stream2 . Seek ( 0 , SeekOrigin . Begin ) ) ;
349
+ buffer = new MemoryStream ( ) ;
350
+ await stream2 . CopyToAsync ( buffer ) ;
351
+ Assert . Equal ( "<!DOCTYPE html><title>Content of a.html.</title>\r \n " , Encoding . ASCII . GetString ( buffer . ToArray ( ) ) ) ;
352
+ }
353
+
318
354
[ Fact ]
319
355
public async Task MultipartReader_TwoPartBodyIncompleteBuffer_TwoSectionsReadSuccessfullyThirdSectionThrows ( )
320
356
{
0 commit comments