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

Commit 25aed6f

Browse files
committed
#274 Reorganize the strong header type extensions. Remove SendAsync extensions.
1 parent d4132d9 commit 25aed6f

File tree

6 files changed

+108
-293
lines changed

6 files changed

+108
-293
lines changed

src/Microsoft.AspNet.Http.Extensions/HeaderDictionaryTypeExtensions.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ public static ResponseHeaders GetTypedHeaders(this HttpResponse response)
2323
return new ResponseHeaders(response.Headers);
2424
}
2525

26-
public static DateTimeOffset? GetDate([NotNull] this IHeaderDictionary headers, [NotNull] string name)
26+
// These are all shared helpers used by both RequestHeaders and ResponseHeaders
27+
28+
internal static DateTimeOffset? GetDate([NotNull] this IHeaderDictionary headers, [NotNull] string name)
2729
{
2830
return headers.Get<DateTimeOffset?>(name);
2931
}
3032

31-
public static void Set([NotNull] this IHeaderDictionary headers, [NotNull] string name, object value)
33+
internal static void Set([NotNull] this IHeaderDictionary headers, [NotNull] string name, object value)
3234
{
3335
if (value == null)
3436
{
@@ -40,7 +42,7 @@ public static void Set([NotNull] this IHeaderDictionary headers, [NotNull] strin
4042
}
4143
}
4244

43-
public static void SetList<T>([NotNull] this IHeaderDictionary headers, [NotNull] string name, IList<T> values)
45+
internal static void SetList<T>([NotNull] this IHeaderDictionary headers, [NotNull] string name, IList<T> values)
4446
{
4547
if (values == null || values.Count == 0)
4648
{
@@ -52,7 +54,7 @@ public static void SetList<T>([NotNull] this IHeaderDictionary headers, [NotNull
5254
}
5355
}
5456

55-
public static void SetDate([NotNull] this IHeaderDictionary headers, [NotNull] string name, DateTimeOffset? value)
57+
internal static void SetDate([NotNull] this IHeaderDictionary headers, [NotNull] string name, DateTimeOffset? value)
5658
{
5759
if (value.HasValue)
5860
{
@@ -64,16 +66,6 @@ public static void SetDate([NotNull] this IHeaderDictionary headers, [NotNull] s
6466
}
6567
}
6668

67-
public static void Append([NotNull] this IHeaderDictionary headers, [NotNull] string name, [NotNull] object value)
68-
{
69-
headers.Append(name, value.ToString());
70-
}
71-
72-
public static void AppendList<T>([NotNull] this IHeaderDictionary headers, [NotNull] string name, [NotNull] IList<T> values)
73-
{
74-
headers.AppendValues(name, values.Select(value => value.ToString()).ToArray());
75-
}
76-
7769
private static IDictionary<Type, object> KnownParsers = new Dictionary<Type, object>()
7870
{
7971
{ typeof(CacheControlHeaderValue), new Func<string, CacheControlHeaderValue>(value => { CacheControlHeaderValue result; return CacheControlHeaderValue.TryParse(value, out result) ? result : null; }) },
@@ -96,7 +88,7 @@ public static void AppendList<T>([NotNull] this IHeaderDictionary headers, [NotN
9688
{ typeof(SetCookieHeaderValue), new Func<IList<string>, IList<SetCookieHeaderValue>>(value => { IList<SetCookieHeaderValue> result; return SetCookieHeaderValue.TryParseList(value, out result) ? result : null; }) },
9789
};
9890

99-
public static T Get<T>([NotNull] this IHeaderDictionary headers, string name)
91+
internal static T Get<T>([NotNull] this IHeaderDictionary headers, string name)
10092
{
10193
object temp;
10294
if (KnownParsers.TryGetValue(typeof(T), out temp))
@@ -114,7 +106,7 @@ public static T Get<T>([NotNull] this IHeaderDictionary headers, string name)
114106
return GetViaReflection<T>(value);
115107
}
116108

117-
public static IList<T> GetList<T>([NotNull] this IHeaderDictionary headers, string name)
109+
internal static IList<T> GetList<T>([NotNull] this IHeaderDictionary headers, string name)
118110
{
119111
object temp;
120112
if (KnownListParsers.TryGetValue(typeof(T), out temp))

src/Microsoft.AspNet.Http.Extensions/HttpResponseSendingExtensions.cs

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

src/Microsoft.AspNet.Http.Extensions/RequestHeaders.cs

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

44
using System;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using Microsoft.Framework.Internal;
78
using Microsoft.Net.Http.Headers;
89

@@ -256,5 +257,35 @@ public RangeHeaderValue Range
256257
Headers.Set(HeaderNames.Range, value);
257258
}
258259
}
260+
261+
public T Get<T>(string name)
262+
{
263+
return Headers.Get<T>(name);
264+
}
265+
266+
public IList<T> GetList<T>(string name)
267+
{
268+
return Headers.GetList<T>(name);
269+
}
270+
271+
public void Set([NotNull] string name, object value)
272+
{
273+
Headers.Set(name, value);
274+
}
275+
276+
public void SetList<T>([NotNull] string name, IList<T> values)
277+
{
278+
Headers.SetList<T>(name, values);
279+
}
280+
281+
public void Append([NotNull] string name, [NotNull] object value)
282+
{
283+
Headers.Append(name, value.ToString());
284+
}
285+
286+
public void AppendList<T>([NotNull] string name, [NotNull] IList<T> values)
287+
{
288+
Headers.AppendValues(name, values.Select(value => value.ToString()).ToArray());
289+
}
259290
}
260291
}

src/Microsoft.AspNet.Http.Extensions/ResponseHeaders.cs

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

44
using System;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using Microsoft.AspNet.Http.Extensions;
78
using Microsoft.Framework.Internal;
89
using Microsoft.Net.Http.Headers;
@@ -153,5 +154,35 @@ public IList<SetCookieHeaderValue> SetCookie
153154
Headers.SetList(HeaderNames.SetCookie, value);
154155
}
155156
}
157+
158+
public T Get<T>(string name)
159+
{
160+
return Headers.Get<T>(name);
161+
}
162+
163+
public IList<T> GetList<T>(string name)
164+
{
165+
return Headers.GetList<T>(name);
166+
}
167+
168+
public void Set([NotNull] string name, object value)
169+
{
170+
Headers.Set(name, value);
171+
}
172+
173+
public void SetList<T>([NotNull] string name, IList<T> values)
174+
{
175+
Headers.SetList<T>(name, values);
176+
}
177+
178+
public void Append([NotNull] string name, [NotNull] object value)
179+
{
180+
Headers.Append(name, value.ToString());
181+
}
182+
183+
public void AppendList<T>([NotNull] string name, [NotNull] IList<T> values)
184+
{
185+
Headers.AppendValues(name, values.Select(value => value.ToString()).ToArray());
186+
}
156187
}
157188
}

0 commit comments

Comments
 (0)