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

Commit e320755

Browse files
authored
Do not run custom header parsers on null header values (#678)
1 parent 6c56f1d commit e320755

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,19 @@ internal static T Get<T>(this IHeaderDictionary headers, string name)
176176
}
177177

178178
object temp;
179-
if (KnownParsers.TryGetValue(typeof(T), out temp))
180-
{
181-
var func = (Func<string, T>)temp;
182-
return func(headers[name]);
183-
}
184-
185179
var value = headers[name];
180+
186181
if (StringValues.IsNullOrEmpty(value))
187182
{
188183
return default(T);
189184
}
190185

186+
if (KnownParsers.TryGetValue(typeof(T), out temp))
187+
{
188+
var func = (Func<string, T>)temp;
189+
return func(value);
190+
}
191+
191192
return GetViaReflection<T>(value.ToString());
192193
}
193194

@@ -199,18 +200,19 @@ internal static IList<T> GetList<T>(this IHeaderDictionary headers, string name)
199200
}
200201

201202
object temp;
202-
if (KnownListParsers.TryGetValue(typeof(T), out temp))
203-
{
204-
var func = (Func<IList<string>, IList<T>>)temp;
205-
return func(headers[name]);
206-
}
207-
208203
var values = headers[name];
204+
209205
if (StringValues.IsNullOrEmpty(values))
210206
{
211207
return null;
212208
}
213209

210+
if (KnownListParsers.TryGetValue(typeof(T), out temp))
211+
{
212+
var func = (Func<IList<string>, IList<T>>)temp;
213+
return func(values);
214+
}
215+
214216
return GetListViaReflection<T>(values);
215217
}
216218

0 commit comments

Comments
 (0)