-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimeoutMiddleware.cs
More file actions
29 lines (27 loc) · 879 Bytes
/
TimeoutMiddleware.cs
File metadata and controls
29 lines (27 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using Microsoft.AspNetCore.Http;
using System.Linq;
using System.Threading.Tasks;
namespace Https.Tests
{
class TimeoutMiddleware
{
readonly RequestDelegate _next;
public TimeoutMiddleware(RequestDelegate next) =>
_next = next;
public async Task InvokeAsync(HttpContext context)
{
if (context.Request.Path.StartsWithSegments("/Timeout") &&
context.Request.Query.TryGetValue("delay", out var delayValues) &&
int.TryParse(delayValues.FirstOrDefault(), out var delay))
{
await Task.Delay(delay);
context.Response.StatusCode = StatusCodes.Status200OK;
await context.Response.WriteAsync("Ignore this");
}
else
{
await _next(context);
}
}
}
}