Add Referer to GetTypedHeaders (#949)

* Add a Referer property

* Add Uri to KnownParsers

* Add property for Origin

* Add Origin

* Encode the URI

From feedback from Tratcher

* Inline the var 'out' declaration

* Remove Origin

Since it does not cleanly map to a Uri object since it can contain multiple values.

* Took back that whitespace

* Reverted

* Add using for UriHelper.Encode
This commit is contained in:
Jonathan 2017-10-12 20:00:23 +02:00 committed by Chris Ross
parent 01b4530fa7
commit 75a7552360
2 changed files with 20 additions and 2 deletions

View File

@ -284,4 +284,4 @@ namespace Microsoft.AspNetCore.Http
return null;
}
}
}
}

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.Http.Headers
@ -261,6 +262,23 @@ namespace Microsoft.AspNetCore.Http.Headers
}
}
public Uri Referer
{
get
{
Uri uri;
if (Uri.TryCreate(Headers[HeaderNames.Referer], UriKind.RelativeOrAbsolute, out uri))
{
return uri;
}
return null;
}
set
{
Headers.Set(HeaderNames.Referer, value == null ? null : UriHelper.Encode(value));
}
}
public T Get<T>(string name)
{
return Headers.Get<T>(name);
@ -311,4 +329,4 @@ namespace Microsoft.AspNetCore.Http.Headers
Headers.AppendList<T>(name, values);
}
}
}
}