33
44using System . IO ;
55using System . Text ;
6+ using System . Threading ;
67using System . Threading . Tasks ;
7- using Microsoft . AspNet . Http ;
88using Microsoft . AspNet . FeatureModel ;
9+ using Microsoft . AspNet . Http ;
910using Microsoft . AspNet . HttpFeature ;
1011using Microsoft . AspNet . PipelineCore . Collections ;
1112using Microsoft . AspNet . PipelineCore . Infrastructure ;
@@ -24,14 +25,22 @@ public FormFeature(IFeatureCollection features)
2425 _features = features ;
2526 }
2627
27- public async Task < IReadableStringCollection > GetFormAsync ( )
28+ public async Task < IReadableStringCollection > GetFormAsync ( CancellationToken cancel )
2829 {
2930 var body = _request . Fetch ( _features ) . Body ;
3031
3132 if ( _bodyStream == null || _bodyStream != body )
3233 {
3334 _bodyStream = body ;
34- using ( var streamReader = new StreamReader ( body , Encoding . UTF8 ,
35+ if ( ! _bodyStream . CanSeek )
36+ {
37+ MemoryStream buffer = new MemoryStream ( ) ;
38+ await _bodyStream . CopyToAsync ( buffer , 4096 , cancel ) ;
39+ _bodyStream = buffer ;
40+ _request . Fetch ( _features ) . Body = _bodyStream ;
41+ _bodyStream . Seek ( 0 , SeekOrigin . Begin ) ;
42+ }
43+ using ( var streamReader = new StreamReader ( _bodyStream , Encoding . UTF8 ,
3544 detectEncodingFromByteOrderMarks : true ,
3645 bufferSize : 1024 , leaveOpen : true ) )
3746 {
0 commit comments