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

Commit 3c2e2b9

Browse files
benaadamsTratcher
authored andcommitted
#426 Less alloc/wrapping/boxing for Query, Forms, Cookies
1 parent af0d2e5 commit 3c2e2b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1606
-747
lines changed

src/Microsoft.AspNet.Http.Abstractions/FragmentString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static FragmentString FromUriComponent(Uri uri)
100100
string fragmentValue = uri.GetComponents(UriComponents.Fragment, UriFormat.UriEscaped);
101101
if (!string.IsNullOrEmpty(fragmentValue))
102102
{
103-
fragmentValue = "#" + fragmentValue;
103+
fragmentValue = $"#{fragmentValue}";
104104
}
105105
return new FragmentString(fragmentValue);
106106
}

src/Microsoft.AspNet.Http.Abstractions/HostString.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ public string ToUriComponent()
7070
&& _value.IndexOf(':', index + 1) >= 0)
7171
{
7272
// IPv6 without brackets ::1 is the only type of host with 2 or more colons
73-
return "[" + _value + "]";
73+
return $"[{_value}]";
7474
}
7575
else if (index >= 0)
7676
{
7777
// Has a port
7878
string port = _value.Substring(index);
79-
IdnMapping mapping = new IdnMapping();
79+
var mapping = new IdnMapping();
8080
return mapping.GetAscii(_value, 0, index) + port;
8181
}
8282
else
8383
{
84-
IdnMapping mapping = new IdnMapping();
84+
var mapping = new IdnMapping();
8585
return mapping.GetAscii(_value);
8686
}
8787
}
@@ -115,12 +115,12 @@ public static HostString FromUriComponent(string uriComponent)
115115
{
116116
// Has a port
117117
string port = uriComponent.Substring(index);
118-
IdnMapping mapping = new IdnMapping();
118+
var mapping = new IdnMapping();
119119
uriComponent = mapping.GetUnicode(uriComponent, 0, index) + port;
120120
}
121121
else
122122
{
123-
IdnMapping mapping = new IdnMapping();
123+
var mapping = new IdnMapping();
124124
uriComponent = mapping.GetUnicode(uriComponent);
125125
}
126126
}

src/Microsoft.AspNet.Http.Abstractions/HttpRequest.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public abstract class HttpRequest
2424
public abstract string Method { get; set; }
2525

2626
/// <summary>
27-
/// Gets or set the HTTP request scheme from owin.RequestScheme.
27+
/// Gets or set the HTTP request scheme.
2828
/// </summary>
29-
/// <returns>The HTTP request scheme from owin.RequestScheme.</returns>
29+
/// <returns>The HTTP request scheme.</returns>
3030
public abstract string Scheme { get; set; }
3131

3232
/// <summary>
33-
/// Returns true if the owin.RequestScheme is https.
33+
/// Returns true if the RequestScheme is https.
3434
/// </summary>
3535
/// <returns>true if this request is using https; otherwise, false.</returns>
3636
public abstract bool IsHttps { get; set; }
@@ -42,33 +42,33 @@ public abstract class HttpRequest
4242
public abstract HostString Host { get; set; }
4343

4444
/// <summary>
45-
/// Gets or set the owin.RequestPathBase.
45+
/// Gets or set the RequestPathBase.
4646
/// </summary>
47-
/// <returns>The owin.RequestPathBase.</returns>
47+
/// <returns>The RequestPathBase.</returns>
4848
public abstract PathString PathBase { get; set; }
4949

5050
/// <summary>
51-
/// Gets or set the request path from owin.RequestPath.
51+
/// Gets or set the request path from RequestPath.
5252
/// </summary>
53-
/// <returns>The request path from owin.RequestPath.</returns>
53+
/// <returns>The request path from RequestPath.</returns>
5454
public abstract PathString Path { get; set; }
5555

5656
/// <summary>
57-
/// Gets or set the query string from owin.RequestQueryString.
57+
/// Gets or set the query string.
5858
/// </summary>
59-
/// <returns>The query string from owin.RequestQueryString.</returns>
59+
/// <returns>The query string.</returns>
6060
public abstract QueryString QueryString { get; set; }
6161

6262
/// <summary>
63-
/// Gets the query value collection parsed from owin.RequestQueryString.
63+
/// Gets the query value collection parsed from RequestQueryString.
6464
/// </summary>
65-
/// <returns>The query value collection parsed from owin.RequestQueryString.</returns>
66-
public abstract IReadableStringCollection Query { get; set; }
65+
/// <returns>The query value collection parsed from RequestQueryString.</returns>
66+
public abstract IQueryCollection Query { get; set; }
6767

6868
/// <summary>
69-
/// Gets or set the owin.RequestProtocol.
69+
/// Gets or set the RequestProtocol.
7070
/// </summary>
71-
/// <returns>The owin.RequestProtocol.</returns>
71+
/// <returns>The RequestProtocol.</returns>
7272
public abstract string Protocol { get; set; }
7373

7474
/// <summary>
@@ -81,7 +81,7 @@ public abstract class HttpRequest
8181
/// Gets the collection of Cookies for this request.
8282
/// </summary>
8383
/// <returns>The collection of Cookies for this request.</returns>
84-
public abstract IReadableStringCollection Cookies { get; set; }
84+
public abstract IRequestCookieCollection Cookies { get; set; }
8585

8686
/// <summary>
8787
/// Gets or sets the Content-Length header
@@ -95,9 +95,9 @@ public abstract class HttpRequest
9595
public abstract string ContentType { get; set; }
9696

9797
/// <summary>
98-
/// Gets or set the owin.RequestBody Stream.
98+
/// Gets or set the RequestBody Stream.
9999
/// </summary>
100-
/// <returns>The owin.RequestBody Stream.</returns>
100+
/// <returns>The RequestBody Stream.</returns>
101101
public abstract Stream Body { get; set; }
102102

103103
/// <summary>
Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,95 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System.Collections.Generic;
5+
using Microsoft.Extensions.Primitives;
6+
47
namespace Microsoft.AspNet.Http
58
{
69
/// <summary>
7-
/// Contains the parsed form values.
10+
/// Represents the parsed form values sent with the HttpRequest.
811
/// </summary>
9-
public interface IFormCollection : IReadableStringCollection
12+
public interface IFormCollection : IEnumerable<KeyValuePair<string, StringValues>>
1013
{
14+
/// <summary>
15+
/// Gets the number of elements contained in the <see cref="T:Microsoft.AspNet.Http.IFormCollection" />.
16+
/// </summary>
17+
/// <returns>
18+
/// The number of elements contained in the <see cref="T:Microsoft.AspNet.Http.IFormCollection" />.
19+
/// </returns>
20+
int Count { get; }
21+
22+
/// <summary>
23+
/// Gets an <see cref="T:System.Collections.Generic.ICollection`1" /> containing the keys of the
24+
/// <see cref="T:Microsoft.AspNet.Http.IFormCollection" />.
25+
/// </summary>
26+
/// <returns>
27+
/// An <see cref="T:System.Collections.Generic.ICollection`1" /> containing the keys of the object
28+
/// that implements <see cref="T:Microsoft.AspNet.Http.IFormCollection" />.
29+
/// </returns>
30+
ICollection<string> Keys { get; }
31+
32+
/// <summary>
33+
/// Determines whether the <see cref="T:Microsoft.AspNet.Http.IFormCollection" /> contains an element
34+
/// with the specified key.
35+
/// </summary>
36+
/// <param name="key">
37+
/// The key to locate in the <see cref="T:Microsoft.AspNet.Http.IFormCollection" />.
38+
/// </param>
39+
/// <returns>
40+
/// true if the <see cref="T:Microsoft.AspNet.Http.IFormCollection" /> contains an element with
41+
/// the key; otherwise, false.
42+
/// </returns>
43+
/// <exception cref="T:System.ArgumentNullException">
44+
/// key is null.
45+
/// </exception>
46+
bool ContainsKey(string key);
47+
48+
/// <summary>
49+
/// Gets the value associated with the specified key.
50+
/// </summary>
51+
/// <param name="key">
52+
/// The key of the value to get.
53+
/// </param>
54+
/// <param name="value">
55+
/// The key of the value to get.
56+
/// When this method returns, the value associated with the specified key, if the
57+
/// key is found; otherwise, the default value for the type of the value parameter.
58+
/// This parameter is passed uninitialized.
59+
/// </param>
60+
/// <returns>
61+
/// true if the object that implements <see cref="T:Microsoft.AspNet.Http.IFormCollection" /> contains
62+
/// an element with the specified key; otherwise, false.
63+
/// </returns>
64+
/// <exception cref="T:System.ArgumentNullException">
65+
/// key is null.
66+
/// </exception>
67+
bool TryGetValue(string key, out StringValues value);
68+
69+
/// <summary>
70+
/// Gets the value with the specified key.
71+
/// </summary>
72+
/// <param name="key">
73+
/// The key of the value to get.
74+
/// </param>
75+
/// <returns>
76+
/// The element with the specified key, or <see cref="T:Microsoft.Extensions.Primitives.StringValues" />.Empty if the key is not present.
77+
/// </returns>
78+
/// <exception cref="T:System.ArgumentNullException">
79+
/// key is null.
80+
/// </exception>
81+
/// <remarks>
82+
/// <see cref="T:Microsoft.AspNet.Http.IFormCollection" /> has a different indexer contract than
83+
/// <see cref="T:System.Collections.Generic.IDictionary`2" />, as it will return StringValues.Empty for missing entries
84+
/// rather than throwing an Exception.
85+
/// </remarks>
86+
StringValues this[string key] { get; }
87+
88+
/// <summary>
89+
/// The file collection sent with the request.
90+
/// </summary>
91+
/// <param name="key"></param>
92+
/// <returns>The files included with the request.</returns>
1193
IFormFileCollection Files { get; }
1294
}
1395
}

