@@ -230,6 +230,99 @@ await client.GetAsync(remoteServer.EchoUri, HttpCompletionOption.ResponseHeaders
230230
231231#if NET
232232
233+ public static IEnumerable < object [ ] > HttpMethods => new object [ ] [ ]
234+ {
235+ new [ ] { HttpMethod . Get } ,
236+ new [ ] { HttpMethod . Head } ,
237+ new [ ] { HttpMethod . Post } ,
238+ new [ ] { HttpMethod . Put } ,
239+ new [ ] { HttpMethod . Delete } ,
240+ new [ ] { HttpMethod . Options } ,
241+ new [ ] { HttpMethod . Patch } ,
242+ } ;
243+
244+ public static IEnumerable < object [ ] > HttpMethodsAndAbort => new object [ ] [ ]
245+ {
246+ new object [ ] { HttpMethod . Get , "abortBeforeHeaders" } ,
247+ new object [ ] { HttpMethod . Head , "abortBeforeHeaders" } ,
248+ new object [ ] { HttpMethod . Post , "abortBeforeHeaders" } ,
249+ new object [ ] { HttpMethod . Put , "abortBeforeHeaders" } ,
250+ new object [ ] { HttpMethod . Delete , "abortBeforeHeaders" } ,
251+ new object [ ] { HttpMethod . Options , "abortBeforeHeaders" } ,
252+ new object [ ] { HttpMethod . Patch , "abortBeforeHeaders" } ,
253+
254+ new object [ ] { HttpMethod . Get , "abortAfterHeaders" } ,
255+ new object [ ] { HttpMethod . Post , "abortAfterHeaders" } ,
256+ new object [ ] { HttpMethod . Put , "abortAfterHeaders" } ,
257+ new object [ ] { HttpMethod . Delete , "abortAfterHeaders" } ,
258+ new object [ ] { HttpMethod . Options , "abortAfterHeaders" } ,
259+ new object [ ] { HttpMethod . Patch , "abortAfterHeaders" } ,
260+
261+ new object [ ] { HttpMethod . Get , "abortDuringBody" } ,
262+ new object [ ] { HttpMethod . Post , "abortDuringBody" } ,
263+ new object [ ] { HttpMethod . Put , "abortDuringBody" } ,
264+ new object [ ] { HttpMethod . Delete , "abortDuringBody" } ,
265+ new object [ ] { HttpMethod . Options , "abortDuringBody" } ,
266+ new object [ ] { HttpMethod . Patch , "abortDuringBody" } ,
267+
268+ } ;
269+
270+ [ MemberData ( nameof ( HttpMethods ) ) ]
271+ [ ConditionalTheory ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsBrowser ) ) ]
272+ public async Task BrowserHttpHandler_StreamingResponse ( HttpMethod method )
273+ {
274+ var WebAssemblyEnableStreamingResponseKey = new HttpRequestOptionsKey < bool > ( "WebAssemblyEnableStreamingResponse" ) ;
275+
276+ var req = new HttpRequestMessage ( method , Configuration . Http . RemoteHttp11Server . BaseUri + "echo.ashx" ) ;
277+ req . Options . Set ( WebAssemblyEnableStreamingResponseKey , true ) ;
278+
279+ if ( method == HttpMethod . Post )
280+ {
281+ req . Content = new StringContent ( "hello world" ) ;
282+ }
283+
284+ using ( HttpClient client = CreateHttpClientForRemoteServer ( Configuration . Http . RemoteHttp11Server ) )
285+ // we need to switch off Response buffering of default ResponseContentRead option
286+ using ( HttpResponseMessage response = await client . SendAsync ( req , HttpCompletionOption . ResponseHeadersRead ) )
287+ {
288+ using var content = response . Content ;
289+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
290+ Assert . Equal ( typeof ( StreamContent ) , content . GetType ( ) ) ;
291+ Assert . NotEqual ( 0 , content . Headers . ContentLength ) ;
292+ if ( method != HttpMethod . Head )
293+ {
294+ var data = await content . ReadAsByteArrayAsync ( ) ;
295+ Assert . NotEqual ( 0 , data . Length ) ;
296+ }
297+ }
298+ }
299+
300+ [ MemberData ( nameof ( HttpMethodsAndAbort ) ) ]
301+ [ ConditionalTheory ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsBrowser ) ) ]
302+ public async Task BrowserHttpHandler_StreamingResponseAbort ( HttpMethod method , string abort )
303+ {
304+ var WebAssemblyEnableStreamingResponseKey = new HttpRequestOptionsKey < bool > ( "WebAssemblyEnableStreamingResponse" ) ;
305+
306+ var req = new HttpRequestMessage ( method , Configuration . Http . RemoteHttp11Server . BaseUri + "echo.ashx?" + abort + "=true" ) ;
307+ req . Options . Set ( WebAssemblyEnableStreamingResponseKey , true ) ;
308+
309+ if ( method == HttpMethod . Post || method == HttpMethod . Put || method == HttpMethod . Patch )
310+ {
311+ req . Content = new StringContent ( "hello world" ) ;
312+ }
313+
314+ using HttpClient client = CreateHttpClientForRemoteServer ( Configuration . Http . RemoteHttp11Server ) ;
315+ if ( abort == "abortDuringBody" )
316+ {
317+ using var res = await client . SendAsync ( req , HttpCompletionOption . ResponseHeadersRead ) ;
318+ await Assert . ThrowsAsync < HttpRequestException > ( ( ) => res . Content . ReadAsByteArrayAsync ( ) ) ;
319+ }
320+ else
321+ {
322+ await Assert . ThrowsAsync < HttpRequestException > ( ( ) => client . SendAsync ( req , HttpCompletionOption . ResponseHeadersRead ) ) ;
323+ }
324+ }
325+
233326 [ ConditionalFact ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsChromium ) ) ]
234327 public async Task BrowserHttpHandler_Streaming ( )
235328 {
@@ -486,7 +579,7 @@ public async Task BrowserHttpHandler_StreamingRequest_Http1Fails()
486579
487580 [ OuterLoop ]
488581 [ ConditionalFact ( typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsChromium ) ) ]
489- public async Task BrowserHttpHandler_StreamingResponse ( )
582+ public async Task BrowserHttpHandler_StreamingResponseLarge ( )
490583 {
491584 var WebAssemblyEnableStreamingResponseKey = new HttpRequestOptionsKey < bool > ( "WebAssemblyEnableStreamingResponse" ) ;
492585
0 commit comments