Merge branch 'release' of github.com:aspnet/HttpAbstractions into release
This commit is contained in:
commit
c62c2b39c8
|
|
@ -1,21 +1,21 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.21916.0
|
||||
VisualStudioVersion = 14.0.22513.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A5A15F1C-885A-452A-A731-B0173DDBD913}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{F31FF137-390C-49BF-A3BD-7C6ED3597C21}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.PipelineCore", "src\Microsoft.AspNet.PipelineCore\Microsoft.AspNet.PipelineCore.kproj", "{BCF0F967-8753-4438-BD07-AADCA9CE509A}"
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Http.Core", "src\Microsoft.AspNet.Http.Core\Microsoft.AspNet.Http.Core.kproj", "{BCF0F967-8753-4438-BD07-AADCA9CE509A}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Http", "src\Microsoft.AspNet.Http\Microsoft.AspNet.Http.kproj", "{22071333-15BA-4D16-A1D5-4D5B1A83FBDD}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.HttpFeature", "src\Microsoft.AspNet.HttpFeature\Microsoft.AspNet.HttpFeature.kproj", "{D9128247-8F97-48B8-A863-F1F21A029FCE}"
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Http.Interfaces", "src\Microsoft.AspNet.Http.Interfaces\Microsoft.AspNet.Http.Interfaces.kproj", "{D9128247-8F97-48B8-A863-F1F21A029FCE}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.FeatureModel", "src\Microsoft.AspNet.FeatureModel\Microsoft.AspNet.FeatureModel.kproj", "{32A4C918-30EE-41DB-8E26-8A3BB88ED231}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.PipelineCore.Tests", "test\Microsoft.AspNet.PipelineCore.Tests\Microsoft.AspNet.PipelineCore.Tests.kproj", "{AA99AF26-F7B1-4A6B-A922-5C25539F6391}"
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Http.Core.Tests", "test\Microsoft.AspNet.Http.Core.Tests\Microsoft.AspNet.Http.Core.Tests.kproj", "{AA99AF26-F7B1-4A6B-A922-5C25539F6391}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.FeatureModel.Tests", "test\Microsoft.AspNet.FeatureModel.Tests\Microsoft.AspNet.FeatureModel.Tests.kproj", "{C5D2BAE1-E182-48A0-AA74-1AF14B782BF7}"
|
||||
EndProject
|
||||
|
|
@ -33,6 +33,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.WebUtiliti
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.WebUtilities.Tests", "test\Microsoft.AspNet.WebUtilities.Tests\Microsoft.AspNet.WebUtilities.Tests.kproj", "{93C10E50-BCBB-4D8E-9492-D46E1396225B}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Net.Http.Headers", "src\Microsoft.Net.Http.Headers\Microsoft.Net.Http.Headers.kproj", "{60AA2FDB-8121-4826-8D00-9A143FEFAF66}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Net.Http.Headers.Tests", "test\Microsoft.Net.Http.Headers.Tests\Microsoft.Net.Http.Headers.Tests.kproj", "{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -173,6 +177,30 @@ Global
|
|||
{93C10E50-BCBB-4D8E-9492-D46E1396225B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{93C10E50-BCBB-4D8E-9492-D46E1396225B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{93C10E50-BCBB-4D8E-9492-D46E1396225B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66}.Release|x86.Build.0 = Release|Any CPU
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -191,5 +219,7 @@ Global
|
|||
{AE25EF21-7F91-4B86-B73E-AF746821D339} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}
|
||||
{A2FB7838-0031-4FAD-BA3E-83C30B3AF406} = {A5A15F1C-885A-452A-A731-B0173DDBD913}
|
||||
{93C10E50-BCBB-4D8E-9492-D46E1396225B} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}
|
||||
{60AA2FDB-8121-4826-8D00-9A143FEFAF66} = {A5A15F1C-885A-452A-A731-B0173DDBD913}
|
||||
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ IF EXIST packages\KoreBuild goto run
|
|||
.nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
|
||||
.nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion
|
||||
|
||||
IF "%SKIP_KRE_INSTALL%"=="1" goto run
|
||||
CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86
|
||||
CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86
|
||||
IF "%SKIP_DOTNET_INSTALL%"=="1" goto run
|
||||
CALL packages\KoreBuild\build\dotnetsdk upgrade -runtime CLR -x86
|
||||
CALL packages\KoreBuild\build\dotnetsdk install default -runtime CoreCLR -x86
|
||||
|
||||
:run
|
||||
CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86
|
||||
CALL packages\KoreBuild\build\dotnetsdk use default -runtime CLR -x86
|
||||
packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*
|
||||
|
|
|
|||
4
build.sh
4
build.sh
|
|
@ -28,11 +28,11 @@ if test ! -d packages/KoreBuild; then
|
|||
fi
|
||||
|
||||
if ! type k > /dev/null 2>&1; then
|
||||
source packages/KoreBuild/build/kvm.sh
|
||||
source packages/KoreBuild/build/dotnetsdk.sh
|
||||
fi
|
||||
|
||||
if ! type k > /dev/null 2>&1; then
|
||||
kvm upgrade
|
||||
dotnetsdk upgrade
|
||||
fi
|
||||
|
||||
mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
|
|
@ -14,4 +14,9 @@
|
|||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties project_1json__JSONSchema="http://www.asp.net/media/4878834/project.json" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
"version": "1.0.0-*",
|
||||
"description": "ASP.NET 5 HTTP feature infrastructure.",
|
||||
"dependencies": {
|
||||
"Microsoft.Framework.Runtime.Interfaces": "1.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"aspnet50": {},
|
||||
|
|
@ -14,7 +13,7 @@
|
|||
"System.Reflection.TypeExtensions": "4.0.0-beta-*",
|
||||
"System.Runtime": "4.0.20-beta-*",
|
||||
"System.Runtime.InteropServices": "4.0.20-beta-*",
|
||||
"System.Threading": "4.0.0-beta-*"
|
||||
"System.Threading": "4.0.10-beta-*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.WebUtilities;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public static class BufferingHelper
|
||||
{
|
||||
internal const int DefaultBufferThreshold = 1024 * 30;
|
||||
|
||||
public static string TempDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
var temp = Environment.GetEnvironmentVariable("ASPNET_TEMP");
|
||||
if (string.IsNullOrEmpty(temp))
|
||||
{
|
||||
temp = Environment.GetEnvironmentVariable("TEMP");
|
||||
}
|
||||
|
||||
if (!Directory.Exists(temp))
|
||||
{
|
||||
// TODO: ???
|
||||
throw new DirectoryNotFoundException(temp);
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpRequest EnableRewind([NotNull] this HttpRequest request, int bufferThreshold = DefaultBufferThreshold)
|
||||
{
|
||||
var body = request.Body;
|
||||
if (!body.CanSeek)
|
||||
{
|
||||
// TODO: Register this buffer for disposal at the end of the request to ensure the temp file is deleted.
|
||||
// Otherwise it won't get deleted until GC closes the stream.
|
||||
request.Body = new FileBufferingReadStream(body, bufferThreshold, TempDirectory);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +1,27 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Http;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Microsoft.AspNet.WebUtilities.Collections
|
||||
namespace Microsoft.AspNet.Http.Core.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the parsed form values.
|
||||
/// </summary>
|
||||
public class FormCollection : ReadableStringCollection, IFormCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:Microsoft.AspNet.WebUtilities.FormCollection" /> class.
|
||||
/// </summary>
|
||||
/// <param name="store">The store for the form.</param>
|
||||
public FormCollection(IDictionary<string, string[]> store)
|
||||
: base(store)
|
||||
public FormCollection([NotNull] IDictionary<string, string[]> store)
|
||||
: this(store, new FormFileCollection())
|
||||
{
|
||||
}
|
||||
|
||||
public FormCollection([NotNull] IDictionary<string, string[]> store, [NotNull] IFormFileCollection files)
|
||||
: base(store)
|
||||
{
|
||||
Files = files;
|
||||
}
|
||||
|
||||
public IFormFileCollection Files { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Core.Collections
|
||||
{
|
||||
public class FormFileCollection : List<IFormFile>, IFormFileCollection
|
||||
{
|
||||
public IFormFile this[string name]
|
||||
{
|
||||
get { return GetFile(name); }
|
||||
}
|
||||
|
||||
public IFormFile GetFile(string name)
|
||||
{
|
||||
return Find(file => string.Equals(name, GetName(file.ContentDisposition)));
|
||||
}
|
||||
|
||||
public IList<IFormFile> GetFiles(string name)
|
||||
{
|
||||
return FindAll(file => string.Equals(name, GetName(file.ContentDisposition)));
|
||||
}
|
||||
|
||||
private static string GetName(string contentDisposition)
|
||||
{
|
||||
// Content-Disposition: form-data; name="myfile1"; filename="Misc 002.jpg"
|
||||
ContentDispositionHeaderValue cd;
|
||||
ContentDispositionHeaderValue.TryParse(contentDisposition, out cd);
|
||||
return HeaderUtilities.RemoveQuotes(cd?.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,26 +7,25 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.Http.Infrastructure;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
||||
using Microsoft.AspNet.Http.Core.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Collections
|
||||
namespace Microsoft.AspNet.Http.Core.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a wrapper for owin.RequestHeaders and owin.ResponseHeaders.
|
||||
/// </summary>
|
||||
public class HeaderDictionary : IHeaderDictionary
|
||||
{
|
||||
public HeaderDictionary() : this(new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:Microsoft.Owin.HeaderDictionary" /> class.
|
||||
/// </summary>
|
||||
/// <param name="store">The underlying data store.</param>
|
||||
public HeaderDictionary(IDictionary<string, string[]> store)
|
||||
public HeaderDictionary([NotNull] IDictionary<string, string[]> store)
|
||||
{
|
||||
if (store == null)
|
||||
{
|
||||
throw new ArgumentNullException("store");
|
||||
}
|
||||
|
||||
Store = store;
|
||||
}
|
||||
|
||||
|
|
@ -3,9 +3,8 @@
|
|||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class ItemsDictionary : IDictionary<object, object>
|
||||
{
|
||||
|
|
@ -6,7 +6,7 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Microsoft.AspNet.WebUtilities.Collections
|
||||
namespace Microsoft.AspNet.Http.Core.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// Accessors for query, forms, etc.
|
||||
|
|
@ -17,13 +17,8 @@ namespace Microsoft.AspNet.WebUtilities.Collections
|
|||
/// Create a new wrapper
|
||||
/// </summary>
|
||||
/// <param name="store"></param>
|
||||
public ReadableStringCollection(IDictionary<string, string[]> store)
|
||||
public ReadableStringCollection([NotNull] IDictionary<string, string[]> store)
|
||||
{
|
||||
if (store == null)
|
||||
{
|
||||
throw new ArgumentNullException("store");
|
||||
}
|
||||
|
||||
Store = store;
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +70,7 @@ namespace Microsoft.AspNet.WebUtilities.Collections
|
|||
/// <returns></returns>
|
||||
public string Get(string key)
|
||||
{
|
||||
return ParsingHelpers.GetJoinedValue(Store, key);
|
||||
return GetJoinedValue(Store, key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -108,5 +103,15 @@ namespace Microsoft.AspNet.WebUtilities.Collections
|
|||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
private static string GetJoinedValue(IDictionary<string, string[]> store, string key)
|
||||
{
|
||||
string[] values;
|
||||
if (store.TryGetValue(key, out values))
|
||||
{
|
||||
return string.Join(",", values);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,9 +5,9 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
||||
using Microsoft.AspNet.Http.Core.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Collections
|
||||
namespace Microsoft.AspNet.Http.Core.Collections
|
||||
{
|
||||
public class RequestCookiesCollection : IReadableStringCollection
|
||||
{
|
||||
|
|
@ -8,7 +8,7 @@ using System.Linq;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Collections
|
||||
namespace Microsoft.AspNet.Http.Core.Collections
|
||||
{
|
||||
/// <summary>
|
||||
/// A wrapper for the response Set-Cookie header
|
||||
|
|
@ -19,13 +19,8 @@ namespace Microsoft.AspNet.PipelineCore.Collections
|
|||
/// Create a new wrapper
|
||||
/// </summary>
|
||||
/// <param name="headers"></param>
|
||||
public ResponseCookies(IHeaderDictionary headers)
|
||||
public ResponseCookies([NotNull] IHeaderDictionary headers)
|
||||
{
|
||||
if (headers == null)
|
||||
{
|
||||
throw new ArgumentNullException("headers");
|
||||
}
|
||||
|
||||
Headers = headers;
|
||||
}
|
||||
|
||||
|
|
@ -47,13 +42,8 @@ namespace Microsoft.AspNet.PipelineCore.Collections
|
|||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="options"></param>
|
||||
public void Append(string key, string value, CookieOptions options)
|
||||
public void Append(string key, string value, [NotNull] CookieOptions options)
|
||||
{
|
||||
if (options == null)
|
||||
{
|
||||
throw new ArgumentNullException("options");
|
||||
}
|
||||
|
||||
bool domainHasValue = !string.IsNullOrEmpty(options.Domain);
|
||||
bool pathHasValue = !string.IsNullOrEmpty(options.Path);
|
||||
bool expiresHasValue = options.Expires.HasValue;
|
||||
|
|
@ -98,13 +88,8 @@ namespace Microsoft.AspNet.PipelineCore.Collections
|
|||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="options"></param>
|
||||
public void Delete(string key, CookieOptions options)
|
||||
public void Delete(string key, [NotNull] CookieOptions options)
|
||||
{
|
||||
if (options == null)
|
||||
{
|
||||
throw new ArgumentNullException("options");
|
||||
}
|
||||
|
||||
bool domainHasValue = !string.IsNullOrEmpty(options.Domain);
|
||||
bool pathHasValue = !string.IsNullOrEmpty(options.Path);
|
||||
|
||||
|
|
@ -5,9 +5,9 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Collections
|
||||
namespace Microsoft.AspNet.Http.Core.Collections
|
||||
{
|
||||
public class SessionCollection : ISessionCollection
|
||||
{
|
||||
|
|
@ -12,13 +12,13 @@ using Microsoft.AspNet.FeatureModel;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Infrastructure;
|
||||
using Microsoft.AspNet.Http.Security;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.HttpFeature.Security;
|
||||
using Microsoft.AspNet.PipelineCore.Collections;
|
||||
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
||||
using Microsoft.AspNet.PipelineCore.Security;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
using Microsoft.AspNet.Http.Interfaces.Security;
|
||||
using Microsoft.AspNet.Http.Core.Collections;
|
||||
using Microsoft.AspNet.Http.Core.Infrastructure;
|
||||
using Microsoft.AspNet.Http.Core.Security;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class DefaultHttpContext : HttpContext
|
||||
{
|
||||
|
|
@ -38,8 +38,8 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
public DefaultHttpContext()
|
||||
: this(new FeatureCollection())
|
||||
{
|
||||
SetFeature<IHttpRequestFeature>(new DefaultHttpRequestFeature());
|
||||
SetFeature<IHttpResponseFeature>(new DefaultHttpResponseFeature());
|
||||
SetFeature<IHttpRequestFeature>(new HttpRequestFeature());
|
||||
SetFeature<IHttpResponseFeature>(new HttpResponseFeature());
|
||||
}
|
||||
|
||||
public DefaultHttpContext(IFeatureCollection features)
|
||||
|
|
@ -214,12 +214,8 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
return authTypeContext.Results;
|
||||
}
|
||||
|
||||
public override IEnumerable<AuthenticationResult> Authenticate(IEnumerable<string> authenticationTypes)
|
||||
public override IEnumerable<AuthenticationResult> Authenticate([NotNull] IEnumerable<string> authenticationTypes)
|
||||
{
|
||||
if (authenticationTypes == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
var handler = HttpAuthenticationFeature.Handler;
|
||||
|
||||
var authenticateContext = new AuthenticateContext(authenticationTypes);
|
||||
|
|
@ -238,12 +234,8 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
return authenticateContext.Results;
|
||||
}
|
||||
|
||||
public override async Task<IEnumerable<AuthenticationResult>> AuthenticateAsync(IEnumerable<string> authenticationTypes)
|
||||
public override async Task<IEnumerable<AuthenticationResult>> AuthenticateAsync([NotNull] IEnumerable<string> authenticationTypes)
|
||||
{
|
||||
if (authenticationTypes == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
var handler = HttpAuthenticationFeature.Handler;
|
||||
|
||||
var authenticateContext = new AuthenticateContext(authenticationTypes);
|
||||
|
|
@ -2,18 +2,17 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Infrastructure;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.PipelineCore.Collections;
|
||||
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
using Microsoft.AspNet.Http.Core.Collections;
|
||||
using Microsoft.AspNet.Http.Core.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class DefaultHttpRequest : HttpRequest
|
||||
{
|
||||
|
|
@ -55,7 +54,7 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
|
||||
private IFormFeature FormFeature
|
||||
{
|
||||
get { return _form.Fetch(_features) ?? _form.Update(_features, new FormFeature(_features)); }
|
||||
get { return _form.Fetch(_features) ?? _form.Update(_features, new FormFeature(this)); }
|
||||
}
|
||||
|
||||
private IRequestCookiesFeature RequestCookiesFeature
|
||||
|
|
@ -83,7 +82,7 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
set { HttpRequestFeature.QueryString = value.Value; }
|
||||
}
|
||||
|
||||
public override long? ContentLength
|
||||
public override long? ContentLength
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
@ -129,11 +128,6 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
get { return QueryFeature.Query; }
|
||||
}
|
||||
|
||||
public override Task<IReadableStringCollection> GetFormAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return FormFeature.GetFormAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public override string Protocol
|
||||
{
|
||||
get { return HttpRequestFeature.Protocol; }
|
||||
|
|
@ -156,16 +150,20 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
set { Headers[Constants.Headers.ContentType] = value; }
|
||||
}
|
||||
|
||||
public override string Accept
|
||||
public override bool HasFormContentType
|
||||
{
|
||||
get { return Headers[Constants.Headers.Accept]; }
|
||||
set { Headers[Constants.Headers.Accept] = value; }
|
||||
get { return FormFeature.HasFormContentType; }
|
||||
}
|
||||
|
||||
public override string AcceptCharset
|
||||
public override IFormCollection Form
|
||||
{
|
||||
get { return Headers[Constants.Headers.AcceptCharset]; }
|
||||
set { Headers[Constants.Headers.AcceptCharset] = value; }
|
||||
get { return FormFeature.ReadForm(); }
|
||||
set { FormFeature.Form = value; }
|
||||
}
|
||||
|
||||
public override Task<IFormCollection> ReadFormAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return FormFeature.ReadFormAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,13 +12,13 @@ using Microsoft.AspNet.Http;
|
|||
using Microsoft.AspNet.Http.Infrastructure;
|
||||
using Microsoft.AspNet.Http.Security;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.HttpFeature.Security;
|
||||
using Microsoft.AspNet.PipelineCore.Collections;
|
||||
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
||||
using Microsoft.AspNet.PipelineCore.Security;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
using Microsoft.AspNet.Http.Interfaces.Security;
|
||||
using Microsoft.AspNet.Http.Core.Collections;
|
||||
using Microsoft.AspNet.Http.Core.Infrastructure;
|
||||
using Microsoft.AspNet.Http.Core.Security;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class DefaultHttpResponse : HttpResponse
|
||||
{
|
||||
|
|
@ -129,12 +129,8 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
Headers.Set(Constants.Headers.Location, location);
|
||||
}
|
||||
|
||||
public override void Challenge(AuthenticationProperties properties, IEnumerable<string> authenticationTypes)
|
||||
public override void Challenge(AuthenticationProperties properties, [NotNull] IEnumerable<string> authenticationTypes)
|
||||
{
|
||||
if (authenticationTypes == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
HttpResponseFeature.StatusCode = 401;
|
||||
var handler = HttpAuthenticationFeature.Handler;
|
||||
|
||||
|
|
@ -152,13 +148,8 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
}
|
||||
}
|
||||
|
||||
public override void SignIn(AuthenticationProperties properties, IEnumerable<ClaimsIdentity> identities)
|
||||
public override void SignIn(AuthenticationProperties properties, [NotNull] IEnumerable<ClaimsIdentity> identities)
|
||||
{
|
||||
if (identities == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
var handler = HttpAuthenticationFeature.Handler;
|
||||
|
||||
var signInContext = new SignInContext(identities, properties == null ? null : properties.Dictionary);
|
||||
|
|
@ -175,12 +166,8 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
}
|
||||
}
|
||||
|
||||
public override void SignOut(IEnumerable<string> authenticationTypes)
|
||||
public override void SignOut([NotNull] IEnumerable<string> authenticationTypes)
|
||||
{
|
||||
if (authenticationTypes == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
var handler = HttpAuthenticationFeature.Handler;
|
||||
|
||||
var signOutContext = new SignOutContext(authenticationTypes);
|
||||
|
|
@ -0,0 +1,207 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Core.Collections;
|
||||
using Microsoft.AspNet.WebUtilities;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class FormFeature : IFormFeature
|
||||
{
|
||||
private readonly HttpRequest _request;
|
||||
|
||||
public FormFeature([NotNull] IFormCollection form)
|
||||
{
|
||||
Form = form;
|
||||
}
|
||||
|
||||
public FormFeature([NotNull] HttpRequest request)
|
||||
{
|
||||
_request = request;
|
||||
}
|
||||
|
||||
private MediaTypeHeaderValue ContentType
|
||||
{
|
||||
get
|
||||
{
|
||||
MediaTypeHeaderValue mt;
|
||||
MediaTypeHeaderValue.TryParse(_request.ContentType, out mt);
|
||||
return mt;
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasFormContentType
|
||||
{
|
||||
get
|
||||
{
|
||||
// Set directly
|
||||
if (Form != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var conentType = ContentType;
|
||||
return HasApplicationFormContentType(conentType) || HasMultipartFormContentType(conentType);
|
||||
}
|
||||
}
|
||||
|
||||
public IFormCollection Form { get; set; }
|
||||
|
||||
public IFormCollection ReadForm()
|
||||
{
|
||||
if (Form != null)
|
||||
{
|
||||
return Form;
|
||||
}
|
||||
|
||||
if (!HasFormContentType)
|
||||
{
|
||||
throw new InvalidOperationException("Incorrect Content-Type: " + _request.ContentType);
|
||||
}
|
||||
|
||||
// TODO: How do we prevent thread exhaustion?
|
||||
return ReadFormAsync(CancellationToken.None).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public async Task<IFormCollection> ReadFormAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (Form != null)
|
||||
{
|
||||
return Form;
|
||||
}
|
||||
|
||||
if (!HasFormContentType)
|
||||
{
|
||||
throw new InvalidOperationException("Incorrect Content-Type: " + _request.ContentType);
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
_request.EnableRewind();
|
||||
|
||||
IDictionary<string, string[]> formFields = null;
|
||||
var files = new FormFileCollection();
|
||||
|
||||
// Some of these code paths use StreamReader which does not support cancellation tokens.
|
||||
using (cancellationToken.Register(_request.HttpContext.Abort))
|
||||
{
|
||||
var contentType = ContentType;
|
||||
// Check the content-type
|
||||
if (HasApplicationFormContentType(contentType))
|
||||
{
|
||||
var encoding = FilterEncoding(contentType.Encoding);
|
||||
formFields = await FormReader.ReadFormAsync(_request.Body, encoding, cancellationToken);
|
||||
}
|
||||
else if (HasMultipartFormContentType(contentType))
|
||||
{
|
||||
var formAccumulator = new KeyValueAccumulator<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var boundary = GetBoundary(contentType);
|
||||
var multipartReader = new MultipartReader(boundary, _request.Body);
|
||||
var section = await multipartReader.ReadNextSectionAsync(cancellationToken);
|
||||
while (section != null)
|
||||
{
|
||||
var headers = new HeaderDictionary(section.Headers);
|
||||
ContentDispositionHeaderValue contentDisposition;
|
||||
ContentDispositionHeaderValue.TryParse(headers.Get(HeaderNames.ContentDisposition), out contentDisposition);
|
||||
if (HasFileContentDisposition(contentDisposition))
|
||||
{
|
||||
// Find the end
|
||||
await section.Body.DrainAsync(cancellationToken);
|
||||
|
||||
var file = new FormFile(_request.Body, section.BaseStreamOffset.Value, section.Body.Length)
|
||||
{
|
||||
Headers = headers,
|
||||
};
|
||||
files.Add(file);
|
||||
}
|
||||
else if (HasFormDataContentDisposition(contentDisposition))
|
||||
{
|
||||
// Content-Disposition: form-data; name="key"
|
||||
//
|
||||
// value
|
||||
|
||||
var key = HeaderUtilities.RemoveQuotes(contentDisposition.Name);
|
||||
MediaTypeHeaderValue mediaType;
|
||||
MediaTypeHeaderValue.TryParse(headers.Get(HeaderNames.ContentType), out mediaType);
|
||||
var encoding = FilterEncoding(mediaType?.Encoding);
|
||||
using (var reader = new StreamReader(section.Body, encoding, detectEncodingFromByteOrderMarks: true, bufferSize: 1024, leaveOpen: true))
|
||||
{
|
||||
var value = await reader.ReadToEndAsync();
|
||||
formAccumulator.Append(key, value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(false, "Unrecognized content-disposition for this section: " + headers.Get(HeaderNames.ContentDisposition));
|
||||
}
|
||||
|
||||
section = await multipartReader.ReadNextSectionAsync(cancellationToken);
|
||||
}
|
||||
|
||||
formFields = formAccumulator.GetResults();
|
||||
}
|
||||
}
|
||||
|
||||
Form = new FormCollection(formFields, files);
|
||||
return Form;
|
||||
}
|
||||
|
||||
private Encoding FilterEncoding(Encoding encoding)
|
||||
{
|
||||
// UTF-7 is insecure and should not be honored. UTF-8 will succeed for most cases.
|
||||
if (encoding == null || Encoding.UTF7.Equals(encoding))
|
||||
{
|
||||
return Encoding.UTF8;
|
||||
}
|
||||
return encoding;
|
||||
}
|
||||
|
||||
private bool HasApplicationFormContentType(MediaTypeHeaderValue contentType)
|
||||
{
|
||||
// Content-Type: application/x-www-form-urlencoded; charset=utf-8
|
||||
return contentType != null && contentType.MediaType.Equals("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private bool HasMultipartFormContentType(MediaTypeHeaderValue contentType)
|
||||
{
|
||||
// Content-Type: multipart/form-data; boundary=----WebKitFormBoundarymx2fSWqWSd0OxQqq
|
||||
return contentType != null && contentType.MediaType.Equals("multipart/form-data", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private bool HasFormDataContentDisposition(ContentDispositionHeaderValue contentDisposition)
|
||||
{
|
||||
// Content-Disposition: form-data; name="key";
|
||||
return contentDisposition != null && contentDisposition.DispositionType.Equals("form-data")
|
||||
&& string.IsNullOrEmpty(contentDisposition.FileName) && string.IsNullOrEmpty(contentDisposition.FileNameStar);
|
||||
}
|
||||
|
||||
private bool HasFileContentDisposition(ContentDispositionHeaderValue contentDisposition)
|
||||
{
|
||||
// Content-Disposition: form-data; name="myfile1"; filename="Misc 002.jpg"
|
||||
return contentDisposition != null && contentDisposition.DispositionType.Equals("form-data")
|
||||
&& (!string.IsNullOrEmpty(contentDisposition.FileName) || !string.IsNullOrEmpty(contentDisposition.FileNameStar));
|
||||
}
|
||||
|
||||
// Content-Type: multipart/form-data; boundary="----WebKitFormBoundarymx2fSWqWSd0OxQqq"
|
||||
// TODO: Limit the length of boundary we accept. The spec says ~70 chars.
|
||||
private static string GetBoundary(MediaTypeHeaderValue contentType)
|
||||
{
|
||||
var boundary = HeaderUtilities.RemoveQuotes(contentType.Boundary);
|
||||
if (string.IsNullOrWhiteSpace(boundary))
|
||||
{
|
||||
throw new InvalidOperationException("Missing content-type boundary.");
|
||||
}
|
||||
return boundary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.IO;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class FormFile : IFormFile
|
||||
{
|
||||
private Stream _baseStream;
|
||||
private long _baseStreamOffset;
|
||||
private long _length;
|
||||
|
||||
public FormFile(Stream baseStream, long baseStreamOffset, long length)
|
||||
{
|
||||
_baseStream = baseStream;
|
||||
_baseStreamOffset = baseStreamOffset;
|
||||
_length = length;
|
||||
}
|
||||
|
||||
public string ContentDisposition
|
||||
{
|
||||
get { return Headers["Content-Disposition"]; }
|
||||
set { Headers["Content-Disposition"] = value; }
|
||||
}
|
||||
|
||||
public string ContentType
|
||||
{
|
||||
get { return Headers["Content-Type"]; }
|
||||
set { Headers["Content-Type"] = value; }
|
||||
}
|
||||
|
||||
public IHeaderDictionary Headers { get; set; }
|
||||
|
||||
public long Length
|
||||
{
|
||||
get { return _length; }
|
||||
}
|
||||
|
||||
public Stream OpenReadStream()
|
||||
{
|
||||
return new ReferenceReadStream(_baseStream, _baseStreamOffset, _length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,13 +4,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class DefaultHttpRequestFeature : IHttpRequestFeature
|
||||
public class HttpRequestFeature : IHttpRequestFeature
|
||||
{
|
||||
public DefaultHttpRequestFeature()
|
||||
public HttpRequestFeature()
|
||||
{
|
||||
Headers = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
||||
Body = Stream.Null;
|
||||
|
|
@ -4,13 +4,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class DefaultHttpResponseFeature : IHttpResponseFeature
|
||||
public class HttpResponseFeature : IHttpResponseFeature
|
||||
{
|
||||
public DefaultHttpResponseFeature()
|
||||
public HttpResponseFeature()
|
||||
{
|
||||
StatusCode = 200;
|
||||
Headers = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public interface IFormFeature
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates if the request has a supported form content-type.
|
||||
/// </summary>
|
||||
bool HasFormContentType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The parsed form, if any.
|
||||
/// </summary>
|
||||
IFormCollection Form { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Parses the request body as a form.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IFormCollection ReadForm();
|
||||
|
||||
/// <summary>
|
||||
/// Parses the request body as a form.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IFormCollection> ReadFormAsync(CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public interface IItemsFeature
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public interface IQueryFeature
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public interface IRequestCookiesFeature
|
||||
{
|
||||
|
|
@ -2,9 +2,9 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.PipelineCore.Collections;
|
||||
using Microsoft.AspNet.Http.Core.Collections;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public interface IResponseCookiesFeature
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public interface IServiceProvidersFeature
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
||||
namespace Microsoft.AspNet.Http.Core.Infrastructure
|
||||
{
|
||||
internal struct FeatureReference<T>
|
||||
{
|
||||
|
|
@ -9,7 +9,7 @@ using System.Linq;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
||||
namespace Microsoft.AspNet.Http.Core.Infrastructure
|
||||
{
|
||||
internal struct HeaderSegment : IEquatable<HeaderSegment>
|
||||
{
|
||||
|
|
@ -445,12 +445,8 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
|
||||
#endregion
|
||||
|
||||
public bool StartsWith(string text, StringComparison comparisonType)
|
||||
public bool StartsWith([NotNull] string text, StringComparison comparisonType)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException("text");
|
||||
}
|
||||
int textLength = text.Length;
|
||||
if (!HasValue || _count < textLength)
|
||||
{
|
||||
|
|
@ -460,12 +456,8 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
return string.Compare(_buffer, _offset, text, 0, textLength, comparisonType) == 0;
|
||||
}
|
||||
|
||||
public bool EndsWith(string text, StringComparison comparisonType)
|
||||
public bool EndsWith([NotNull] string text, StringComparison comparisonType)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException("text");
|
||||
}
|
||||
int textLength = text.Length;
|
||||
if (!HasValue || _count < textLength)
|
||||
{
|
||||
|
|
@ -475,12 +467,8 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
return string.Compare(_buffer, _offset + _count - textLength, text, 0, textLength, comparisonType) == 0;
|
||||
}
|
||||
|
||||
public bool Equals(string text, StringComparison comparisonType)
|
||||
public bool Equals([NotNull] string text, StringComparison comparisonType)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
throw new ArgumentNullException("text");
|
||||
}
|
||||
int textLength = text.Length;
|
||||
if (!HasValue || _count != textLength)
|
||||
{
|
||||
|
|
@ -530,25 +518,6 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
request.HttpContext.Items[key] = value;
|
||||
}
|
||||
|
||||
internal static IDictionary<string, string> GetCookies(HttpRequest request)
|
||||
{
|
||||
var cookies = GetItem<IDictionary<string, string>>(request, "Microsoft.Owin.Cookies#dictionary");
|
||||
if (cookies == null)
|
||||
{
|
||||
cookies = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
SetItem(request, "Microsoft.Owin.Cookies#dictionary", cookies);
|
||||
}
|
||||
|
||||
string text = GetHeader(request.Headers, "Cookie");
|
||||
if (GetItem<string>(request, "Microsoft.Owin.Cookies#text") != text)
|
||||
{
|
||||
cookies.Clear();
|
||||
ParseDelimited(text, SemicolonAndComma, AddCookieCallback, cookies);
|
||||
SetItem(request, "Microsoft.Owin.Cookies#text", text);
|
||||
}
|
||||
return cookies;
|
||||
}
|
||||
|
||||
internal static void ParseCookies(string cookiesHeader, IDictionary<string, string> cookiesCollection)
|
||||
{
|
||||
ParseDelimited(cookiesHeader, SemicolonAndComma, AddCookieCallback, cookiesCollection);
|
||||
|
|
@ -615,25 +584,17 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
}
|
||||
}
|
||||
|
||||
public static string[] GetHeaderUnmodified(IDictionary<string, string[]> headers, string key)
|
||||
public static string[] GetHeaderUnmodified([NotNull] IDictionary<string, string[]> headers, string key)
|
||||
{
|
||||
if (headers == null)
|
||||
{
|
||||
throw new ArgumentNullException("headers");
|
||||
}
|
||||
string[] values;
|
||||
return headers.TryGetValue(key, out values) ? values : null;
|
||||
}
|
||||
|
||||
public static void SetHeader(IDictionary<string, string[]> headers, string key, string value)
|
||||
public static void SetHeader([NotNull] IDictionary<string, string[]> headers, [NotNull] string key, string value)
|
||||
{
|
||||
if (headers == null)
|
||||
{
|
||||
throw new ArgumentNullException("headers");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
throw new ArgumentNullException("key");
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
|
|
@ -645,15 +606,11 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
}
|
||||
}
|
||||
|
||||
public static void SetHeaderJoined(IDictionary<string, string[]> headers, string key, params string[] values)
|
||||
public static void SetHeaderJoined([NotNull] IDictionary<string, string[]> headers, [NotNull] string key, params string[] values)
|
||||
{
|
||||
if (headers == null)
|
||||
{
|
||||
throw new ArgumentNullException("headers");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
throw new ArgumentNullException("key");
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
if (values == null || values.Length == 0)
|
||||
{
|
||||
|
|
@ -697,15 +654,11 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
return value;
|
||||
}
|
||||
|
||||
public static void SetHeaderUnmodified(IDictionary<string, string[]> headers, string key, params string[] values)
|
||||
public static void SetHeaderUnmodified([NotNull] IDictionary<string, string[]> headers, [NotNull] string key, params string[] values)
|
||||
{
|
||||
if (headers == null)
|
||||
{
|
||||
throw new ArgumentNullException("headers");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
throw new ArgumentNullException("key");
|
||||
throw new ArgumentNullException(nameof(key));
|
||||
}
|
||||
if (values == null || values.Length == 0)
|
||||
{
|
||||
|
|
@ -717,16 +670,12 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
}
|
||||
}
|
||||
|
||||
public static void SetHeaderUnmodified(IDictionary<string, string[]> headers, string key, IEnumerable<string> values)
|
||||
public static void SetHeaderUnmodified([NotNull] IDictionary<string, string[]> headers, [NotNull] string key, [NotNull] IEnumerable<string> values)
|
||||
{
|
||||
if (headers == null)
|
||||
{
|
||||
throw new ArgumentNullException("headers");
|
||||
}
|
||||
headers[key] = values.ToArray();
|
||||
}
|
||||
|
||||
public static void AppendHeader(IDictionary<string, string[]> headers, string key, string values)
|
||||
public static void AppendHeader([NotNull] IDictionary<string, string[]> headers, [NotNull] string key, string values)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(values))
|
||||
{
|
||||
|
|
@ -744,7 +693,7 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
}
|
||||
}
|
||||
|
||||
public static void AppendHeaderJoined(IDictionary<string, string[]> headers, string key, params string[] values)
|
||||
public static void AppendHeaderJoined([NotNull] IDictionary<string, string[]> headers, [NotNull] string key, params string[] values)
|
||||
{
|
||||
if (values == null || values.Length == 0)
|
||||
{
|
||||
|
|
@ -762,7 +711,7 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
}
|
||||
}
|
||||
|
||||
public static void AppendHeaderUnmodified(IDictionary<string, string[]> headers, string key, params string[] values)
|
||||
public static void AppendHeaderUnmodified([NotNull] IDictionary<string, string[]> headers, [NotNull] string key, params string[] values)
|
||||
{
|
||||
if (values == null || values.Length == 0)
|
||||
{
|
||||
|
|
@ -801,12 +750,8 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
return values == null ? null : string.Join(",", values);
|
||||
}
|
||||
|
||||
internal static string[] GetUnmodifiedValues(IDictionary<string, string[]> store, string key)
|
||||
internal static string[] GetUnmodifiedValues([NotNull] IDictionary<string, string[]> store, string key)
|
||||
{
|
||||
if (store == null)
|
||||
{
|
||||
throw new ArgumentNullException("store");
|
||||
}
|
||||
string[] values;
|
||||
return store.TryGetValue(key, out values) ? values : null;
|
||||
}
|
||||
|
|
@ -826,7 +771,7 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
// return string.IsNullOrWhiteSpace(localPort) ? localIpAddress : (localIpAddress + ":" + localPort);
|
||||
//}
|
||||
|
||||
public static long? GetContentLength(IHeaderDictionary headers)
|
||||
public static long? GetContentLength([NotNull] IHeaderDictionary headers)
|
||||
{
|
||||
const NumberStyles styles = NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite;
|
||||
long value;
|
||||
|
|
@ -840,7 +785,7 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void SetContentLength(IHeaderDictionary headers, long? value)
|
||||
public static void SetContentLength([NotNull] IHeaderDictionary headers, long? value)
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class ItemsFeature : IItemsFeature
|
||||
{
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
|
|
@ -14,4 +14,9 @@
|
|||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties project_1json__JSONSchema="http://www.asp.net/media/4878834/project.json" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
|
||||
internal sealed class NotNullAttribute : Attribute
|
||||
|
|
@ -4,12 +4,12 @@
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
using Microsoft.AspNet.Http.Core.Collections;
|
||||
using Microsoft.AspNet.Http.Core.Infrastructure;
|
||||
using Microsoft.AspNet.WebUtilities;
|
||||
using Microsoft.AspNet.WebUtilities.Collections;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class QueryFeature : IQueryFeature
|
||||
{
|
||||
|
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
if (_query == null || _queryString != queryString)
|
||||
{
|
||||
_queryString = queryString;
|
||||
_query = QueryHelpers.ParseQuery(queryString);
|
||||
_query = new ReadableStringCollection(QueryHelpers.ParseQuery(queryString));
|
||||
}
|
||||
return _query;
|
||||
}
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// A Stream that wraps another stream starting at a certain offset and reading for the given length.
|
||||
/// </summary>
|
||||
internal class ReferenceReadStream : Stream
|
||||
{
|
||||
private readonly Stream _inner;
|
||||
private readonly long _innerOffset;
|
||||
private readonly long _length;
|
||||
private long _position;
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
public ReferenceReadStream([NotNull] Stream inner, long offset, long length)
|
||||
{
|
||||
_inner = inner;
|
||||
_innerOffset = offset;
|
||||
_length = length;
|
||||
_inner.Position = offset;
|
||||
}
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return _inner.CanSeek; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get { return _length; }
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get { return _position; }
|
||||
set
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
if (value < 0 || value > Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("value", value, "The Position must be within the length of the Stream: " + Length);
|
||||
}
|
||||
VerifyPosition();
|
||||
_position = value;
|
||||
_inner.Position = _innerOffset + _position;
|
||||
}
|
||||
}
|
||||
|
||||
// Throws if the position in the underlying stream has changed without our knowledge, indicating someone else is trying
|
||||
// to use the stream at the same time which could lead to data corruption.
|
||||
private void VerifyPosition()
|
||||
{
|
||||
if (_inner.Position != _innerOffset + _position)
|
||||
{
|
||||
throw new InvalidOperationException("The inner stream position has changed unexpectedly.");
|
||||
}
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
if (origin == SeekOrigin.Begin)
|
||||
{
|
||||
Position = offset;
|
||||
}
|
||||
else if (origin == SeekOrigin.End)
|
||||
{
|
||||
Position = Length + offset;
|
||||
}
|
||||
else // if (origin == SeekOrigin.Current)
|
||||
{
|
||||
Position = Position + offset;
|
||||
}
|
||||
return Position;
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
VerifyPosition();
|
||||
var toRead = Math.Min(count, _length - _position);
|
||||
var read = _inner.Read(buffer, offset, (int)toRead);
|
||||
_position += read;
|
||||
return read;
|
||||
}
|
||||
|
||||
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
VerifyPosition();
|
||||
var toRead = Math.Min(count, _length - _position);
|
||||
var read = await _inner.ReadAsync(buffer, offset, (int)toRead, cancellationToken);
|
||||
_position += read;
|
||||
return read;
|
||||
}
|
||||
#if ASPNET50
|
||||
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
VerifyPosition();
|
||||
var tcs = new TaskCompletionSource<int>(state);
|
||||
BeginRead(buffer, offset, count, callback, tcs);
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
private async void BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, TaskCompletionSource<int> tcs)
|
||||
{
|
||||
try
|
||||
{
|
||||
var read = await ReadAsync(buffer, offset, count);
|
||||
tcs.TrySetResult(read);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tcs.TrySetException(ex);
|
||||
}
|
||||
|
||||
if (callback != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
callback(tcs.Task);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Suppress exceptions on background threads.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override int EndRead(IAsyncResult asyncResult)
|
||||
{
|
||||
var task = (Task<int>)asyncResult;
|
||||
return task.GetAwaiter().GetResult();
|
||||
}
|
||||
#endif
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
#if ASPNET50
|
||||
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void EndWrite(IAsyncResult asyncResult)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
#endif
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void ThrowIfDisposed()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(nameof(ReferenceReadStream));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,12 +6,11 @@ using System.Collections.Generic;
|
|||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Infrastructure;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.PipelineCore.Collections;
|
||||
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
||||
using Microsoft.AspNet.WebUtilities.Collections;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
using Microsoft.AspNet.Http.Core.Collections;
|
||||
using Microsoft.AspNet.Http.Core.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class RequestCookiesFeature : IRequestCookiesFeature
|
||||
{
|
||||
|
|
@ -3,11 +3,11 @@
|
|||
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.PipelineCore.Collections;
|
||||
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
using Microsoft.AspNet.Http.Core.Collections;
|
||||
using Microsoft.AspNet.Http.Core.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class ResponseCookiesFeature : IResponseCookiesFeature
|
||||
{
|
||||
|
|
@ -4,9 +4,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http.Security;
|
||||
using Microsoft.AspNet.HttpFeature.Security;
|
||||
using Microsoft.AspNet.Http.Interfaces.Security;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Security
|
||||
namespace Microsoft.AspNet.Http.Core.Security
|
||||
{
|
||||
public class AuthTypeContext : IAuthTypeContext
|
||||
{
|
||||
|
|
@ -8,21 +8,17 @@ using System.Security.Claims;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http.Security;
|
||||
using Microsoft.AspNet.HttpFeature.Security;
|
||||
using Microsoft.AspNet.Http.Interfaces.Security;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Security
|
||||
namespace Microsoft.AspNet.Http.Core.Security
|
||||
{
|
||||
public class AuthenticateContext : IAuthenticateContext
|
||||
{
|
||||
private List<AuthenticationResult> _results;
|
||||
private List<string> _accepted;
|
||||
|
||||
public AuthenticateContext(IEnumerable<string> authenticationTypes)
|
||||
public AuthenticateContext([NotNull] IEnumerable<string> authenticationTypes)
|
||||
{
|
||||
if (authenticationTypes == null)
|
||||
{
|
||||
throw new ArgumentNullException("authenticationType");
|
||||
}
|
||||
AuthenticationTypes = authenticationTypes;
|
||||
_results = new List<AuthenticationResult>();
|
||||
_accepted = new List<string>();
|
||||
|
|
@ -6,20 +6,16 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.HttpFeature.Security;
|
||||
using Microsoft.AspNet.Http.Interfaces.Security;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Security
|
||||
namespace Microsoft.AspNet.Http.Core.Security
|
||||
{
|
||||
public class ChallengeContext : IChallengeContext
|
||||
{
|
||||
private List<string> _accepted;
|
||||
|
||||
public ChallengeContext(IEnumerable<string> authenticationTypes, IDictionary<string, string> properties)
|
||||
public ChallengeContext([NotNull] IEnumerable<string> authenticationTypes, IDictionary<string, string> properties)
|
||||
{
|
||||
if (authenticationTypes == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
AuthenticationTypes = authenticationTypes;
|
||||
Properties = properties ?? new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
_accepted = new List<string>();
|
||||
|
|
@ -33,7 +29,7 @@ namespace Microsoft.AspNet.PipelineCore.Security
|
|||
{
|
||||
get { return _accepted; }
|
||||
}
|
||||
|
||||
|
||||
public void Accept(string authenticationType, IDictionary<string, object> description)
|
||||
{
|
||||
_accepted.Add(authenticationType);
|
||||
|
|
@ -2,9 +2,9 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.HttpFeature.Security;
|
||||
using Microsoft.AspNet.Http.Interfaces.Security;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Security
|
||||
namespace Microsoft.AspNet.Http.Core.Security
|
||||
{
|
||||
public class HttpAuthenticationFeature : IHttpAuthenticationFeature
|
||||
{
|
||||
|
|
@ -4,20 +4,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.HttpFeature.Security;
|
||||
using Microsoft.AspNet.Http.Interfaces.Security;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Security
|
||||
namespace Microsoft.AspNet.Http.Core.Security
|
||||
{
|
||||
public class SignInContext : ISignInContext
|
||||
{
|
||||
private List<string> _accepted;
|
||||
|
||||
public SignInContext(IEnumerable<ClaimsIdentity> identities, IDictionary<string, string> dictionary)
|
||||
public SignInContext([NotNull] IEnumerable<ClaimsIdentity> identities, IDictionary<string, string> dictionary)
|
||||
{
|
||||
if (identities == null)
|
||||
{
|
||||
throw new ArgumentNullException("identities");
|
||||
}
|
||||
Identities = identities;
|
||||
Properties = dictionary ?? new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
_accepted = new List<string>();
|
||||
|
|
@ -3,20 +3,16 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.HttpFeature.Security;
|
||||
using Microsoft.AspNet.Http.Interfaces.Security;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Security
|
||||
namespace Microsoft.AspNet.Http.Core.Security
|
||||
{
|
||||
public class SignOutContext : ISignOutContext
|
||||
{
|
||||
private List<string> _accepted;
|
||||
|
||||
public SignOutContext(IEnumerable<string> authenticationTypes)
|
||||
public SignOutContext([NotNull] IEnumerable<string> authenticationTypes)
|
||||
{
|
||||
if (authenticationTypes == null)
|
||||
{
|
||||
throw new ArgumentNullException("authenticationTypes");
|
||||
}
|
||||
AuthenticationTypes = authenticationTypes;
|
||||
_accepted = new List<string>();
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class ServiceProvidersFeature : IServiceProvidersFeature
|
||||
{
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class WebSocketAcceptContext : IWebSocketAcceptContext
|
||||
{
|
||||
|
|
@ -5,8 +5,10 @@
|
|||
"dependencies": {
|
||||
"Microsoft.AspNet.FeatureModel": "1.0.0-*",
|
||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||
"Microsoft.AspNet.HttpFeature": "1.0.0-*",
|
||||
"Microsoft.AspNet.WebUtilities": "1.0.0-*"
|
||||
"Microsoft.AspNet.Http.Interfaces": "1.0.0-*",
|
||||
"Microsoft.AspNet.WebUtilities": "1.0.0-*",
|
||||
"Microsoft.Net.Http.Headers": "1.0.0-*"
|
||||
|
||||
},
|
||||
"frameworks": {
|
||||
"aspnet50": {},
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNet.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="IFormFile"/>.
|
||||
/// </summary>
|
||||
public static class FormFileExtensions
|
||||
{
|
||||
// Stream.CopyTo method uses 80KB as the default buffer size.
|
||||
private static int DefaultBufferSize = 80 * 1024;
|
||||
|
||||
/// <summary>
|
||||
/// Saves the contents of an uploaded file.
|
||||
/// </summary>
|
||||
/// <param name="formFile">The <see cref="IFormFile"/>.</param>
|
||||
/// <param name="filename">The name of the file to create.</param>
|
||||
public static void SaveAs([NotNull] this IFormFile formFile, string filename)
|
||||
{
|
||||
using (var fileStream = new FileStream(filename, FileMode.Create))
|
||||
{
|
||||
var inputStream = formFile.OpenReadStream();
|
||||
inputStream.CopyTo(fileStream);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously saves the contents of an uploaded file.
|
||||
/// </summary>
|
||||
/// <param name="formFile">The <see cref="IFormFile"/>.</param>
|
||||
/// <param name="filename">The name of the file to create.</param>
|
||||
public async static Task SaveAsAsync([NotNull] this IFormFile formFile,
|
||||
string filename,
|
||||
CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
using (var fileStream = new FileStream(filename, FileMode.Create))
|
||||
{
|
||||
var inputStream = formFile.OpenReadStream();
|
||||
await inputStream.CopyToAsync(fileStream, DefaultBufferSize, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNet.Http.Headers;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNet.Http
|
||||
{
|
||||
public static class HeaderDictionaryTypeExtensions
|
||||
{
|
||||
public static RequestHeaders GetTypedHeaders(this HttpRequest request)
|
||||
{
|
||||
return new RequestHeaders(request.Headers);
|
||||
}
|
||||
|
||||
public static ResponseHeaders GetTypedHeaders(this HttpResponse response)
|
||||
{
|
||||
return new ResponseHeaders(response.Headers);
|
||||
}
|
||||
|
||||
public static DateTimeOffset? GetDate([NotNull] this IHeaderDictionary headers, [NotNull] string name)
|
||||
{
|
||||
return headers.Get<DateTimeOffset?>(name);
|
||||
}
|
||||
|
||||
public static void Set([NotNull] this IHeaderDictionary headers, [NotNull] string name, object value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
headers.Remove(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
headers[name] = value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetList<T>([NotNull] this IHeaderDictionary headers, [NotNull] string name, IList<T> values)
|
||||
{
|
||||
if (values == null || values.Count == 0)
|
||||
{
|
||||
headers.Remove(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
headers.SetValues(name, values.Select(value => value.ToString()).ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetDate([NotNull] this IHeaderDictionary headers, [NotNull] string name, DateTimeOffset? value)
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
headers[name] = HeaderUtilities.FormatDate(value.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
headers.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Append([NotNull] this IHeaderDictionary headers, [NotNull] string name, [NotNull] object value)
|
||||
{
|
||||
headers.Append(name, value.ToString());
|
||||
}
|
||||
|
||||
public static void AppendList<T>([NotNull] this IHeaderDictionary headers, [NotNull] string name, [NotNull] IList<T> values)
|
||||
{
|
||||
headers.AppendValues(name, values.Select(value => value.ToString()).ToArray());
|
||||
}
|
||||
|
||||
private static IDictionary<Type, object> KnownParsers = new Dictionary<Type, object>()
|
||||
{
|
||||
{ typeof(CacheControlHeaderValue), new Func<string, CacheControlHeaderValue>(value => { CacheControlHeaderValue result; return CacheControlHeaderValue.TryParse(value, out result) ? result : null; }) },
|
||||
{ typeof(ContentDispositionHeaderValue), new Func<string, ContentDispositionHeaderValue>(value => { ContentDispositionHeaderValue result; return ContentDispositionHeaderValue.TryParse(value, out result) ? result : null; }) },
|
||||
{ typeof(ContentRangeHeaderValue), new Func<string, ContentRangeHeaderValue>(value => { ContentRangeHeaderValue result; return ContentRangeHeaderValue.TryParse(value, out result) ? result : null; }) },
|
||||
{ typeof(MediaTypeHeaderValue), new Func<string, MediaTypeHeaderValue>(value => { MediaTypeHeaderValue result; return MediaTypeHeaderValue.TryParse(value, out result) ? result : null; }) },
|
||||
{ typeof(RangeConditionHeaderValue), new Func<string, RangeConditionHeaderValue>(value => { RangeConditionHeaderValue result; return RangeConditionHeaderValue.TryParse(value, out result) ? result : null; }) },
|
||||
{ typeof(RangeHeaderValue), new Func<string, RangeHeaderValue>(value => { RangeHeaderValue result; return RangeHeaderValue.TryParse(value, out result) ? result : null; }) },
|
||||
{ typeof(EntityTagHeaderValue), new Func<string, EntityTagHeaderValue>(value => { EntityTagHeaderValue result; return EntityTagHeaderValue.TryParse(value, out result) ? result : null; }) },
|
||||
{ typeof(DateTimeOffset?), new Func<string, DateTimeOffset?>(value => { DateTimeOffset result; return HeaderUtilities.TryParseDate(value, out result) ? result : (DateTimeOffset?)null; }) },
|
||||
{ typeof(long?), new Func<string, long?>(value => { long result; return HeaderUtilities.TryParseInt64(value, out result) ? result : (long?)null; }) },
|
||||
};
|
||||
|
||||
private static IDictionary<Type, object> KnownListParsers = new Dictionary<Type, object>()
|
||||
{
|
||||
{ typeof(MediaTypeHeaderValue), new Func<IList<string>, IList<MediaTypeHeaderValue>>(value => { IList<MediaTypeHeaderValue> result; return MediaTypeHeaderValue.TryParseList(value, out result) ? result : null; }) },
|
||||
{ typeof(StringWithQualityHeaderValue), new Func<IList<string>, IList<StringWithQualityHeaderValue>>(value => { IList<StringWithQualityHeaderValue> result; return StringWithQualityHeaderValue.TryParseList(value, out result) ? result : null; }) },
|
||||
{ typeof(CookieHeaderValue), new Func<IList<string>, IList<CookieHeaderValue>>(value => { IList<CookieHeaderValue> result; return CookieHeaderValue.TryParseList(value, out result) ? result : null; }) },
|
||||
{ typeof(EntityTagHeaderValue), new Func<IList<string>, IList<EntityTagHeaderValue>>(value => { IList<EntityTagHeaderValue> result; return EntityTagHeaderValue.TryParseList(value, out result) ? result : null; }) },
|
||||
{ typeof(SetCookieHeaderValue), new Func<IList<string>, IList<SetCookieHeaderValue>>(value => { IList<SetCookieHeaderValue> result; return SetCookieHeaderValue.TryParseList(value, out result) ? result : null; }) },
|
||||
};
|
||||
|
||||
public static T Get<T>([NotNull] this IHeaderDictionary headers, string name)
|
||||
{
|
||||
object temp;
|
||||
if (KnownParsers.TryGetValue(typeof(T), out temp))
|
||||
{
|
||||
var func = (Func<string, T>)temp;
|
||||
return func(headers[name]);
|
||||
}
|
||||
|
||||
var value = headers[name];
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
return GetViaReflection<T>(value);
|
||||
}
|
||||
|
||||
public static IList<T> GetList<T>([NotNull] this IHeaderDictionary headers, string name)
|
||||
{
|
||||
object temp;
|
||||
if (KnownListParsers.TryGetValue(typeof(T), out temp))
|
||||
{
|
||||
var func = (Func<IList<string>, IList<T>>)temp;
|
||||
return func(headers.GetValues(name));
|
||||
}
|
||||
|
||||
var values = headers.GetValues(name);
|
||||
if (values == null || !values.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return GetListViaReflection<T>(values);
|
||||
}
|
||||
|
||||
private static T GetViaReflection<T>(string value)
|
||||
{
|
||||
// TODO: Cache the reflected type for later? Only if success?
|
||||
var type = typeof(T);
|
||||
var method = type.GetMethods(BindingFlags.Public | BindingFlags.Static)
|
||||
.Where(methodInfo =>
|
||||
{
|
||||
if (string.Equals("TryParse", methodInfo.Name, StringComparison.Ordinal)
|
||||
&& methodInfo.ReturnParameter.ParameterType.Equals(typeof(bool)))
|
||||
{
|
||||
var methodParams = methodInfo.GetParameters();
|
||||
return methodParams.Length == 2
|
||||
&& methodParams[0].ParameterType.Equals(typeof(string))
|
||||
&& methodParams[1].IsOut
|
||||
&& methodParams[1].ParameterType.Equals(type.MakeByRefType());
|
||||
}
|
||||
return false;
|
||||
}).FirstOrDefault();
|
||||
|
||||
if (method == null)
|
||||
{
|
||||
throw new NotSupportedException(string.Format(
|
||||
"The given type '{0}' does not have a TryParse method with the required signature 'public static bool TryParse(string, out {0}).", nameof(T)));
|
||||
}
|
||||
|
||||
var parameters = new object[] { value, null };
|
||||
var success = (bool)method.Invoke(null, parameters);
|
||||
if (success)
|
||||
{
|
||||
return (T)parameters[1];
|
||||
}
|
||||
return default(T);
|
||||
}
|
||||
|
||||
private static IList<T> GetListViaReflection<T>(IList<string> values)
|
||||
{
|
||||
// TODO: Cache the reflected type for later? Only if success?
|
||||
var type = typeof(T);
|
||||
var method = type.GetMethods(BindingFlags.Public | BindingFlags.Static)
|
||||
.Where(methodInfo =>
|
||||
{
|
||||
if (string.Equals("TryParseList", methodInfo.Name, StringComparison.Ordinal)
|
||||
&& methodInfo.ReturnParameter.ParameterType.Equals(typeof(Boolean)))
|
||||
{
|
||||
var methodParams = methodInfo.GetParameters();
|
||||
return methodParams.Length == 2
|
||||
&& methodParams[0].ParameterType.Equals(typeof(IList<string>))
|
||||
&& methodParams[1].IsOut
|
||||
&& methodParams[1].ParameterType.Equals(typeof(IList<T>).MakeByRefType());
|
||||
}
|
||||
return false;
|
||||
}).FirstOrDefault();
|
||||
|
||||
if (method == null)
|
||||
{
|
||||
throw new NotSupportedException(string.Format(
|
||||
"The given type '{0}' does not have a TryParseList method with the required signature 'public static bool TryParseList(IList<string>, out IList<{0}>).", nameof(T)));
|
||||
}
|
||||
|
||||
var parameters = new object[] { values, null };
|
||||
var success = (bool)method.Invoke(null, parameters);
|
||||
if (success)
|
||||
{
|
||||
return (IList<T>)parameters[1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
|
|
@ -14,4 +14,9 @@
|
|||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties project_1json__JSONSchema="http://www.asp.net/media/4878834/project.json" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
|
|
@ -5,9 +5,8 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
namespace Microsoft.AspNet.WebUtilities
|
||||
namespace Microsoft.AspNet.Http.Extensions
|
||||
{
|
||||
// The IEnumerable interface is required for the collection initialization syntax: new QueryBuilder() { { "key", "value" } };
|
||||
public class QueryBuilder : IEnumerable<KeyValuePair<string, string>>
|
||||
|
|
@ -0,0 +1,259 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Headers
|
||||
{
|
||||
public class RequestHeaders
|
||||
{
|
||||
public RequestHeaders([NotNull] IHeaderDictionary headers)
|
||||
{
|
||||
Headers = headers;
|
||||
}
|
||||
|
||||
public IHeaderDictionary Headers { get; private set; }
|
||||
|
||||
public IList<MediaTypeHeaderValue> Accept
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetList<MediaTypeHeaderValue>(HeaderNames.Accept);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetList(HeaderNames.Accept, value);
|
||||
}
|
||||
}
|
||||
|
||||
public IList<StringWithQualityHeaderValue> AcceptCharset
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetList<StringWithQualityHeaderValue>(HeaderNames.AcceptCharset);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetList(HeaderNames.AcceptCharset, value);
|
||||
}
|
||||
}
|
||||
|
||||
public IList<StringWithQualityHeaderValue> AcceptEncoding
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetList<StringWithQualityHeaderValue>(HeaderNames.AcceptEncoding);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetList(HeaderNames.AcceptEncoding, value);
|
||||
}
|
||||
}
|
||||
|
||||
public IList<StringWithQualityHeaderValue> AcceptLanguage
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetList<StringWithQualityHeaderValue>(HeaderNames.AcceptLanguage);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetList(HeaderNames.AcceptLanguage, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CacheControlHeaderValue CacheControl
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<CacheControlHeaderValue>(HeaderNames.CacheControl);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.CacheControl, value);
|
||||
}
|
||||
}
|
||||
|
||||
public ContentDispositionHeaderValue ContentDisposition
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<ContentDispositionHeaderValue>(HeaderNames.ContentDisposition);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.ContentDisposition, value);
|
||||
}
|
||||
}
|
||||
|
||||
public long? ContentLength
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<long?>(HeaderNames.ContentLength);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.ContentLength, value.HasValue ? HeaderUtilities.FormatInt64(value.Value) : null);
|
||||
}
|
||||
}
|
||||
|
||||
public ContentRangeHeaderValue ContentRange
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<ContentRangeHeaderValue>(HeaderNames.ContentRange);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.ContentRange, value);
|
||||
}
|
||||
}
|
||||
|
||||
public MediaTypeHeaderValue ContentType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<MediaTypeHeaderValue>(HeaderNames.ContentType);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.ContentType, value);
|
||||
}
|
||||
}
|
||||
|
||||
public IList<CookieHeaderValue> Cookie
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetList<CookieHeaderValue>(HeaderNames.Cookie);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetList(HeaderNames.Cookie, value);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTimeOffset? Date
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetDate(HeaderNames.Date);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetDate(HeaderNames.Date, value);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTimeOffset? Expires
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetDate(HeaderNames.Expires);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetDate(HeaderNames.Expires, value);
|
||||
}
|
||||
}
|
||||
|
||||
public HostString Host
|
||||
{
|
||||
get
|
||||
{
|
||||
return HostString.FromUriComponent(Headers[HeaderNames.Host]);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers[HeaderNames.Host] = value.ToUriComponent();
|
||||
}
|
||||
}
|
||||
|
||||
public IList<EntityTagHeaderValue> IfMatch
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetList<EntityTagHeaderValue>(HeaderNames.IfMatch);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetList(HeaderNames.IfMatch, value);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTimeOffset? IfModifiedSince
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetDate(HeaderNames.IfModifiedSince);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetDate(HeaderNames.IfModifiedSince, value);
|
||||
}
|
||||
}
|
||||
|
||||
public IList<EntityTagHeaderValue> IfNoneMatch
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetList<EntityTagHeaderValue>(HeaderNames.IfNoneMatch);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetList(HeaderNames.IfNoneMatch, value);
|
||||
}
|
||||
}
|
||||
|
||||
public RangeConditionHeaderValue IfRange
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<RangeConditionHeaderValue>(HeaderNames.IfRange);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.IfRange, value);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTimeOffset? IfUnmodifiedSince
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetDate(HeaderNames.IfUnmodifiedSince);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetDate(HeaderNames.IfUnmodifiedSince, value);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTimeOffset? LastModified
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetDate(HeaderNames.LastModified);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetDate(HeaderNames.LastModified, value);
|
||||
}
|
||||
}
|
||||
|
||||
public RangeHeaderValue Range
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<RangeHeaderValue>(HeaderNames.Range);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.Range, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http.Extensions;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Headers
|
||||
{
|
||||
public class ResponseHeaders
|
||||
{
|
||||
public ResponseHeaders([NotNull] IHeaderDictionary headers)
|
||||
{
|
||||
Headers = headers;
|
||||
}
|
||||
|
||||
public IHeaderDictionary Headers { get; private set; }
|
||||
|
||||
public CacheControlHeaderValue CacheControl
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<CacheControlHeaderValue>(HeaderNames.CacheControl);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.CacheControl, value);
|
||||
}
|
||||
}
|
||||
|
||||
public ContentDispositionHeaderValue ContentDisposition
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<ContentDispositionHeaderValue>(HeaderNames.ContentDisposition);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.ContentDisposition, value);
|
||||
}
|
||||
}
|
||||
|
||||
public long? ContentLength
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<long?>(HeaderNames.ContentLength);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.ContentLength, value.HasValue ? HeaderUtilities.FormatInt64(value.Value) : null);
|
||||
}
|
||||
}
|
||||
|
||||
public ContentRangeHeaderValue ContentRange
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<ContentRangeHeaderValue>(HeaderNames.ContentRange);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.ContentRange, value);
|
||||
}
|
||||
}
|
||||
|
||||
public MediaTypeHeaderValue ContentType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<MediaTypeHeaderValue>(HeaderNames.ContentType);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.ContentType, value);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTimeOffset? Date
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetDate(HeaderNames.Date);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetDate(HeaderNames.Date, value);
|
||||
}
|
||||
}
|
||||
|
||||
public EntityTagHeaderValue ETag
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.Get<EntityTagHeaderValue>(HeaderNames.ETag);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.ETag, value);
|
||||
}
|
||||
}
|
||||
public DateTimeOffset? Expires
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetDate(HeaderNames.Expires);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetDate(HeaderNames.Expires, value);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTimeOffset? LastModified
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetDate(HeaderNames.LastModified);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetDate(HeaderNames.LastModified, value);
|
||||
}
|
||||
}
|
||||
|
||||
public UriHelper Location
|
||||
{
|
||||
get
|
||||
{
|
||||
Uri uri;
|
||||
if (Uri.TryCreate(Headers[HeaderNames.Location], UriKind.RelativeOrAbsolute, out uri))
|
||||
{
|
||||
return new UriHelper(uri);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.Set(HeaderNames.Location, value);
|
||||
}
|
||||
}
|
||||
|
||||
public IList<SetCookieHeaderValue> SetCookie
|
||||
{
|
||||
get
|
||||
{
|
||||
return Headers.GetList<SetCookieHeaderValue>(HeaderNames.SetCookie);
|
||||
}
|
||||
set
|
||||
{
|
||||
Headers.SetList(HeaderNames.SetCookie, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Http;
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.WebUtilities
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper class for constructing encoded Uris for use in headers and other Uris.
|
||||
|
|
@ -44,6 +46,11 @@ namespace Microsoft.AspNet.WebUtilities
|
|||
|
||||
public FragmentString Fragment { get; set; }
|
||||
|
||||
public bool IsFullUri
|
||||
{
|
||||
get { return !string.IsNullOrEmpty(Scheme) && Host.HasValue; }
|
||||
}
|
||||
|
||||
// Always returns at least '/'
|
||||
public string GetPartialUri()
|
||||
{
|
||||
|
|
@ -67,6 +74,11 @@ namespace Microsoft.AspNet.WebUtilities
|
|||
return Scheme + "://" + Host + path + Query + Fragment;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return IsFullUri ? GetFullUri() : GetPartialUri();
|
||||
}
|
||||
|
||||
public static string Create(PathString pathBase,
|
||||
PathString path = new PathString(),
|
||||
QueryString query = new QueryString(),
|
||||
|
|
@ -3,12 +3,13 @@
|
|||
"description": "ASP.NET 5 common extension methods for HTTP abstractions and IApplicationBuilder.",
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||
"Microsoft.Framework.DependencyInjection": "1.0.0-*"
|
||||
"Microsoft.Framework.DependencyInjection": "1.0.0-*",
|
||||
"Microsoft.Net.Http.Headers": "1.0.0-*"
|
||||
},
|
||||
"frameworks" : {
|
||||
"aspnet50" : {
|
||||
},
|
||||
"aspnetcore50" : {
|
||||
"aspnetcore50" : {
|
||||
"dependencies": {
|
||||
"System.Reflection.TypeExtensions": "4.0.0-beta-*",
|
||||
"System.Runtime": "4.0.20-beta-*"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Threading;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IHttpApplicationFeature
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IHttpBufferingFeature
|
||||
|
|
@ -6,7 +6,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IHttpClientCertificateFeature
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Net;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IHttpConnectionFeature
|
||||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IHttpRequestFeature
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Threading;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IHttpRequestLifetimeFeature
|
||||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IHttpResponseFeature
|
||||
|
|
@ -5,7 +5,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IHttpSendFileFeature
|
||||
|
|
@ -5,7 +5,7 @@ using System.IO;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IHttpUpgradeFeature
|
||||
|
|
@ -5,7 +5,7 @@ using System.Net.WebSockets;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IHttpWebSocketFeature
|
||||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface ISession
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface ISessionFactory
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
// TODO: Is there any reason not to flatten the Factory down into the Feature?
|
||||
[AssemblyNeutral]
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature
|
||||
namespace Microsoft.AspNet.Http.Interfaces
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IWebSocketAcceptContext
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
|
|
@ -14,4 +14,9 @@
|
|||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties project_1json__JSONSchema="http://www.asp.net/media/4878834/project.json" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature.Security
|
||||
namespace Microsoft.AspNet.Http.Interfaces.Security
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IAuthTypeContext
|
||||
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||
using System.Security.Claims;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature.Security
|
||||
namespace Microsoft.AspNet.Http.Interfaces.Security
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IAuthenticateContext
|
||||
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature.Security
|
||||
namespace Microsoft.AspNet.Http.Interfaces.Security
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IAuthenticationHandler
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature.Security
|
||||
namespace Microsoft.AspNet.Http.Interfaces.Security
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IChallengeContext
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Security.Claims;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature.Security
|
||||
namespace Microsoft.AspNet.Http.Interfaces.Security
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface IHttpAuthenticationFeature
|
||||
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||
using System.Security.Claims;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature.Security
|
||||
namespace Microsoft.AspNet.Http.Interfaces.Security
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface ISignInContext
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.Framework.Runtime;
|
||||
|
||||
namespace Microsoft.AspNet.HttpFeature.Security
|
||||
namespace Microsoft.AspNet.Http.Interfaces.Security
|
||||
{
|
||||
[AssemblyNeutral]
|
||||
public interface ISignOutContext
|
||||
|
|
@ -90,12 +90,8 @@ namespace Microsoft.AspNet.Http
|
|||
/// </summary>
|
||||
/// <param name="uri">The Uri object</param>
|
||||
/// <returns>The resulting FragmentString</returns>
|
||||
public static FragmentString FromUriComponent(Uri uri)
|
||||
public static FragmentString FromUriComponent([NotNull] Uri uri)
|
||||
{
|
||||
if (uri == null)
|
||||
{
|
||||
throw new ArgumentNullException("uri");
|
||||
}
|
||||
string fragmentValue = uri.GetComponents(UriComponents.Fragment, UriFormat.UriEscaped);
|
||||
if (!string.IsNullOrEmpty(fragmentValue))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -134,12 +134,8 @@ namespace Microsoft.AspNet.Http
|
|||
/// </summary>
|
||||
/// <param name="uri"></param>
|
||||
/// <returns></returns>
|
||||
public static HostString FromUriComponent(Uri uri)
|
||||
public static HostString FromUriComponent([NotNull] Uri uri)
|
||||
{
|
||||
if (uri == null)
|
||||
{
|
||||
throw new ArgumentNullException("uri");
|
||||
}
|
||||
return new HostString(uri.GetComponents(
|
||||
UriComponents.NormalizedHost | // Always convert punycode to Unicode.
|
||||
UriComponents.HostAndPort, UriFormat.Unescaped));
|
||||
|
|
|
|||
|
|
@ -64,12 +64,6 @@ namespace Microsoft.AspNet.Http
|
|||
/// <returns>The query value collection parsed from owin.RequestQueryString.</returns>
|
||||
public abstract IReadableStringCollection Query { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the form collection.
|
||||
/// </summary>
|
||||
/// <returns>The form collection parsed from the request body.</returns>
|
||||
public abstract Task<IReadableStringCollection> GetFormAsync(CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
/// <summary>
|
||||
/// Gets or set the owin.RequestProtocol.
|
||||
/// </summary>
|
||||
|
|
@ -99,34 +93,26 @@ namespace Microsoft.AspNet.Http
|
|||
/// <returns>The Content-Type header.</returns>
|
||||
public abstract string ContentType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Cache-Control header.
|
||||
/// </summary>
|
||||
/// <returns>The Cache-Control header.</returns>
|
||||
// (TODO header conventions?) public abstract string CacheControl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Media-Type header.
|
||||
/// </summary>
|
||||
/// <returns>The Media-Type header.</returns>
|
||||
// (TODO header conventions?) public abstract string MediaType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or set the Accept header.
|
||||
/// </summary>
|
||||
/// <returns>The Accept header.</returns>
|
||||
public abstract string Accept { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or set the Accept-Charset header.
|
||||
/// </summary>
|
||||
/// <returns>The Accept-Charset header.</returns>
|
||||
public abstract string AcceptCharset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or set the owin.RequestBody Stream.
|
||||
/// </summary>
|
||||
/// <returns>The owin.RequestBody Stream.</returns>
|
||||
public abstract Stream Body { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Checks the content-type header for form types.
|
||||
/// </summary>
|
||||
public abstract bool HasFormContentType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the request body as a form.
|
||||
/// </summary>
|
||||
public abstract IFormCollection Form { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reads the request body if it is a form.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract Task<IFormCollection> ReadFormAsync(CancellationToken cancellationToken = new CancellationToken());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Http
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -8,5 +10,6 @@ namespace Microsoft.AspNet.Http
|
|||
/// </summary>
|
||||
public interface IFormCollection : IReadableStringCollection
|
||||
{
|
||||
IFormFileCollection Files { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace Microsoft.AspNet.Http
|
||||
{
|
||||
public interface IFormFile
|
||||
{
|
||||
string ContentType { get; }
|
||||
|
||||
string ContentDisposition { get; }
|
||||
|
||||
IHeaderDictionary Headers { get; }
|
||||
|
||||
long Length { get; }
|
||||
|
||||
Stream OpenReadStream();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Http
|
||||
{
|
||||
public interface IFormFileCollection : IList<IFormFile>
|
||||
{
|
||||
IFormFile this[string name] { get; }
|
||||
|
||||
IFormFile GetFile(string name);
|
||||
|
||||
IList<IFormFile> GetFiles(string name);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
|
|
@ -14,4 +14,9 @@
|
|||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties project_1json__JSONSchema="http://www.asp.net/media/4878834/project.json" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
|
|
@ -86,12 +86,8 @@ namespace Microsoft.AspNet.Http
|
|||
/// </summary>
|
||||
/// <param name="uri">The Uri object</param>
|
||||
/// <returns>The resulting PathString</returns>
|
||||
public static PathString FromUriComponent(Uri uri)
|
||||
public static PathString FromUriComponent([NotNull] Uri uri)
|
||||
{
|
||||
if (uri == null)
|
||||
{
|
||||
throw new ArgumentNullException("uri");
|
||||
}
|
||||
// REVIEW: what is the exactly correct thing to do?
|
||||
return new PathString("/" + uri.GetComponents(UriComponents.Path, UriFormat.Unescaped));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,12 +102,8 @@ namespace Microsoft.AspNet.Http
|
|||
/// </summary>
|
||||
/// <param name="uri">The Uri object</param>
|
||||
/// <returns>The resulting QueryString</returns>
|
||||
public static QueryString FromUriComponent(Uri uri)
|
||||
public static QueryString FromUriComponent([NotNull] Uri uri)
|
||||
{
|
||||
if (uri == null)
|
||||
{
|
||||
throw new ArgumentNullException("uri");
|
||||
}
|
||||
string queryValue = uri.GetComponents(UriComponents.Query, UriFormat.UriEscaped);
|
||||
if (!string.IsNullOrEmpty(queryValue))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,16 +18,8 @@ namespace Microsoft.AspNet.Http.Security
|
|||
/// <param name="identity">Assigned to Identity. May be null.</param>
|
||||
/// <param name="properties">Assigned to Properties. Contains extra information carried along with the identity.</param>
|
||||
/// <param name="description">Assigned to Description. Contains information describing the authentication provider.</param>
|
||||
public AuthenticationResult(IIdentity identity, AuthenticationProperties properties, AuthenticationDescription description)
|
||||
public AuthenticationResult(IIdentity identity, [NotNull] AuthenticationProperties properties, [NotNull] AuthenticationDescription description)
|
||||
{
|
||||
if (properties == null)
|
||||
{
|
||||
throw new ArgumentNullException("properties");
|
||||
}
|
||||
if (description == null)
|
||||
{
|
||||
throw new ArgumentNullException("description");
|
||||
}
|
||||
if (identity != null)
|
||||
{
|
||||
Identity = identity as ClaimsIdentity ?? new ClaimsIdentity(identity);
|
||||
|
|
|
|||
|
|
@ -27,12 +27,8 @@ namespace Microsoft.AspNet.Http.Security
|
|||
/// Initializes a new instance of the <see cref="AuthenticationDescription"/> class
|
||||
/// </summary>
|
||||
/// <param name="properties"></param>
|
||||
public AuthenticationDescription(IDictionary<string, object> properties)
|
||||
public AuthenticationDescription([NotNull] IDictionary<string, object> properties)
|
||||
{
|
||||
if (properties == null)
|
||||
{
|
||||
throw new ArgumentNullException("properties");
|
||||
}
|
||||
Dictionary = properties;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
|
|
@ -14,4 +14,9 @@
|
|||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties project_1json__JSONSchema="http://www.asp.net/media/4878834/project.json" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.Owin
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
|
||||
internal sealed class NotNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -14,9 +14,9 @@ using System.Security.Principal;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.HttpFeature.Security;
|
||||
using Microsoft.AspNet.PipelineCore.Security;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
using Microsoft.AspNet.Http.Interfaces.Security;
|
||||
using Microsoft.AspNet.Http.Core.Security;
|
||||
|
||||
namespace Microsoft.AspNet.Owin
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.Owin;
|
||||
using Microsoft.AspNet.PipelineCore;
|
||||
using Microsoft.AspNet.Http.Core;
|
||||
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ using System.Security.Principal;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.HttpFeature.Security;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
using Microsoft.AspNet.Http.Interfaces.Security;
|
||||
|
||||
namespace Microsoft.AspNet.Owin
|
||||
{
|
||||
|
|
@ -294,7 +294,7 @@ namespace Microsoft.AspNet.Owin
|
|||
public bool ContainsKey(Type key)
|
||||
{
|
||||
// Does this type implement the requested interface?
|
||||
if (key.GetTypeInfo().IsAssignableFrom(this.GetType().GetTypeInfo()))
|
||||
if (key.GetTypeInfo().IsAssignableFrom(GetType().GetTypeInfo()))
|
||||
{
|
||||
// Check for conditional features
|
||||
if (key == typeof(IHttpSendFileFeature))
|
||||
|
|
@ -399,12 +399,8 @@ namespace Microsoft.AspNet.Owin
|
|||
return TryGetValue(item.Key, out result) && result.Equals(item.Value);
|
||||
}
|
||||
|
||||
public void CopyTo(KeyValuePair<Type, object>[] array, int arrayIndex)
|
||||
public void CopyTo([NotNull] KeyValuePair<Type, object>[] array, int arrayIndex)
|
||||
{
|
||||
if (array == null)
|
||||
{
|
||||
throw new ArgumentNullException("array");
|
||||
}
|
||||
if (arrayIndex < 0 || arrayIndex > array.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("arrayIndex", arrayIndex, string.Empty);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Net.WebSockets;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
|
||||
namespace Microsoft.AspNet.Owin
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
|
||||
namespace Microsoft.AspNet.Owin
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Net.WebSockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.Http.Interfaces;
|
||||
|
||||
namespace Microsoft.AspNet.Owin
|
||||
{
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ namespace Microsoft.AspNet.Owin
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("buffer");
|
||||
throw new ArgumentOutOfRangeException(nameof(buffer));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +149,7 @@ namespace Microsoft.AspNet.Owin
|
|||
case 0x8:
|
||||
return WebSocketMessageType.Close;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("messageType", messageType, string.Empty);
|
||||
throw new ArgumentOutOfRangeException(nameof(messageType), messageType, string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ namespace Microsoft.AspNet.Owin
|
|||
case WebSocketMessageType.Close:
|
||||
return 0x8;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("webSocketMessageType", webSocketMessageType, string.Empty);
|
||||
throw new ArgumentOutOfRangeException(nameof(webSocketMessageType), webSocketMessageType, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
"dependencies": {
|
||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||
"Microsoft.AspNet.FeatureModel": "1.0.0-*",
|
||||
"Microsoft.AspNet.PipelineCore": "1.0.0-*",
|
||||
"Microsoft.AspNet.HttpFeature": { "version": "1.0.0-*", "type": "build" }
|
||||
"Microsoft.AspNet.Http.Core": "1.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"aspnet50": { },
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue