Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 2ae3a24

Browse files
committed
Remove CallCancelled property. Fix Owin query string. Add Owin user. Add Owin tests.
1 parent cd906e3 commit 2ae3a24

File tree

4 files changed

+145
-209
lines changed

4 files changed

+145
-209
lines changed

src/Microsoft.AspNet.Http/HttpRequest.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,5 @@ public abstract class HttpRequest
120120
/// </summary>
121121
/// <returns>The owin.RequestBody Stream.</returns>
122122
public abstract Stream Body { get; set; }
123-
124-
/// <summary>
125-
/// Gets or sets the cancellation token for the request.
126-
/// </summary>
127-
/// <returns>The cancellation token for the request.</returns>
128-
public abstract CancellationToken CallCanceled { get; set; }
129-
130123
}
131124
}

src/Microsoft.AspNet.Owin/OwinEnvironment.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
using System.IO;
99
using System.Linq;
1010
using System.Net;
11+
using System.Security.Claims;
1112
using System.Security.Cryptography.X509Certificates;
13+
using System.Security.Principal;
1214
using System.Threading;
1315
using System.Threading.Tasks;
1416
using Microsoft.AspNet.Http;
1517
using Microsoft.AspNet.HttpFeature;
18+
using Microsoft.AspNet.HttpFeature.Security;
1619

1720
namespace Microsoft.AspNet.Owin
1821
{
@@ -28,12 +31,14 @@ public OwinEnvironment(HttpContext context)
2831
_context = context;
2932
_entries = new Dictionary<string, FeatureMap>()
3033
{
34+
{ OwinConstants.CallCancelled, new FeatureMap<IHttpRequestLifetimeFeature>(feature => feature.OnRequestAborted) },
3135
{ OwinConstants.RequestProtocol, new FeatureMap<IHttpRequestFeature>(feature => feature.Protocol, (feature, value) => feature.Protocol = Convert.ToString(value)) },
3236
{ OwinConstants.RequestScheme, new FeatureMap<IHttpRequestFeature>(feature => feature.Scheme, (feature, value) => feature.Scheme = Convert.ToString(value)) },
3337
{ OwinConstants.RequestMethod, new FeatureMap<IHttpRequestFeature>(feature => feature.Method, (feature, value) => feature.Method = Convert.ToString(value)) },
3438
{ OwinConstants.RequestPathBase, new FeatureMap<IHttpRequestFeature>(feature => feature.PathBase, (feature, value) => feature.PathBase = Convert.ToString(value)) },
3539
{ OwinConstants.RequestPath, new FeatureMap<IHttpRequestFeature>(feature => feature.Path, (feature, value) => feature.Path = Convert.ToString(value)) },
36-
{ OwinConstants.RequestQueryString, new FeatureMap<IHttpRequestFeature>(feature => feature.QueryString, (feature, value) => feature.QueryString = Convert.ToString(value)) },
40+
{ OwinConstants.RequestQueryString, new FeatureMap<IHttpRequestFeature>(feature => RemoveQuestionMark(feature.QueryString),
41+
(feature, value) => feature.QueryString = AddQuestionMark(Convert.ToString(value))) },
3742
{ OwinConstants.RequestHeaders, new FeatureMap<IHttpRequestFeature>(feature => feature.Headers, (feature, value) => feature.Headers = (IDictionary<string, string[]>)value) },
3843
{ OwinConstants.RequestBody, new FeatureMap<IHttpRequestFeature>(feature => feature.Body, (feature, value) => feature.Body = (Stream)value) },
3944

@@ -56,6 +61,8 @@ public OwinEnvironment(HttpContext context)
5661
{ OwinConstants.CommonKeys.IsLocal, new FeatureMap<IHttpConnectionFeature>(feature => feature.IsLocal, (feature, value) => feature.IsLocal = Convert.ToBoolean(value)) },
5762

5863
{ OwinConstants.SendFiles.SendAsync, new FeatureMap<IHttpSendFileFeature>(feature => new SendFileFunc(feature.SendFileAsync)) },
64+
65+
{ OwinConstants.Security.User, new FeatureMap<IHttpAuthenticationFeature>(feature => feature.User, (feature, value) => feature.User = MakeClaimsPrincipal((IPrincipal)value)) },
5966
};
6067

6168
if (context.Request.IsSecure)
@@ -222,6 +229,36 @@ IEnumerator IEnumerable.GetEnumerator()
222229
throw new NotImplementedException();
223230
}
224231

232+
private string RemoveQuestionMark(string queryString)
233+
{
234+
if (!string.IsNullOrEmpty(queryString))
235+
{
236+
if (queryString[0] == '?')
237+
{
238+
return queryString.Substring(1);
239+
}
240+
}
241+
return queryString;
242+
}
243+
244+
private string AddQuestionMark(string queryString)
245+
{
246+
if (!string.IsNullOrEmpty(queryString))
247+
{
248+
return '?' + queryString;
249+
}
250+
return queryString;
251+
}
252+
253+
private ClaimsPrincipal MakeClaimsPrincipal(IPrincipal principal)
254+
{
255+
if (principal is ClaimsPrincipal)
256+
{
257+
return principal as ClaimsPrincipal;
258+
}
259+
return new ClaimsPrincipal(principal);
260+
}
261+
225262
public class FeatureMap
226263
{
227264
public FeatureMap(Type featureInterface, Func<object, object> getter)

src/Microsoft.AspNet.PipelineCore/DefaultHttpRequest.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,5 @@ public override IReadableStringCollection Cookies
149149
{
150150
get { return RequestCookiesFeature.Cookies; }
151151
}
152-
153-
public override System.Threading.CancellationToken CallCanceled
154-
{
155-
get
156-
{
157-
// TODO: Which feature exposes this?
158-
return CancellationToken.None;
159-
}
160-
set
161-
{
162-
throw new NotImplementedException();
163-
}
164-
}
165152
}
166153
}

0 commit comments

Comments
 (0)