Skip to content

Commit 554c0c5

Browse files
authored
Add docs for Microsoft.AspNetCore.Http (#28867)
* Microsoft.AspNetCore.Http * Microsoft.AspNetCore.Http.Extensions * Microsoft.AspNetCore.Http.Features
1 parent 0db9bfb commit 554c0c5

File tree

62 files changed

+877
-124
lines changed

Some content is hidden

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

62 files changed

+877
-124
lines changed

src/Http/Http.Extensions/src/HeaderDictionaryTypeExtensions.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,27 @@
1212

1313
namespace Microsoft.AspNetCore.Http
1414
{
15+
/// <summary>
16+
/// Extension methods for accessing strongly typed HTTP request and response
17+
/// headers.
18+
/// </summary>
1519
public static class HeaderDictionaryTypeExtensions
1620
{
21+
/// <summary>
22+
/// Gets strongly typed HTTP request headers.
23+
/// </summary>
24+
/// <param name="request">The <see cref="HttpRequest"/>.</param>
25+
/// <returns>The <see cref="RequestHeaders"/>.</returns>
1726
public static RequestHeaders GetTypedHeaders(this HttpRequest request)
1827
{
1928
return new RequestHeaders(request.Headers);
2029
}
2130

31+
/// <summary>
32+
/// Gets strongly typed HTTP response headers.
33+
/// </summary>
34+
/// <param name="response">The <see cref="HttpResponse"/>.</param>
35+
/// <returns>The <see cref="ResponseHeaders"/>.</returns>
2236
public static ResponseHeaders GetTypedHeaders(this HttpResponse response)
2337
{
2438
return new ResponseHeaders(response.Headers);
@@ -94,6 +108,13 @@ internal static void SetList<T>(this IHeaderDictionary headers, string name, ILi
94108
}
95109
}
96110

111+
/// <summary>
112+
/// Appends a sequence of values to <see cref="IHeaderDictionary"/>.
113+
/// </summary>
114+
/// <typeparam name="T">The type of header value.</typeparam>
115+
/// <param name="Headers">The <see cref="IHeaderDictionary"/>.</param>
116+
/// <param name="name">The header name.</param>
117+
/// <param name="values">The values to append.</param>
97118
public static void AppendList<T>(this IHeaderDictionary Headers, string name, IList<T> values)
98119
{
99120
if (name == null)
@@ -246,7 +267,7 @@ internal static IList<T> GetList<T>(this IHeaderDictionary headers, string name)
246267
var success = (bool)method.Invoke(null, parameters)!;
247268
if (success)
248269
{
249-
return (T)parameters[1];
270+
return (T?)parameters[1];
250271
}
251272
return default(T);
252273
}

src/Http/Http.Extensions/src/HttpContextServerVariableExtensions.cs

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

66
namespace Microsoft.AspNetCore.Http
77
{
8+
/// <summary>
9+
/// Extensions for reading HTTP server variables.
10+
/// </summary>
811
public static class HttpContextServerVariableExtensions
912
{
1013
/// <summary>

src/Http/Http.Extensions/src/HttpRequestJsonExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
using Microsoft.Extensions.Primitives;
1515
using Microsoft.Net.Http.Headers;
1616

17-
#nullable enable
18-
1917
namespace Microsoft.AspNetCore.Http
2018
{
19+
/// <summary>
20+
/// Extension methods to read the request body as JSON.
21+
/// </summary>
2122
public static class HttpRequestJsonExtensions
2223
{
2324
/// <summary>

src/Http/Http.Extensions/src/HttpRequestMultipartExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@
66

77
namespace Microsoft.AspNetCore.Http.Extensions
88
{
9+
/// <summary>
10+
/// Extension methods for working with multipart form requests.
11+
/// </summary>
912
public static class HttpRequestMultipartExtensions
1013
{
14+
/// <summary>
15+
/// Gets the mutipart boundary from the <c>Content-Type</c> header.
16+
/// </summary>
17+
/// <param name="request">The <see cref="HttpRequest"/>.</param>
18+
/// <returns>The multipart boundary.</returns>
1119
public static string GetMultipartBoundary(this HttpRequest request)
1220
{
1321
if (request == null)

src/Http/Http.Extensions/src/HttpResponseJsonExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
using Microsoft.Extensions.DependencyInjection;
1111
using Microsoft.Extensions.Options;
1212

13-
#nullable enable
14-
1513
namespace Microsoft.AspNetCore.Http
1614
{
15+
/// <summary>
16+
/// Provides extension methods for writing a JSON serialized value to the HTTP response.
17+
/// </summary>
1718
public static partial class HttpResponseJsonExtensions
1819
{
1920
/// <summary>

src/Http/Http.Extensions/src/JsonOptions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
namespace Microsoft.AspNetCore.Http.Json
1010
{
11+
/// <summary>
12+
/// Options to configure JSON serialization settings for <see cref="HttpRequestJsonExtensions"/>
13+
/// and <see cref="HttpResponseJsonExtensions"/>.
14+
/// </summary>
1115
public class JsonOptions
1216
{
1317
internal static readonly JsonSerializerOptions DefaultSerializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web)
@@ -20,6 +24,9 @@ public class JsonOptions
2024
};
2125

2226
// Use a copy so the defaults are not modified.
27+
/// <summary>
28+
/// Gets the <see cref="JsonSerializerOptions"/>.
29+
/// </summary>
2330
public JsonSerializerOptions SerializerOptions { get; } = new JsonSerializerOptions(DefaultSerializerOptions);
2431
}
2532
}

src/Http/Http.Extensions/src/Microsoft.AspNetCore.Http.Extensions.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<Description>ASP.NET Core common extension methods for HTTP abstractions, HTTP headers, HTTP request/response, and session state.</Description>
55
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
66
<IsAspNetCoreApp>true</IsAspNetCoreApp>
7-
<NoWarn>$(NoWarn);CS1591</NoWarn>
87
<GenerateDocumentationFile>true</GenerateDocumentationFile>
98
<PackageTags>aspnetcore</PackageTags>
109
<IsPackable>false</IsPackable>

src/Http/Http.Extensions/src/QueryBuilder.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,45 @@
1111
namespace Microsoft.AspNetCore.Http.Extensions
1212
{
1313
// The IEnumerable interface is required for the collection initialization syntax: new QueryBuilder() { { "key", "value" } };
14+
/// <summary>
15+
/// Allows constructing a query string.
16+
/// </summary>
1417
public class QueryBuilder : IEnumerable<KeyValuePair<string, string>>
1518
{
1619
private IList<KeyValuePair<string, string>> _params;
1720

21+
/// <summary>
22+
/// Initializes a new instance of <see cref="QueryBuilder"/>.
23+
/// </summary>
1824
public QueryBuilder()
1925
{
2026
_params = new List<KeyValuePair<string, string>>();
2127
}
2228

29+
/// <summary>
30+
/// Initializes a new instance of <see cref="QueryBuilder"/>.
31+
/// </summary>
32+
/// <param name="parameters">The parameters to initialize the instance with.</param>
2333
public QueryBuilder(IEnumerable<KeyValuePair<string, string>> parameters)
2434
{
2535
_params = new List<KeyValuePair<string, string>>(parameters);
2636
}
2737

38+
/// <summary>
39+
/// Initializes a new instance of <see cref="QueryBuilder"/>.
40+
/// </summary>
41+
/// <param name="parameters">The parameters to initialize the instance with.</param>
2842
public QueryBuilder(IEnumerable<KeyValuePair<string, StringValues>> parameters)
2943
: this(parameters.SelectMany(kvp => kvp.Value, (kvp, v) => KeyValuePair.Create(kvp.Key, v)))
3044
{
3145

3246
}
3347

48+
/// <summary>
49+
/// Adds a query string token to the instance.
50+
/// </summary>
51+
/// <param name="key">The query key.</param>
52+
/// <param name="values">The sequence of query values.</param>
3453
public void Add(string key, IEnumerable<string> values)
3554
{
3655
foreach (var value in values)
@@ -39,43 +58,56 @@ public void Add(string key, IEnumerable<string> values)
3958
}
4059
}
4160

61+
/// <summary>
62+
/// Adds a query string token to the instance.
63+
/// </summary>
64+
/// <param name="key">The query key.</param>
65+
/// <param name="value">The query value.</param>
4266
public void Add(string key, string value)
4367
{
4468
_params.Add(new KeyValuePair<string, string>(key, value));
4569
}
4670

71+
/// <inheritdoc/>
4772
public override string ToString()
4873
{
4974
var builder = new StringBuilder();
5075
bool first = true;
51-
for (int i = 0; i < _params.Count; i++)
76+
for (var i = 0; i < _params.Count; i++)
5277
{
5378
var pair = _params[i];
54-
builder.Append(first ? "?" : "&");
79+
builder.Append(first ? '?' : '&');
5580
first = false;
5681
builder.Append(UrlEncoder.Default.Encode(pair.Key));
57-
builder.Append("=");
82+
builder.Append('=');
5883
builder.Append(UrlEncoder.Default.Encode(pair.Value));
5984
}
6085

6186
return builder.ToString();
6287
}
6388

89+
/// <summary>
90+
/// Constructs a <see cref="QueryString"/> from this <see cref="QueryBuilder"/>.
91+
/// </summary>
92+
/// <returns>The <see cref="QueryString"/>.</returns>
6493
public QueryString ToQueryString()
6594
{
6695
return new QueryString(ToString());
6796
}
6897

98+
/// <inheritdoc/>
6999
public override int GetHashCode()
70100
{
71101
return ToQueryString().GetHashCode();
72102
}
73103

104+
/// <inheritdoc/>
74105
public override bool Equals(object? obj)
75106
{
76107
return ToQueryString().Equals(obj);
77108
}
78109

110+
/// <inheritdoc/>
79111
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
80112
{
81113
return _params.GetEnumerator();

0 commit comments

Comments
 (0)