@@ -28,8 +28,8 @@ public void should_call_pre_query_string_builder_middleware()
28
28
_counter ++ ;
29
29
await next . Invoke ( ) ;
30
30
} ,
31
- } ;
32
-
31
+ } ;
32
+
33
33
var port = RandomPortFinder . GetRandomPort ( ) ;
34
34
35
35
var fileConfiguration = new FileConfiguration
@@ -73,8 +73,8 @@ public void should_call_authorization_middleware()
73
73
_counter ++ ;
74
74
await next . Invoke ( ) ;
75
75
} ,
76
- } ;
77
-
76
+ } ;
77
+
78
78
var port = RandomPortFinder . GetRandomPort ( ) ;
79
79
80
80
var fileConfiguration = new FileConfiguration
@@ -118,8 +118,8 @@ public void should_call_authentication_middleware()
118
118
_counter ++ ;
119
119
await next . Invoke ( ) ;
120
120
} ,
121
- } ;
122
-
121
+ } ;
122
+
123
123
var port = RandomPortFinder . GetRandomPort ( ) ;
124
124
125
125
var fileConfiguration = new FileConfiguration
@@ -163,8 +163,8 @@ public void should_call_pre_error_middleware()
163
163
_counter ++ ;
164
164
await next . Invoke ( ) ;
165
165
} ,
166
- } ;
167
-
166
+ } ;
167
+
168
168
var port = RandomPortFinder . GetRandomPort ( ) ;
169
169
170
170
var fileConfiguration = new FileConfiguration
@@ -208,8 +208,8 @@ public void should_call_pre_authorization_middleware()
208
208
_counter ++ ;
209
209
await next . Invoke ( ) ;
210
210
} ,
211
- } ;
212
-
211
+ } ;
212
+
213
213
var port = RandomPortFinder . GetRandomPort ( ) ;
214
214
215
215
var fileConfiguration = new FileConfiguration
@@ -253,8 +253,8 @@ public void should_call_pre_http_authentication_middleware()
253
253
_counter ++ ;
254
254
await next . Invoke ( ) ;
255
255
} ,
256
- } ;
257
-
256
+ } ;
257
+
258
258
var port = RandomPortFinder . GetRandomPort ( ) ;
259
259
260
260
var fileConfiguration = new FileConfiguration
@@ -286,8 +286,54 @@ public void should_call_pre_http_authentication_middleware()
286
286
. Then ( x => _steps . ThenTheStatusCodeShouldBe ( HttpStatusCode . OK ) )
287
287
. And ( x => x . ThenTheCounterIs ( 1 ) )
288
288
. BDDfy ( ) ;
289
- }
289
+ }
290
+
291
+ [ Fact ]
292
+ public void should_not_throw_when_pipeline_terminates_early ( )
293
+ {
294
+ var configuration = new OcelotPipelineConfiguration
295
+ {
296
+ PreQueryStringBuilderMiddleware = ( context , next ) =>
297
+ Task . Run ( ( ) =>
298
+ {
299
+ _counter ++ ;
300
+ return ; // do not invoke the rest of the pipeline
301
+ } ) ,
302
+ } ;
303
+
304
+ var port = RandomPortFinder . GetRandomPort ( ) ;
290
305
306
+ var fileConfiguration = new FileConfiguration
307
+ {
308
+ Routes = new List < FileRoute >
309
+ {
310
+ new ( )
311
+ {
312
+ DownstreamPathTemplate = "/" ,
313
+ DownstreamHostAndPorts = new List < FileHostAndPort >
314
+ {
315
+ new ( )
316
+ {
317
+ Host = "localhost" ,
318
+ Port = port ,
319
+ } ,
320
+ } ,
321
+ DownstreamScheme = "http" ,
322
+ UpstreamPathTemplate = "/" ,
323
+ UpstreamHttpMethod = new List < string > { "Get" } ,
324
+ } ,
325
+ } ,
326
+ } ;
327
+
328
+ this . Given ( x => x . GivenThereIsAServiceRunningOn ( $ "http://localhost:{ port } ", 200 , "" ) )
329
+ . And ( x => _steps . GivenThereIsAConfiguration ( fileConfiguration ) )
330
+ . And ( x => _steps . GivenOcelotIsRunning ( configuration ) )
331
+ . When ( x => _steps . WhenIGetUrlOnTheApiGateway ( "/" ) )
332
+ . Then ( x => _steps . ThenTheStatusCodeShouldBe ( HttpStatusCode . OK ) )
333
+ . And ( x => x . ThenTheCounterIs ( 1 ) )
334
+ . BDDfy ( ) ;
335
+ }
336
+
291
337
[ Fact ( Skip = "This is just an example to show how you could hook into Ocelot pipeline with your own middleware. At the moment you must use Response.OnCompleted callback and cannot change the response :( I will see if this can be changed one day!" ) ]
292
338
public void should_fix_issue_237 ( )
293
339
{
@@ -296,14 +342,14 @@ public void should_fix_issue_237()
296
342
var httpContext = ( HttpContext ) state ;
297
343
298
344
if ( httpContext . Response . StatusCode > 400 )
299
- {
345
+ {
300
346
Debug . WriteLine ( "COUNT CALLED" ) ;
301
347
Console . WriteLine ( "COUNT CALLED" ) ;
302
348
}
303
349
304
350
return Task . CompletedTask ;
305
- } ;
306
-
351
+ } ;
352
+
307
353
var port = RandomPortFinder . GetRandomPort ( ) ;
308
354
309
355
var fileConfiguration = new FileConfiguration
@@ -367,8 +413,8 @@ public void Dispose()
367
413
public class FakeMiddleware
368
414
{
369
415
private readonly RequestDelegate _next ;
370
- private readonly Func < object , Task > _callback ;
371
-
416
+ private readonly Func < object , Task > _callback ;
417
+
372
418
public FakeMiddleware ( RequestDelegate next , Func < object , Task > callback )
373
419
{
374
420
_next = next ;
@@ -377,10 +423,10 @@ public FakeMiddleware(RequestDelegate next, Func<object, Task> callback)
377
423
378
424
public async Task Invoke ( HttpContext context )
379
425
{
380
- await _next ( context ) ;
381
-
426
+ await _next ( context ) ;
427
+
382
428
context . Response . OnCompleted ( _callback , context ) ;
383
429
}
384
430
}
385
431
}
386
- }
432
+ }
0 commit comments