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