Skip to content

Commit 3d1be94

Browse files
committed
Add IRequest.RequestAborted
1 parent b633182 commit 3d1be94

File tree

10 files changed

+27
-0
lines changed

10 files changed

+27
-0
lines changed

ServiceStack/src/ServiceStack.Extensions/Grpc/GrpcRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Net;
66
using System.Security.Claims;
7+
using System.Threading;
78
using System.Threading.Tasks;
89
using Grpc.Core;
910
using Microsoft.Extensions.DependencyInjection;
@@ -155,6 +156,8 @@ public string GetHeader(string headerName)
155156

156157
public IRequestPreferences RequestPreferences => requestPreferences ??= new RequestPreferences(this);
157158

159+
public CancellationToken RequestAborted => Context.CancellationToken;
160+
158161
public string ContentType { get; set; }
159162

160163
public bool IsLocal { get; private set; }

ServiceStack/src/ServiceStack.Interfaces/Web/IRequest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Collections.Specialized;
77
using System.IO;
8+
using System.Threading;
89
using System.Threading.Tasks;
910
using ServiceStack.Configuration;
1011

@@ -180,4 +181,9 @@ public interface IRequest : IResolver, IServiceProvider
180181
/// The value of the Referrer, null if not available
181182
/// </summary>
182183
Uri UrlReferrer { get; }
184+
185+
/// <summary>
186+
/// Notifies when the connection underlying this request is aborted and thus request operations should be cancelled.
187+
/// </summary>
188+
CancellationToken RequestAborted { get; }
183189
}

ServiceStack/src/ServiceStack/Host/AspNet/AspNetRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22

33
using System.Security.Claims;
4+
using System.Threading;
45
using System.Threading.Tasks;
56
#if !NETCORE
67

@@ -78,6 +79,8 @@ public AspNetRequest(HttpContextBase httpContext, string operationName, RequestA
7879

7980
public IHttpResponse HttpResponse => response;
8081

82+
public CancellationToken RequestAborted => CancellationToken.None;
83+
8184
public ClaimsPrincipal User => request.RequestContext?.HttpContext.User as ClaimsPrincipal;
8285

8386
public RequestAttributes RequestAttributes { get; set; }

ServiceStack/src/ServiceStack/Host/BasicHttpRequest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Net;
4+
using System.Threading;
45
using ServiceStack.Web;
56

67
namespace ServiceStack.Host;

ServiceStack/src/ServiceStack/Host/BasicRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Net;
66
using System.Security.Claims;
7+
using System.Threading;
78
using System.Threading.Tasks;
89
using ServiceStack.Configuration;
910
using ServiceStack.IO;
@@ -22,6 +23,7 @@ public class BasicRequest : IRequest, IHasResolver, IHasVirtualFiles, IHasClaims
2223
public IMessage Message { get; set; }
2324
public object OriginalRequest { get; protected set; }
2425
public IResponse Response { get; set; }
26+
public CancellationToken RequestAborted => CancellationToken.None;
2527

2628
#if NETCORE
2729
public Microsoft.Extensions.DependencyInjection.IServiceScope ServiceScope { get; set; }

ServiceStack/src/ServiceStack/Host/HttpListener/ListenerRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22

33
using System.Security.Claims;
4+
using System.Threading;
45
using System.Threading.Tasks;
56
#if !NETCORE
67

@@ -76,6 +77,8 @@ private string GetPathInfo()
7677

7778
public IHttpResponse HttpResponse => response;
7879

80+
public CancellationToken RequestAborted => CancellationToken.None;
81+
7982
public ClaimsPrincipal User => httpContext.User as ClaimsPrincipal;
8083
public RequestAttributes RequestAttributes { get; set; }
8184

ServiceStack/src/ServiceStack/Host/NetCore/NetCoreRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22

33
using System.Security.Claims;
4+
using System.Threading;
45
using System.Threading.Tasks;
56
#if NETCORE
67
using System;
@@ -67,6 +68,7 @@ public T TryResolve<T>()
6768

6869
private IResponse response;
6970
public IResponse Response => response ??= new NetCoreResponse(this, context.Response);
71+
public CancellationToken RequestAborted => context.RequestAborted;
7072

7173
public string OperationName { get; set; }
7274
public string Verb => HttpMethod;

ServiceStack/src/ServiceStack/Testing/MockHttpRequest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Specialized;
44
using System.IO;
55
using System.Net;
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using ServiceStack.Configuration;
89
using ServiceStack.Host;
@@ -56,6 +57,8 @@ public MockHttpRequest(string operationName, string httpMethod,
5657

5758
public IResponse Response { get; }
5859

60+
public CancellationToken RequestAborted => CancellationToken.None;
61+
5962
public T TryResolve<T>()
6063
{
6164
#if NETCORE

ServiceStack/tests/ServiceStack.ServiceHost.Tests/HttpRequestMock.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Specialized;
44
using System.Linq;
55
using System.Text;
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using ServiceStack.Web;
89

@@ -13,6 +14,7 @@ class HttpRequestMock : IHttpRequest
1314
public object OriginalRequest => throw new NotImplementedException();
1415

1516
public IResponse Response { get; private set; }
17+
public CancellationToken RequestAborted => CancellationToken.None;
1618

1719
public string OperationName { get; set; }
1820

ServiceStack/tests/ServiceStack.ServiceHost.Tests/ServiceStackHandlerUrlTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Linq;
66
using System.Net;
7+
using System.Threading;
78
using System.Threading.Tasks;
89
using NUnit.Framework;
910
using ServiceStack.Text;
@@ -32,6 +33,7 @@ public MockUrlHttpRequest(string mode, string path, string rawUrl)
3233
}
3334

3435
public object OriginalRequest => throw new NotImplementedException();
36+
public CancellationToken RequestAborted => CancellationToken.None;
3537

3638
public IResponse Response { get; private set; }
3739

0 commit comments

Comments
 (0)