This repository was archived by the owner on Nov 1, 2018. It is now read-only.
File tree 2 files changed +18
-10
lines changed
2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -62,18 +62,15 @@ public void Dispose()
62
62
63
63
public async Task Send ( params string [ ] lines )
64
64
{
65
- var text = string . Join ( "\r \n " , lines ) ;
66
- var writer = new StreamWriter ( _stream , Encoding . GetEncoding ( "iso-8859-1" ) ) ;
67
- for ( var index = 0 ; index < text . Length ; index ++ )
65
+ var bytes = Encoding . ASCII . GetBytes ( string . Join ( "\r \n " , lines ) ) ;
66
+
67
+ for ( var index = 0 ; index < bytes . Length ; index ++ )
68
68
{
69
- var ch = text [ index ] ;
70
- writer . Write ( ch ) ;
71
- await writer . FlushAsync ( ) . ConfigureAwait ( false ) ;
69
+ await _stream . WriteAsync ( bytes , index , 1 ) . ConfigureAwait ( false ) ;
70
+ await _stream . FlushAsync ( ) . ConfigureAwait ( false ) ;
72
71
// Re-add delay to help find socket input consumption bugs more consistently
73
72
//await Task.Delay(TimeSpan.FromMilliseconds(5));
74
73
}
75
- await writer . FlushAsync ( ) . ConfigureAwait ( false ) ;
76
- await _stream . FlushAsync ( ) . ConfigureAwait ( false ) ;
77
74
}
78
75
79
76
public async Task < int > ReadCharAsync ( )
Original file line number Diff line number Diff line change @@ -206,13 +206,15 @@ public async Task ReaderThrowsCancelledException()
206
206
[ ConditionalFact ]
207
207
public async Task ReaderThrowsResetExceptionOnInvalidBody ( )
208
208
{
209
+ var requestStartedCompletionSource = CreateTaskCompletionSource ( ) ;
209
210
var requestCompletedCompletionSource = CreateTaskCompletionSource ( ) ;
210
211
211
212
Exception exception = null ;
212
213
213
214
var data = new byte [ 1024 ] ;
214
215
using ( var testServer = await TestServer . Create ( async ctx =>
215
216
{
217
+ requestStartedCompletionSource . SetResult ( true ) ;
216
218
try
217
219
{
218
220
await ctx . Request . Body . ReadAsync ( data ) ;
@@ -233,10 +235,19 @@ await connection.Send(
233
235
"Host: localhost" ,
234
236
"Connection: close" ,
235
237
"" ,
236
- "ZZZ" ,
237
238
"" ) ;
238
- await requestCompletedCompletionSource . Task . DefaultTimeout ( ) ;
239
+
240
+ await requestStartedCompletionSource . Task ;
241
+ await connection . Send (
242
+ "ZZZZZZZZZZZZZ" ) ;
243
+
244
+ await connection . Receive (
245
+ "HTTP/1.1 400 Bad Request" ,
246
+ ""
247
+ ) ;
248
+
239
249
}
250
+ await requestCompletedCompletionSource . Task . DefaultTimeout ( ) ;
240
251
}
241
252
242
253
Assert . IsType < ConnectionResetException > ( exception ) ;
You can’t perform that action at this time.
0 commit comments