src/Microsoft.AspNet.Http.Abstractions/IFormFile.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace Microsoft.AspNet.Http
77
{
8+
/// <summary>
9+
/// Represents a file sent with the HttpRequest.
10+
/// </summary>
811
public interface IFormFile
912
{
1013
string ContentType { get; }

src/Microsoft.AspNet.Http.Abstractions/IFormFileCollection.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace Microsoft.AspNet.Http
77
{
8+
/// <summary>
9+
/// Represents the collection of files sent with the HttpRequest.
10+
/// </summary>
811
public interface IFormFileCollection : IReadOnlyList<IFormFile>
912
{
1013
IFormFile this[string name] { get; }
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
using Microsoft.Extensions.Primitives;
6+
7+
namespace Microsoft.AspNet.Http
8+
{
9+
/// <summary>
10+
/// Represents the HttpRequest query string collection
11+
/// </summary>
12+
public interface IQueryCollection : IEnumerable<KeyValuePair<string, StringValues>>
13+
{
14+
/// <summary>
15+
/// Gets the number of elements contained in the <see cref="T:Microsoft.AspNet.Http.IQueryCollection" />.
16+
/// </summary>
17+
/// <returns>
18+
/// The number of elements contained in the <see cref="T:Microsoft.AspNet.Http.IQueryCollection" />.
19+
/// </returns>
20+
int Count { get; }
21+
22+
/// <summary>
23+
/// Gets an <see cref="T:System.Collections.Generic.ICollection`1" /> containing the keys of the
24+
/// <see cref="T:Microsoft.AspNet.Http.IQueryCollection" />.
25+
/// </summary>
26+
/// <returns>
27+
/// An <see cref="T:System.Collections.Generic.ICollection`1" /> containing the keys of the object
28+
/// that implements <see cref="T:Microsoft.AspNet.Http.IQueryCollection" />.
29+
/// </returns>
30+
ICollection<string> Keys { get; }
31+
32+
/// <summary>
33+
/// Determines whether the <see cref="T:Microsoft.AspNet.Http.IQueryCollection" /> contains an element
34+
/// with the specified key.
35+
/// </summary>
36+
/// <param name="key">
37+
/// The key to locate in the <see cref="T:Microsoft.AspNet.Http.IQueryCollection" />.
38+
/// </param>
39+
/// <returns>
40+
/// true if the <see cref="T:Microsoft.AspNet.Http.IQueryCollection" /> contains an element with
41+
/// the key; otherwise, false.
42+
/// </returns>
43+
/// <exception cref="T:System.ArgumentNullException">
44+
/// key is null.
45+
/// </exception>
46+
bool ContainsKey(string key);
47+
48+
/// <summary>
49+
/// Gets the value associated with the specified key.
50+
/// </summary>
51+
/// <param name="key">
52+
/// The key of the value to get.
53+
/// </param>
54+
/// <param name="value">
55+
/// The key of the value to get.
56+
/// When this method returns, the value associated with the specified key, if the
57+
/// key is found; otherwise, the default value for the type of the value parameter.
58+
/// This parameter is passed uninitialized.
59+
/// </param>
60+
/// <returns>
61+
/// true if the object that implements <see cref="T:Microsoft.AspNet.Http.IQueryCollection" /> contains
62+
/// an element with the specified key; otherwise, false.
63+
/// </returns>
64+
/// <exception cref="T:System.ArgumentNullException">
65+
/// key is null.
66+
/// </exception>
67+
bool TryGetValue(string key, out StringValues value);
68+
69+
/// <summary>
70+
/// Gets the value with the specified key.
71+
/// </summary>
72+
/// <param name="key">
73+
/// The key of the value to get.
74+
/// </param>
75+
/// <returns>
76+
/// The element with the specified key, or <see cref="T:Microsoft.Extensions.Primitives.StringValues" />.Empty if the key is not present.
77+
/// </returns>
78+
/// <exception cref="T:System.ArgumentNullException">
79+
/// key is null.
80+
/// </exception>
81+
/// <remarks>
82+
/// <see cref="T:Microsoft.AspNet.Http.IQueryCollection" /> has a different indexer contract than
83+
/// <see cref="T:System.Collections.Generic.IDictionary`2" />, as it will return StringValues.Empty for missing entries
84+
/// rather than throwing an Exception.
85+
/// </remarks>
86+
StringValues this[string key] { get; }
87+
}
88+
}

src/Microsoft.AspNet.Http.Abstractions/IReadableStringCollection.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)