├── .appveyor.yml
├── .gitattributes
├── .github
└── ISSUE_TEMPLATE.md
├── .gitignore
├── .travis.yml
├── .vsts-pipelines
└── builds
│ ├── ci-internal.yml
│ └── ci-public.yml
├── CONTRIBUTING.md
├── Directory.Build.props
├── Directory.Build.targets
├── HttpAbstractions.sln
├── LICENSE.txt
├── NuGet.config
├── NuGetPackageVerifier.json
├── README.md
├── benchmarks
└── Microsoft.AspNetCore.Http.Performance
│ ├── Microsoft.AspNetCore.Http.Performance.csproj
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── RouteValueDictionaryBenchmark.cs
│ └── StreamPipeWriterBenchmark.cs
├── build.cmd
├── build.sh
├── build
├── Key.snk
├── dependencies.props
├── repo.props
└── sources.props
├── korebuild-lock.txt
├── korebuild.json
├── run.cmd
├── run.ps1
├── run.sh
├── samples
└── SampleApp
│ ├── PooledHttpContext.cs
│ ├── PooledHttpContextFactory.cs
│ ├── Program.cs
│ └── SampleApp.csproj
├── src
├── Directory.Build.props
├── Microsoft.AspNetCore.Authentication.Abstractions
│ ├── AuthenticateResult.cs
│ ├── AuthenticationHttpContextExtensions.cs
│ ├── AuthenticationOptions.cs
│ ├── AuthenticationProperties.cs
│ ├── AuthenticationScheme.cs
│ ├── AuthenticationSchemeBuilder.cs
│ ├── AuthenticationTicket.cs
│ ├── AuthenticationToken.cs
│ ├── IAuthenticationFeature.cs
│ ├── IAuthenticationHandler.cs
│ ├── IAuthenticationHandlerProvider.cs
│ ├── IAuthenticationRequestHandler.cs
│ ├── IAuthenticationSchemeProvider.cs
│ ├── IAuthenticationService.cs
│ ├── IAuthenticationSignInHandler.cs
│ ├── IAuthenticationSignOutHandler.cs
│ ├── IClaimsTransformation.cs
│ ├── Microsoft.AspNetCore.Authentication.Abstractions.csproj
│ ├── TokenExtensions.cs
│ └── baseline.netcore.json
├── Microsoft.AspNetCore.Authentication.Core
│ ├── AuthenticationCoreServiceCollectionExtensions.cs
│ ├── AuthenticationFeature.cs
│ ├── AuthenticationHandlerProvider.cs
│ ├── AuthenticationSchemeProvider.cs
│ ├── AuthenticationService.cs
│ ├── Microsoft.AspNetCore.Authentication.Core.csproj
│ ├── NoopClaimsTransformation.cs
│ └── baseline.netcore.json
├── Microsoft.AspNetCore.Http.Abstractions
│ ├── Authentication
│ │ ├── AuthenticateInfo.cs
│ │ ├── AuthenticationDescription.cs
│ │ ├── AuthenticationManager.cs
│ │ └── AuthenticationProperties.cs
│ ├── ConnectionInfo.cs
│ ├── CookieBuilder.cs
│ ├── CookieSecurePolicy.cs
│ ├── Extensions
│ │ ├── HeaderDictionaryExtensions.cs
│ │ ├── HttpResponseWritingExtensions.cs
│ │ ├── MapExtensions.cs
│ │ ├── MapMiddleware.cs
│ │ ├── MapOptions.cs
│ │ ├── MapWhenExtensions.cs
│ │ ├── MapWhenMiddleware.cs
│ │ ├── MapWhenOptions.cs
│ │ ├── ResponseTrailerExtensions.cs
│ │ ├── RunExtensions.cs
│ │ ├── UseExtensions.cs
│ │ ├── UseMiddlewareExtensions.cs
│ │ ├── UsePathBaseExtensions.cs
│ │ ├── UsePathBaseMiddleware.cs
│ │ └── UseWhenExtensions.cs
│ ├── FragmentString.cs
│ ├── HostString.cs
│ ├── HttpContext.cs
│ ├── HttpMethods.cs
│ ├── HttpRequest.cs
│ ├── HttpResponse.cs
│ ├── IApplicationBuilder.cs
│ ├── IHttpContextAccessor.cs
│ ├── IHttpContextFactory.cs
│ ├── IMiddleware.cs
│ ├── IMiddlewareFactory.cs
│ ├── Internal
│ │ ├── HeaderSegment.cs
│ │ ├── HeaderSegmentCollection.cs
│ │ ├── HostStringHelper.cs
│ │ ├── ParsingHelpers.cs
│ │ └── PathStringHelper.cs
│ ├── Microsoft.AspNetCore.Http.Abstractions.csproj
│ ├── PathString.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ └── Resources.Designer.cs
│ ├── QueryString.cs
│ ├── RequestDelegate.cs
│ ├── Resources.resx
│ ├── Routing
│ │ ├── Endpoint.cs
│ │ ├── EndpointHttpContextExtensions.cs
│ │ ├── EndpointMetadataCollection.cs
│ │ ├── IEndpointFeature.cs
│ │ ├── IRouteValuesFeature.cs
│ │ └── RouteValueDictionary.cs
│ ├── StatusCodes.cs
│ ├── WebSocketManager.cs
│ └── baseline.netcore.json
├── Microsoft.AspNetCore.Http.Extensions
│ ├── HeaderDictionaryTypeExtensions.cs
│ ├── HttpRequestMultipartExtensions.cs
│ ├── Microsoft.AspNetCore.Http.Extensions.csproj
│ ├── QueryBuilder.cs
│ ├── RequestHeaders.cs
│ ├── ResponseExtensions.cs
│ ├── ResponseHeaders.cs
│ ├── SendFileResponseExtensions.cs
│ ├── SessionExtensions.cs
│ ├── StreamCopyOperation.cs
│ ├── UriHelper.cs
│ └── baseline.netcore.json
├── Microsoft.AspNetCore.Http.Features
│ ├── Authentication
│ │ ├── AuthenticateContext.cs
│ │ ├── ChallengeBehavior.cs
│ │ ├── ChallengeContext.cs
│ │ ├── DescribeSchemesContext.cs
│ │ ├── IAuthenticationHandler.cs
│ │ ├── IHttpAuthenticationFeature.cs
│ │ ├── SignInContext.cs
│ │ └── SignOutContext.cs
│ ├── CookieOptions.cs
│ ├── FeatureCollection.cs
│ ├── FeatureReference.cs
│ ├── FeatureReferences.cs
│ ├── IFeatureCollection.cs
│ ├── IFormCollection.cs
│ ├── IFormFeature.cs
│ ├── IFormFile.cs
│ ├── IFormFileCollection.cs
│ ├── IHeaderDictionary.cs
│ ├── IHttpBodyControlFeature.cs
│ ├── IHttpBufferingFeature.cs
│ ├── IHttpConnectionFeature.cs
│ ├── IHttpMaxRequestBodySizeFeature.cs
│ ├── IHttpRequestFeature.cs
│ ├── IHttpRequestIdentifierFeature.cs
│ ├── IHttpRequestLifetimeFeature.cs
│ ├── IHttpResponseFeature.cs
│ ├── IHttpResponseTrailersFeature.cs
│ ├── IHttpSendFileFeature.cs
│ ├── IHttpUpgradeFeature.cs
│ ├── IHttpWebSocketFeature.cs
│ ├── IItemsFeature.cs
│ ├── IQueryCollection.cs
│ ├── IQueryFeature.cs
│ ├── IRequestCookieCollection.cs
│ ├── IRequestCookiesFeature.cs
│ ├── IResponseCookies.cs
│ ├── IResponseCookiesFeature.cs
│ ├── IServiceProvidersFeature.cs
│ ├── ISession.cs
│ ├── ISessionFeature.cs
│ ├── ITlsConnectionFeature.cs
│ ├── ITlsTokenBindingFeature.cs
│ ├── ITrackingConsentFeature.cs
│ ├── Microsoft.AspNetCore.Http.Features.csproj
│ ├── SameSiteMode.cs
│ ├── WebSocketAcceptContext.cs
│ └── baseline.netcore.json
├── Microsoft.AspNetCore.Http
│ ├── Authentication
│ │ └── DefaultAuthenticationManager.cs
│ ├── DefaultHttpContext.cs
│ ├── Extensions
│ │ └── HttpRequestRewindExtensions.cs
│ ├── Features
│ │ ├── Authentication
│ │ │ └── HttpAuthenticationFeature.cs
│ │ ├── DefaultSessionFeature.cs
│ │ ├── FormFeature.cs
│ │ ├── FormOptions.cs
│ │ ├── HttpConnectionFeature.cs
│ │ ├── HttpRequestFeature.cs
│ │ ├── HttpRequestIdentifierFeature.cs
│ │ ├── HttpRequestLifetimeFeature.cs
│ │ ├── HttpResponseFeature.cs
│ │ ├── ItemsFeature.cs
│ │ ├── QueryFeature.cs
│ │ ├── RequestCookiesFeature.cs
│ │ ├── ResponseCookiesFeature.cs
│ │ ├── RouteValuesFeature.cs
│ │ ├── ServiceProvidersFeature.cs
│ │ └── TlsConnectionFeature.cs
│ ├── FormCollection.cs
│ ├── HeaderDictionary.cs
│ ├── HttpContextAccessor.cs
│ ├── HttpContextFactory.cs
│ ├── HttpServiceCollectionExtensions.cs
│ ├── Internal
│ │ ├── ApplicationBuilder.cs
│ │ ├── BindingAddress.cs
│ │ ├── BufferingHelper.cs
│ │ ├── Constants.cs
│ │ ├── DefaultConnectionInfo.cs
│ │ ├── DefaultHttpRequest.cs
│ │ ├── DefaultHttpResponse.cs
│ │ ├── DefaultWebSocketManager.cs
│ │ ├── FormFile.cs
│ │ ├── FormFileCollection.cs
│ │ ├── ItemsDictionary.cs
│ │ ├── QueryCollection.cs
│ │ ├── ReferenceReadStream.cs
│ │ ├── RequestCookieCollection.cs
│ │ └── ResponseCookies.cs
│ ├── Microsoft.AspNetCore.Http.csproj
│ ├── MiddlewareFactory.cs
│ ├── RequestFormReaderExtensions.cs
│ ├── StreamPipeWriter.cs
│ └── baseline.netcore.json
├── Microsoft.AspNetCore.Owin
│ ├── DictionaryStringArrayWrapper.cs
│ ├── DictionaryStringValuesWrapper.cs
│ ├── IOwinEnvironmentFeature.cs
│ ├── Microsoft.AspNetCore.Owin.csproj
│ ├── OwinConstants.cs
│ ├── OwinEnvironment.cs
│ ├── OwinEnvironmentFeature.cs
│ ├── OwinExtensions.cs
│ ├── OwinFeatureCollection.cs
│ ├── Utilities.cs
│ ├── WebSockets
│ │ ├── OwinWebSocketAcceptAdapter.cs
│ │ ├── OwinWebSocketAcceptContext.cs
│ │ ├── OwinWebSocketAdapter.cs
│ │ ├── WebSocketAcceptAdapter.cs
│ │ └── WebSocketAdapter.cs
│ └── baseline.netcore.json
├── Microsoft.AspNetCore.WebUtilities
│ ├── Base64UrlTextEncoder.cs
│ ├── BufferedReadStream.cs
│ ├── FileBufferingReadStream.cs
│ ├── FileMultipartSection.cs
│ ├── FormMultipartSection.cs
│ ├── FormReader.cs
│ ├── HttpRequestStreamReader.cs
│ ├── HttpResponseStreamWriter.cs
│ ├── KeyValueAccumulator.cs
│ ├── Microsoft.AspNetCore.WebUtilities.csproj
│ ├── MultipartBoundary.cs
│ ├── MultipartReader.cs
│ ├── MultipartReaderStream.cs
│ ├── MultipartSection.cs
│ ├── MultipartSectionConverterExtensions.cs
│ ├── MultipartSectionStreamExtensions.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── QueryHelpers.cs
│ ├── ReasonPhrases.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── StreamHelperExtensions.cs
│ └── baseline.netcore.json
└── Microsoft.Net.Http.Headers
│ ├── BaseHeaderParser.cs
│ ├── CacheControlHeaderValue.cs
│ ├── ContentDispositionHeaderValue.cs
│ ├── ContentDispositionHeaderValueIdentityExtensions.cs
│ ├── ContentRangeHeaderValue.cs
│ ├── CookieHeaderParser.cs
│ ├── CookieHeaderValue.cs
│ ├── DateTimeFormatter.cs
│ ├── EntityTagHeaderValue.cs
│ ├── GenericHeaderParser.cs
│ ├── HeaderNames.cs
│ ├── HeaderQuality.cs
│ ├── HeaderUtilities.cs
│ ├── HttpHeaderParser.cs
│ ├── HttpParseResult.cs
│ ├── HttpRuleParser.cs
│ ├── MediaTypeHeaderValue.cs
│ ├── MediaTypeHeaderValueComparer.cs
│ ├── Microsoft.Net.Http.Headers.csproj
│ ├── NameValueHeaderValue.cs
│ ├── ObjectCollection.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── RangeConditionHeaderValue.cs
│ ├── RangeHeaderValue.cs
│ ├── RangeItemHeaderValue.cs
│ ├── SameSiteMode.cs
│ ├── SetCookieHeaderValue.cs
│ ├── StringWithQualityHeaderValue.cs
│ ├── StringWithQualityHeaderValueComparer.cs
│ └── baseline.netcore.json
├── test
├── Directory.Build.props
├── Microsoft.AspNetCore.Authentication.Core.Test
│ ├── AuthenticationPropertiesTests.cs
│ ├── AuthenticationSchemeProviderTests.cs
│ ├── AuthenticationServiceTests.cs
│ ├── Microsoft.AspNetCore.Authentication.Core.Test.csproj
│ └── TokenExtensionTests.cs
├── Microsoft.AspNetCore.Http.Abstractions.Tests
│ ├── CookieBuilderTests.cs
│ ├── EndpointHttpContextExtensionsTests.cs
│ ├── EndpointMetadataCollectionTests.cs
│ ├── FragmentStringTests.cs
│ ├── HostStringTest.cs
│ ├── HttpResponseWritingExtensionsTests.cs
│ ├── MapPathMiddlewareTests.cs
│ ├── MapPredicateMiddlewareTests.cs
│ ├── Microsoft.AspNetCore.Http.Abstractions.Tests.csproj
│ ├── PathStringTests.cs
│ ├── QueryStringTests.cs
│ ├── RouteValueDictionaryTests.cs
│ ├── UseMiddlewareTest.cs
│ ├── UsePathBaseExtensionsTests.cs
│ └── UseWhenExtensionsTests.cs
├── Microsoft.AspNetCore.Http.Extensions.Tests
│ ├── HeaderDictionaryTypeExtensionsTest.cs
│ ├── Microsoft.AspNetCore.Http.Extensions.Tests.csproj
│ ├── QueryBuilderTests.cs
│ ├── ResponseExtensionTests.cs
│ ├── SendFileResponseExtensionsTests.cs
│ └── UriHelperTests.cs
├── Microsoft.AspNetCore.Http.Features.Tests
│ ├── Authentication
│ │ └── AuthenticateContextTest.cs
│ ├── FeatureCollectionTests.cs
│ ├── IThing.cs
│ ├── Microsoft.AspNetCore.Http.Features.Tests.csproj
│ └── Thing.cs
├── Microsoft.AspNetCore.Http.Tests
│ ├── Authentication
│ │ └── DefaultAuthenticationManagerTests.cs
│ ├── DefaultHttpContextTests.cs
│ ├── Features
│ │ ├── FakeResponseFeature.cs
│ │ ├── FormFeatureTests.cs
│ │ ├── HttpRequestIdentifierFeatureTests.cs
│ │ ├── NonSeekableReadStream.cs
│ │ └── QueryFeatureTests.cs
│ ├── FlushResultCancellationTests.cs
│ ├── HeaderDictionaryTests.cs
│ ├── HttpContextAccessorTests.cs
│ ├── HttpContextFactoryTests.cs
│ ├── HttpServiceCollectionExtensionsTests.cs
│ ├── Internal
│ │ ├── ApplicationBuilderTests.cs
│ │ ├── BindingAddressTests.cs
│ │ ├── BufferingHelperTests.cs
│ │ ├── DefaultHttpRequestTests.cs
│ │ └── DefaultHttpResponseTests.cs
│ ├── Microsoft.AspNetCore.Http.Tests.csproj
│ ├── PipeTest.cs
│ ├── PipeWriterTests.cs
│ ├── RequestCookiesCollectionTests.cs
│ ├── ResponseCookiesTest.cs
│ ├── StreamPipeWriterTests.cs
│ └── TestMemoryPool.cs
├── Microsoft.AspNetCore.Owin.Tests
│ ├── Microsoft.AspNetCore.Owin.Tests.csproj
│ ├── OwinEnvironmentTests.cs
│ ├── OwinExtensionTests.cs
│ └── OwinFeatureCollectionTests.cs
├── Microsoft.AspNetCore.WebUtilities.Tests
│ ├── FileBufferingReadStreamTests.cs
│ ├── FormReaderAsyncTest.cs
│ ├── FormReaderTests.cs
│ ├── HttpRequestStreamReaderTest.cs
│ ├── HttpResponseStreamWriterTest.cs
│ ├── Microsoft.AspNetCore.WebUtilities.Tests.csproj
│ ├── MultipartReaderTests.cs
│ ├── NonSeekableReadStream.cs
│ ├── QueryHelpersTests.cs
│ └── WebEncodersTests.cs
└── Microsoft.Net.Http.Headers.Tests
│ ├── CacheControlHeaderValueTest.cs
│ ├── ContentDispositionHeaderValueTest.cs
│ ├── ContentRangeHeaderValueTest.cs
│ ├── CookieHeaderValueTest.cs
│ ├── DateParserTest.cs
│ ├── EntityTagHeaderValueTest.cs
│ ├── HeaderUtilitiesTest.cs
│ ├── MediaTypeHeaderValueComparerTests.cs
│ ├── MediaTypeHeaderValueTest.cs
│ ├── Microsoft.Net.Http.Headers.Tests.csproj
│ ├── NameValueHeaderValueTest.cs
│ ├── RangeConditionHeaderValueTest.cs
│ ├── RangeHeaderValueTest.cs
│ ├── RangeItemHeaderValueTest.cs
│ ├── SetCookieHeaderValueTest.cs
│ ├── StringWithQualityHeaderValueComparerTest.cs
│ └── StringWithQualityHeaderValueTest.cs
└── version.props
/.appveyor.yml:
--------------------------------------------------------------------------------
1 | init:
2 | - git config --global core.autocrlf true
3 | branches:
4 | only:
5 | - master
6 | - /^release\/.*$/
7 | - /^(.*\/)?ci-.*$/
8 | build_script:
9 | - ps: .\run.ps1 default-build
10 | clone_depth: 1
11 | environment:
12 | global:
13 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
14 | DOTNET_CLI_TELEMETRY_OPTOUT: 1
15 | test: 'off'
16 | deploy: 'off'
17 | os: Visual Studio 2017
18 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.doc diff=astextplain
2 | *.DOC diff=astextplain
3 | *.docx diff=astextplain
4 | *.DOCX diff=astextplain
5 | *.dot diff=astextplain
6 | *.DOT diff=astextplain
7 | *.pdf diff=astextplain
8 | *.PDF diff=astextplain
9 | *.rtf diff=astextplain
10 | *.RTF diff=astextplain
11 |
12 | *.jpg binary
13 | *.png binary
14 | *.gif binary
15 |
16 | *.cs text=auto diff=csharp
17 | *.vb text=auto
18 | *.resx text=auto
19 | *.c text=auto
20 | *.cpp text=auto
21 | *.cxx text=auto
22 | *.h text=auto
23 | *.hxx text=auto
24 | *.py text=auto
25 | *.rb text=auto
26 | *.java text=auto
27 | *.html text=auto
28 | *.htm text=auto
29 | *.css text=auto
30 | *.scss text=auto
31 | *.sass text=auto
32 | *.less text=auto
33 | *.js text=auto
34 | *.lisp text=auto
35 | *.clj text=auto
36 | *.sql text=auto
37 | *.php text=auto
38 | *.lua text=auto
39 | *.m text=auto
40 | *.asm text=auto
41 | *.erl text=auto
42 | *.fs text=auto
43 | *.fsx text=auto
44 | *.hs text=auto
45 |
46 | *.csproj text=auto
47 | *.vbproj text=auto
48 | *.fsproj text=auto
49 | *.dbproj text=auto
50 | *.sln text=auto eol=crlf
51 |
52 | *.sh eol=lf
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | THIS ISSUE TRACKER IS CLOSED - please log new issues here: https://github.com/aspnet/Home/issues
2 |
3 | For information about this change, see https://github.com/aspnet/Announcements/issues/283
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | [Oo]bj/
2 | [Bb]in/
3 | TestResults/
4 | .nuget/
5 | _ReSharper.*/
6 | packages/
7 | artifacts/
8 | PublishProfiles/
9 | *.user
10 | *.suo
11 | *.cache
12 | *.docstates
13 | _ReSharper.*
14 | nuget.exe
15 | *net45.csproj
16 | *net451.csproj
17 | *k10.csproj
18 | *.psess
19 | *.vsp
20 | *.pidb
21 | *.userprefs
22 | *DS_Store
23 | *.ncrunchsolution
24 | *.*sdf
25 | *.ipch
26 | *.sln.ide
27 | project.lock.json
28 | .build/
29 | .testPublish/
30 | /.vs/
31 | .vscode/
32 | global.json
33 | BenchmarkDotNet.Artifacts/
34 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: csharp
2 | sudo: false
3 | dist: trusty
4 | env:
5 | global:
6 | - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
7 | - DOTNET_CLI_TELEMETRY_OPTOUT: 1
8 | mono: none
9 | os:
10 | - linux
11 | - osx
12 | osx_image: xcode8.2
13 | addons:
14 | apt:
15 | packages:
16 | - libunwind8
17 | branches:
18 | only:
19 | - master
20 | - /^release\/.*$/
21 | - /^(.*\/)?ci-.*$/
22 | before_install:
23 | - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s
24 | /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
25 | /usr/local/lib/; fi
26 | script:
27 | - ./build.sh
28 |
--------------------------------------------------------------------------------
/.vsts-pipelines/builds/ci-internal.yml:
--------------------------------------------------------------------------------
1 | trigger:
2 | - master
3 | - release/*
4 |
5 | resources:
6 | repositories:
7 | - repository: buildtools
8 | type: git
9 | name: aspnet-BuildTools
10 | ref: refs/heads/master
11 |
12 | phases:
13 | - template: .vsts-pipelines/templates/project-ci.yml@buildtools
14 |
--------------------------------------------------------------------------------
/.vsts-pipelines/builds/ci-public.yml:
--------------------------------------------------------------------------------
1 | trigger:
2 | - master
3 | - release/*
4 |
5 | # See https://github.com/aspnet/BuildTools
6 | resources:
7 | repositories:
8 | - repository: buildtools
9 | type: github
10 | endpoint: DotNet-Bot GitHub Connection
11 | name: aspnet/BuildTools
12 | ref: refs/heads/master
13 |
14 | phases:
15 | - template: .vsts-pipelines/templates/project-ci.yml@buildtools
16 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing
2 | ======
3 |
4 | Information on contributing to this repo is in the [Contributing Guide](https://github.com/aspnet/Home/blob/master/CONTRIBUTING.md) in the Home repo.
5 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Microsoft ASP.NET Core
12 | https://github.com/aspnet/HttpAbstractions
13 | git
14 | $(MSBuildThisFileDirectory)
15 | $(MSBuildThisFileDirectory)build\Key.snk
16 | true
17 | true
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(MicrosoftNETCoreApp20PackageVersion)
4 | $(MicrosoftNETCoreApp21PackageVersion)
5 | $(MicrosoftNETCoreApp22PackageVersion)
6 | $(NETStandardLibrary20PackageVersion)
7 |
8 | 99.9
9 |
10 |
11 |
--------------------------------------------------------------------------------
/NuGet.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/NuGetPackageVerifier.json:
--------------------------------------------------------------------------------
1 | {
2 | "Default": {
3 | "rules": [
4 | "DefaultCompositeRule"
5 | ]
6 | }
7 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | HttpAbstractions [Archived]
2 | ===========================
3 |
4 | **This GitHub project has been archived.** Ongoing development on this project can be found in https://github.com/aspnet/AspNetCore.
5 |
6 | Contains HTTP abstractions for ASP.NET Core such as `HttpContext`, `HttpRequest`, `HttpResponse` and `RequestDelegate`.
7 |
8 | It also contains `IApplicationBuilder` and extensions to create and compose your application's pipeline.
9 |
10 | This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the [AspNetCore](https://github.com/aspnet/AspNetCore) repo.
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/benchmarks/Microsoft.AspNetCore.Http.Performance/Microsoft.AspNetCore.Http.Performance.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.2
5 | Exe
6 | true
7 | true
8 | false
9 | Microsoft.AspNetCore.Http
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/benchmarks/Microsoft.AspNetCore.Http.Performance/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | [assembly: BenchmarkDotNet.Attributes.AspNetCoreBenchmark]
--------------------------------------------------------------------------------
/build.cmd:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 | PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' default-build %*; exit $LASTEXITCODE"
3 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -euo pipefail
4 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5 |
6 | # Call "sync" between "chmod" and execution to prevent "text file busy" error in Docker (aufs)
7 | chmod +x "$DIR/run.sh"; sync
8 | "$DIR/run.sh" default-build "$@"
9 |
--------------------------------------------------------------------------------
/build/Key.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aspnet/HttpAbstractions/bc7092a32b1943c7f17439e419d3f66cd94ce9bd/build/Key.snk
--------------------------------------------------------------------------------
/build/repo.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Internal.AspNetCore.Universe.Lineup
7 | https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | true
18 |
19 |
20 |
--------------------------------------------------------------------------------
/build/sources.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $(DotNetRestoreSources)
6 |
7 | $(RestoreSources);
8 | https://dotnet.myget.org/F/dotnet-core/api/v3/index.json;
9 | https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;
10 | https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json;
11 |
12 |
13 | $(RestoreSources);
14 | https://api.nuget.org/v3/index.json;
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/korebuild-lock.txt:
--------------------------------------------------------------------------------
1 | version:3.0.0-alpha1-20181004.7
2 | commithash:27fabdaf2b1d4753c3d2749581694ca65d78f7f2
3 |
--------------------------------------------------------------------------------
/korebuild.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/master/tools/korebuild.schema.json",
3 | "channel": "master"
4 | }
5 |
--------------------------------------------------------------------------------
/run.cmd:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 | PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' %*; exit $LASTEXITCODE"
3 |
--------------------------------------------------------------------------------
/samples/SampleApp/PooledHttpContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using Microsoft.AspNetCore.Http;
5 | using Microsoft.AspNetCore.Http.Features;
6 | using Microsoft.AspNetCore.Http.Internal;
7 |
8 | namespace SampleApp
9 | {
10 | public class PooledHttpContext : DefaultHttpContext
11 | {
12 | DefaultHttpRequest _pooledHttpRequest;
13 | DefaultHttpResponse _pooledHttpResponse;
14 |
15 | public PooledHttpContext(IFeatureCollection featureCollection) :
16 | base(featureCollection)
17 | {
18 | }
19 |
20 | protected override HttpRequest InitializeHttpRequest()
21 | {
22 | if (_pooledHttpRequest != null)
23 | {
24 | _pooledHttpRequest.Initialize(this);
25 | return _pooledHttpRequest;
26 | }
27 |
28 | return new DefaultHttpRequest(this);
29 | }
30 |
31 | protected override void UninitializeHttpRequest(HttpRequest instance)
32 | {
33 | _pooledHttpRequest = instance as DefaultHttpRequest;
34 | _pooledHttpRequest?.Uninitialize();
35 | }
36 |
37 | protected override HttpResponse InitializeHttpResponse()
38 | {
39 | if (_pooledHttpResponse != null)
40 | {
41 | _pooledHttpResponse.Initialize(this);
42 | return _pooledHttpResponse;
43 | }
44 |
45 | return new DefaultHttpResponse(this);
46 | }
47 |
48 | protected override void UninitializeHttpResponse(HttpResponse instance)
49 | {
50 | _pooledHttpResponse = instance as DefaultHttpResponse;
51 | _pooledHttpResponse?.Uninitialize();
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/samples/SampleApp/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.AspNetCore.Http;
3 | using Microsoft.AspNetCore.Http.Extensions;
4 |
5 | namespace SampleApp
6 | {
7 | public class Program
8 | {
9 | public static void Main(string[] args)
10 | {
11 | var query = new QueryBuilder()
12 | {
13 | { "hello", "world" }
14 | }.ToQueryString();
15 |
16 | var uri = UriHelper.BuildAbsolute("http", new HostString("contoso.com"), query: query);
17 |
18 | Console.WriteLine(uri);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/samples/SampleApp/SampleApp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.2;net461
5 | Exe
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticationScheme.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Reflection;
6 |
7 | namespace Microsoft.AspNetCore.Authentication
8 | {
9 | ///
10 | /// AuthenticationSchemes assign a name to a specific
11 | /// handlerType.
12 | ///
13 | public class AuthenticationScheme
14 | {
15 | ///
16 | /// Constructor.
17 | ///
18 | /// The name for the authentication scheme.
19 | /// The display name for the authentication scheme.
20 | /// The type that handles this scheme.
21 | public AuthenticationScheme(string name, string displayName, Type handlerType)
22 | {
23 | if (name == null)
24 | {
25 | throw new ArgumentNullException(nameof(name));
26 | }
27 | if (handlerType == null)
28 | {
29 | throw new ArgumentNullException(nameof(handlerType));
30 | }
31 | if (!typeof(IAuthenticationHandler).IsAssignableFrom(handlerType))
32 | {
33 | throw new ArgumentException("handlerType must implement IAuthenticationHandler.");
34 | }
35 |
36 | Name = name;
37 | HandlerType = handlerType;
38 | DisplayName = displayName;
39 | }
40 |
41 | ///
42 | /// The name of the authentication scheme.
43 | ///
44 | public string Name { get; }
45 |
46 | ///
47 | /// The display name for the scheme. Null is valid and used for non user facing schemes.
48 | ///
49 | public string DisplayName { get; }
50 |
51 | ///
52 | /// The type that handles this scheme.
53 | ///
54 | public Type HandlerType { get; }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticationSchemeBuilder.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 |
6 | namespace Microsoft.AspNetCore.Authentication
7 | {
8 | ///
9 | /// Used to build s.
10 | ///
11 | public class AuthenticationSchemeBuilder
12 | {
13 | ///
14 | /// Constructor.
15 | ///
16 | /// The name of the scheme being built.
17 | public AuthenticationSchemeBuilder(string name)
18 | {
19 | Name = name;
20 | }
21 |
22 | ///
23 | /// The name of the scheme being built.
24 | ///
25 | public string Name { get; }
26 |
27 | ///
28 | /// The display name for the scheme being built.
29 | ///
30 | public string DisplayName { get; set; }
31 |
32 | ///
33 | /// The type responsible for this scheme.
34 | ///
35 | public Type HandlerType { get; set; }
36 |
37 | ///
38 | /// Builds the instance.
39 | ///
40 | ///
41 | public AuthenticationScheme Build() => new AuthenticationScheme(Name, DisplayName, HandlerType);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticationToken.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 |
5 | namespace Microsoft.AspNetCore.Authentication
6 | {
7 | ///
8 | /// Name/Value representing a token.
9 | ///
10 | public class AuthenticationToken
11 | {
12 | ///
13 | /// Name.
14 | ///
15 | public string Name { get; set; }
16 |
17 | ///
18 | /// Value.
19 | ///
20 | public string Value { get; set; }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Abstractions/IAuthenticationFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using Microsoft.AspNetCore.Http;
5 |
6 | namespace Microsoft.AspNetCore.Authentication
7 | {
8 | ///
9 | /// Used to capture path info so redirects can be computed properly within an app.Map().
10 | ///
11 | public interface IAuthenticationFeature
12 | {
13 | ///
14 | /// The original path base.
15 | ///
16 | PathString OriginalPathBase { get; set; }
17 |
18 | ///
19 | /// The original path.
20 | ///
21 | PathString OriginalPath { get; set; }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Abstractions/IAuthenticationHandler.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Http;
6 |
7 | namespace Microsoft.AspNetCore.Authentication
8 | {
9 | ///
10 | /// Created per request to handle authentication for to a particular scheme.
11 | ///
12 | public interface IAuthenticationHandler
13 | {
14 | ///
15 | /// The handler should initialize anything it needs from the request and scheme here.
16 | ///
17 | /// The scheme.
18 | /// The context.
19 | ///
20 | Task InitializeAsync(AuthenticationScheme scheme, HttpContext context);
21 |
22 | ///
23 | /// Authentication behavior.
24 | ///
25 | /// The result.
26 | Task AuthenticateAsync();
27 |
28 | ///
29 | /// Challenge behavior.
30 | ///
31 | /// The that contains the extra meta-data arriving with the authentication.
32 | /// A task.
33 | Task ChallengeAsync(AuthenticationProperties properties);
34 |
35 | ///
36 | /// Forbid behavior.
37 | ///
38 | /// The that contains the extra meta-data arriving with the authentication.
39 | /// A task.
40 | Task ForbidAsync(AuthenticationProperties properties);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Abstractions/IAuthenticationHandlerProvider.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Http;
6 |
7 | namespace Microsoft.AspNetCore.Authentication
8 | {
9 | ///
10 | /// Provides the appropriate IAuthenticationHandler instance for the authenticationScheme and request.
11 | ///
12 | public interface IAuthenticationHandlerProvider
13 | {
14 | ///
15 | /// Returns the handler instance that will be used.
16 | ///
17 | /// The context.
18 | /// The name of the authentication scheme being handled.
19 | /// The handler instance.
20 | Task GetHandlerAsync(HttpContext context, string authenticationScheme);
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Abstractions/IAuthenticationRequestHandler.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Threading.Tasks;
5 |
6 | namespace Microsoft.AspNetCore.Authentication
7 | {
8 | ///
9 | /// Used to determine if a handler wants to participate in request processing.
10 | ///
11 | public interface IAuthenticationRequestHandler : IAuthenticationHandler
12 | {
13 | ///
14 | /// Returns true if request processing should stop.
15 | ///
16 | ///
17 | Task HandleRequestAsync();
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Abstractions/IAuthenticationSignInHandler.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Security.Claims;
5 | using System.Threading.Tasks;
6 |
7 | namespace Microsoft.AspNetCore.Authentication
8 | {
9 | ///
10 | /// Used to determine if a handler supports SignIn.
11 | ///
12 | public interface IAuthenticationSignInHandler : IAuthenticationSignOutHandler
13 | {
14 | ///
15 | /// Handle sign in.
16 | ///
17 | /// The user.
18 | /// The that contains the extra meta-data arriving with the authentication.
19 | /// A task.
20 | Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties properties);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Abstractions/IAuthenticationSignOutHandler.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Threading.Tasks;
5 |
6 | namespace Microsoft.AspNetCore.Authentication
7 | {
8 | ///
9 | /// Used to determine if a handler supports SignOut.
10 | ///
11 | public interface IAuthenticationSignOutHandler : IAuthenticationHandler
12 | {
13 | ///
14 | /// Signout behavior.
15 | ///
16 | /// The that contains the extra meta-data arriving with the authentication.
17 | /// A task.
18 | Task SignOutAsync(AuthenticationProperties properties);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Abstractions/IClaimsTransformation.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Security.Claims;
5 | using System.Threading.Tasks;
6 |
7 | namespace Microsoft.AspNetCore.Authentication
8 | {
9 | ///
10 | /// Used by the for claims transformation.
11 | ///
12 | public interface IClaimsTransformation
13 | {
14 | ///
15 | /// Provides a central transformation point to change the specified principal.
16 | /// Note: this will be run on each AuthenticateAsync call, so its safer to
17 | /// return a new ClaimsPrincipal if your transformation is not idempotent.
18 | ///
19 | /// The to transform.
20 | /// The transformed principal.
21 | Task TransformAsync(ClaimsPrincipal principal);
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Abstractions/Microsoft.AspNetCore.Authentication.Abstractions.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | ASP.NET Core common types used by the various authentication components.
4 | netstandard2.0
5 | $(NoWarn);CS1591
6 | true
7 | aspnetcore;authentication;security
8 | false
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Core/AuthenticationFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using Microsoft.AspNetCore.Http;
5 |
6 | namespace Microsoft.AspNetCore.Authentication
7 | {
8 | ///
9 | /// Used to capture path info so redirects can be computed properly within an app.Map().
10 | ///
11 | public class AuthenticationFeature : IAuthenticationFeature
12 | {
13 | ///
14 | /// The original path base.
15 | ///
16 | public PathString OriginalPathBase { get; set; }
17 |
18 | ///
19 | /// The original path.
20 | ///
21 | public PathString OriginalPath { get; set; }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Core/Microsoft.AspNetCore.Authentication.Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ASP.NET Core common types used by the various authentication middleware components.
5 | netstandard2.0
6 | $(NoWarn);CS1591
7 | true
8 | aspnetcore;authentication;security
9 | false
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Authentication.Core/NoopClaimsTransformation.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Security.Claims;
5 | using System.Threading.Tasks;
6 |
7 | namespace Microsoft.AspNetCore.Authentication
8 | {
9 | ///
10 | /// Default claims transformation is a no-op.
11 | ///
12 | public class NoopClaimsTransformation : IClaimsTransformation
13 | {
14 | ///
15 | /// Returns the principal unchanged.
16 | ///
17 | /// The user.
18 | /// The principal unchanged.
19 | public virtual Task TransformAsync(ClaimsPrincipal principal)
20 | {
21 | return Task.FromResult(principal);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Authentication/AuthenticateInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Security.Claims;
6 |
7 | namespace Microsoft.AspNetCore.Http.Authentication
8 | {
9 | ///
10 | /// Used to store the results of an Authenticate call.
11 | ///
12 | public class AuthenticateInfo
13 | {
14 | ///
15 | /// The .
16 | ///
17 | public ClaimsPrincipal Principal { get; set; }
18 |
19 | ///
20 | /// The .
21 | ///
22 | public AuthenticationProperties Properties { get; set; }
23 |
24 | ///
25 | /// The .
26 | ///
27 | public AuthenticationDescription Description { get; set; }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Authentication/AuthenticationDescription.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Globalization;
7 |
8 | namespace Microsoft.AspNetCore.Http.Authentication
9 | {
10 | ///
11 | /// Contains information describing an authentication provider.
12 | ///
13 | public class AuthenticationDescription
14 | {
15 | private const string DisplayNamePropertyKey = "DisplayName";
16 | private const string AuthenticationSchemePropertyKey = "AuthenticationScheme";
17 |
18 | ///
19 | /// Initializes a new instance of the class
20 | ///
21 | public AuthenticationDescription()
22 | : this(items: null)
23 | {
24 | }
25 |
26 | ///
27 | /// Initializes a new instance of the class
28 | ///
29 | ///
30 | public AuthenticationDescription(IDictionary items)
31 | {
32 | Items = items ?? new Dictionary(StringComparer.Ordinal); ;
33 | }
34 |
35 | ///
36 | /// Contains metadata about the authentication provider.
37 | ///
38 | public IDictionary Items { get; }
39 |
40 | ///
41 | /// Gets or sets the name used to reference the authentication middleware instance.
42 | ///
43 | public string AuthenticationScheme
44 | {
45 | get { return GetString(AuthenticationSchemePropertyKey); }
46 | set { Items[AuthenticationSchemePropertyKey] = value; }
47 | }
48 |
49 | ///
50 | /// Gets or sets the display name for the authentication provider.
51 | ///
52 | public string DisplayName
53 | {
54 | get { return GetString(DisplayNamePropertyKey); }
55 | set { Items[DisplayNamePropertyKey] = value; }
56 | }
57 |
58 | private string GetString(string name)
59 | {
60 | object value;
61 | if (Items.TryGetValue(name, out value))
62 | {
63 | return Convert.ToString(value, CultureInfo.InvariantCulture);
64 | }
65 | return null;
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/ConnectionInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Net;
5 | using System.Security.Cryptography.X509Certificates;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 |
9 | namespace Microsoft.AspNetCore.Http
10 | {
11 | public abstract class ConnectionInfo
12 | {
13 | ///
14 | /// Gets or sets a unique identifier to represent this connection.
15 | ///
16 | public abstract string Id { get; set; }
17 |
18 | public abstract IPAddress RemoteIpAddress { get; set; }
19 |
20 | public abstract int RemotePort { get; set; }
21 |
22 | public abstract IPAddress LocalIpAddress { get; set; }
23 |
24 | public abstract int LocalPort { get; set; }
25 |
26 | public abstract X509Certificate2 ClientCertificate { get; set; }
27 |
28 | public abstract Task GetClientCertificateAsync(CancellationToken cancellationToken = new CancellationToken());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/CookieSecurePolicy.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.AspNetCore.Http
5 | {
6 | ///
7 | /// Determines how cookie security properties are set.
8 | ///
9 | public enum CookieSecurePolicy
10 | {
11 | ///
12 | /// If the URI that provides the cookie is HTTPS, then the cookie will only be returned to the server on
13 | /// subsequent HTTPS requests. Otherwise if the URI that provides the cookie is HTTP, then the cookie will
14 | /// be returned to the server on all HTTP and HTTPS requests. This is the default value because it ensures
15 | /// HTTPS for all authenticated requests on deployed servers, and also supports HTTP for localhost development
16 | /// and for servers that do not have HTTPS support.
17 | ///
18 | SameAsRequest,
19 |
20 | ///
21 | /// Secure is always marked true. Use this value when your login page and all subsequent pages
22 | /// requiring the authenticated identity are HTTPS. Local development will also need to be done with HTTPS urls.
23 | ///
24 | Always,
25 |
26 | ///
27 | /// Secure is not marked true. Use this value when your login page is HTTPS, but other pages
28 | /// on the site which are HTTP also require authentication information. This setting is not recommended because
29 | /// the authentication information provided with an HTTP request may be observed and used by other computers
30 | /// on your local network or wireless connection.
31 | ///
32 | None,
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/MapExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.AspNetCore.Http;
6 | using Microsoft.AspNetCore.Builder.Extensions;
7 |
8 | namespace Microsoft.AspNetCore.Builder
9 | {
10 | ///
11 | /// Extension methods for the .
12 | ///
13 | public static class MapExtensions
14 | {
15 | ///
16 | /// Branches the request pipeline based on matches of the given request path. If the request path starts with
17 | /// the given path, the branch is executed.
18 | ///
19 | /// The instance.
20 | /// The request path to match.
21 | /// The branch to take for positive path matches.
22 | /// The instance.
23 | public static IApplicationBuilder Map(this IApplicationBuilder app, PathString pathMatch, Action configuration)
24 | {
25 | if (app == null)
26 | {
27 | throw new ArgumentNullException(nameof(app));
28 | }
29 |
30 | if (configuration == null)
31 | {
32 | throw new ArgumentNullException(nameof(configuration));
33 | }
34 |
35 | if (pathMatch.HasValue && pathMatch.Value.EndsWith("/", StringComparison.Ordinal))
36 | {
37 | throw new ArgumentException("The path must not end with a '/'", nameof(pathMatch));
38 | }
39 |
40 | // create branch
41 | var branchBuilder = app.New();
42 | configuration(branchBuilder);
43 | var branch = branchBuilder.Build();
44 |
45 | var options = new MapOptions
46 | {
47 | Branch = branch,
48 | PathMatch = pathMatch,
49 | };
50 | return app.Use(next => new MapMiddleware(next, options).Invoke);
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/MapOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using Microsoft.AspNetCore.Http;
5 |
6 | namespace Microsoft.AspNetCore.Builder.Extensions
7 | {
8 | ///
9 | /// Options for the .
10 | ///
11 | public class MapOptions
12 | {
13 | ///
14 | /// The path to match.
15 | ///
16 | public PathString PathMatch { get; set; }
17 |
18 | ///
19 | /// The branch taken for a positive match.
20 | ///
21 | public RequestDelegate Branch { get; set; }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/MapWhenExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.AspNetCore.Http;
6 | using Microsoft.AspNetCore.Builder.Extensions;
7 |
8 |
9 | namespace Microsoft.AspNetCore.Builder
10 | {
11 | using Predicate = Func;
12 |
13 | ///
14 | /// Extension methods for the .
15 | ///
16 | public static class MapWhenExtensions
17 | {
18 | ///
19 | /// Branches the request pipeline based on the result of the given predicate.
20 | ///
21 | ///
22 | /// Invoked with the request environment to determine if the branch should be taken
23 | /// Configures a branch to take
24 | ///
25 | public static IApplicationBuilder MapWhen(this IApplicationBuilder app, Predicate predicate, Action configuration)
26 | {
27 | if (app == null)
28 | {
29 | throw new ArgumentNullException(nameof(app));
30 | }
31 |
32 | if (predicate == null)
33 | {
34 | throw new ArgumentNullException(nameof(predicate));
35 | }
36 |
37 | if (configuration == null)
38 | {
39 | throw new ArgumentNullException(nameof(configuration));
40 | }
41 |
42 | // create branch
43 | var branchBuilder = app.New();
44 | configuration(branchBuilder);
45 | var branch = branchBuilder.Build();
46 |
47 | // put middleware in pipeline
48 | var options = new MapWhenOptions
49 | {
50 | Predicate = predicate,
51 | Branch = branch,
52 | };
53 | return app.Use(next => new MapWhenMiddleware(next, options).Invoke);
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/MapWhenMiddleware.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore.Http;
7 |
8 | namespace Microsoft.AspNetCore.Builder.Extensions
9 | {
10 | ///
11 | /// Represents a middleware that runs a sub-request pipeline when a given predicate is matched.
12 | ///
13 | public class MapWhenMiddleware
14 | {
15 | private readonly RequestDelegate _next;
16 | private readonly MapWhenOptions _options;
17 |
18 | ///
19 | /// Creates a new instance of .
20 | ///
21 | /// The delegate representing the next middleware in the request pipeline.
22 | /// The middleware options.
23 | public MapWhenMiddleware(RequestDelegate next, MapWhenOptions options)
24 | {
25 | if (next == null)
26 | {
27 | throw new ArgumentNullException(nameof(next));
28 | }
29 |
30 | if (options == null)
31 | {
32 | throw new ArgumentNullException(nameof(options));
33 | }
34 |
35 | _next = next;
36 | _options = options;
37 | }
38 |
39 | ///
40 | /// Executes the middleware.
41 | ///
42 | /// The for the current request.
43 | /// A task that represents the execution of this middleware.
44 | public async Task Invoke(HttpContext context)
45 | {
46 | if (context == null)
47 | {
48 | throw new ArgumentNullException(nameof(context));
49 | }
50 |
51 | if (_options.Predicate(context))
52 | {
53 | await _options.Branch(context);
54 | }
55 | else
56 | {
57 | await _next(context);
58 | }
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/MapWhenOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.AspNetCore.Http;
6 |
7 | namespace Microsoft.AspNetCore.Builder.Extensions
8 | {
9 | ///
10 | /// Options for the .
11 | ///
12 | public class MapWhenOptions
13 | {
14 | private Func _predicate;
15 |
16 | ///
17 | /// The user callback that determines if the branch should be taken.
18 | ///
19 | public Func Predicate
20 | {
21 | get
22 | {
23 | return _predicate;
24 | }
25 | set
26 | {
27 | if (value == null)
28 | {
29 | throw new ArgumentNullException(nameof(value));
30 | }
31 |
32 | _predicate = value;
33 | }
34 | }
35 |
36 | ///
37 | /// The branch taken for a positive match.
38 | ///
39 | public RequestDelegate Branch { get; set; }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/ResponseTrailerExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.AspNetCore.Http.Features;
6 | using Microsoft.Extensions.Primitives;
7 |
8 | namespace Microsoft.AspNetCore.Http
9 | {
10 | public static class ResponseTrailerExtensions
11 | {
12 | private const string Trailer = "Trailer";
13 |
14 | ///
15 | /// Adds the given trailer name to the 'Trailer' response header. This must happen before the response headers are sent.
16 | ///
17 | ///
18 | ///
19 | public static void DeclareTrailer(this HttpResponse response, string trailerName)
20 | {
21 | response.Headers.AppendCommaSeparatedValues(Trailer, trailerName);
22 | }
23 |
24 | ///
25 | /// Indicates if the server supports sending trailer headers for this response.
26 | ///
27 | ///
28 | ///
29 | public static bool SupportsTrailers(this HttpResponse response)
30 | {
31 | var feature = response.HttpContext.Features.Get();
32 | return feature?.Trailers != null && !feature.Trailers.IsReadOnly;
33 | }
34 |
35 | ///
36 | /// Adds the given trailer header to the trailers collection to be sent at the end of the response body.
37 | /// Check or an InvalidOperationException may be thrown.
38 | ///
39 | ///
40 | ///
41 | ///
42 | public static void AppendTrailer(this HttpResponse response, string trailerName, StringValues trailerValues)
43 | {
44 | var feature = response.HttpContext.Features.Get();
45 | if (feature?.Trailers == null || feature.Trailers.IsReadOnly)
46 | {
47 | throw new InvalidOperationException("Trailers are not supported for this response.");
48 | }
49 |
50 | feature.Trailers.Append(trailerName, trailerValues);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/RunExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.AspNetCore.Http;
6 |
7 | namespace Microsoft.AspNetCore.Builder
8 | {
9 | ///
10 | /// Extension methods for adding terminal middleware.
11 | ///
12 | public static class RunExtensions
13 | {
14 | ///
15 | /// Adds a terminal middleware delegate to the application's request pipeline.
16 | ///
17 | /// The instance.
18 | /// A delegate that handles the request.
19 | public static void Run(this IApplicationBuilder app, RequestDelegate handler)
20 | {
21 | if (app == null)
22 | {
23 | throw new ArgumentNullException(nameof(app));
24 | }
25 |
26 | if (handler == null)
27 | {
28 | throw new ArgumentNullException(nameof(handler));
29 | }
30 |
31 | app.Use(_ => handler);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/UseExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Threading.Tasks;
6 | using Microsoft.AspNetCore.Http;
7 |
8 | namespace Microsoft.AspNetCore.Builder
9 | {
10 | ///
11 | /// Extension methods for adding middleware.
12 | ///
13 | public static class UseExtensions
14 | {
15 | ///
16 | /// Adds a middleware delegate defined in-line to the application's request pipeline.
17 | ///
18 | /// The instance.
19 | /// A function that handles the request or calls the given next function.
20 | /// The instance.
21 | public static IApplicationBuilder Use(this IApplicationBuilder app, Func, Task> middleware)
22 | {
23 | return app.Use(next =>
24 | {
25 | return context =>
26 | {
27 | Func simpleNext = () => next(context);
28 | return middleware(context, simpleNext);
29 | };
30 | });
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/UsePathBaseExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.AspNetCore.Http;
6 | using Microsoft.AspNetCore.Builder.Extensions;
7 |
8 | namespace Microsoft.AspNetCore.Builder
9 | {
10 | ///
11 | /// Extension methods for .
12 | ///
13 | public static class UsePathBaseExtensions
14 | {
15 | ///
16 | /// Adds a middleware that extracts the specified path base from request path and postpend it to the request path base.
17 | ///
18 | /// The instance.
19 | /// The path base to extract.
20 | /// The instance.
21 | public static IApplicationBuilder UsePathBase(this IApplicationBuilder app, PathString pathBase)
22 | {
23 | if (app == null)
24 | {
25 | throw new ArgumentNullException(nameof(app));
26 | }
27 |
28 | // Strip trailing slashes
29 | pathBase = pathBase.Value?.TrimEnd('/');
30 | if (!pathBase.HasValue)
31 | {
32 | return app;
33 | }
34 |
35 | return app.UseMiddleware(pathBase);
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/IApplicationBuilder.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using Microsoft.AspNetCore.Http;
7 | using Microsoft.AspNetCore.Http.Features;
8 |
9 | namespace Microsoft.AspNetCore.Builder
10 | {
11 | ///
12 | /// Defines a class that provides the mechanisms to configure an application's request pipeline.
13 | ///
14 | public interface IApplicationBuilder
15 | {
16 | ///
17 | /// Gets or sets the that provides access to the application's service container.
18 | ///
19 | IServiceProvider ApplicationServices { get; set; }
20 |
21 | ///
22 | /// Gets the set of HTTP features the application's server provides.
23 | ///
24 | IFeatureCollection ServerFeatures { get; }
25 |
26 | ///
27 | /// Gets a key/value collection that can be used to share data between middleware.
28 | ///
29 | IDictionary Properties { get; }
30 |
31 | ///
32 | /// Adds a middleware delegate to the application's request pipeline.
33 | ///
34 | /// The middleware delegate.
35 | /// The .
36 | IApplicationBuilder Use(Func middleware);
37 |
38 | ///
39 | /// Creates a new that shares the of this
40 | /// .
41 | ///
42 | /// The new .
43 | IApplicationBuilder New();
44 |
45 | ///
46 | /// Builds the delegate used by this application to process HTTP requests.
47 | ///
48 | /// The request handling delegate.
49 | RequestDelegate Build();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/IHttpContextAccessor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.AspNetCore.Http
5 | {
6 | public interface IHttpContextAccessor
7 | {
8 | HttpContext HttpContext { get; set; }
9 | }
10 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/IHttpContextFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using Microsoft.AspNetCore.Http.Features;
5 |
6 | namespace Microsoft.AspNetCore.Http
7 | {
8 | public interface IHttpContextFactory
9 | {
10 | HttpContext Create(IFeatureCollection featureCollection);
11 | void Dispose(HttpContext httpContext);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/IMiddleware.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Threading.Tasks;
5 |
6 | namespace Microsoft.AspNetCore.Http
7 | {
8 | ///
9 | /// Defines middleware that can be added to the application's request pipeline.
10 | ///
11 | public interface IMiddleware
12 | {
13 | ///
14 | /// Request handling method.
15 | ///
16 | /// The for the current request.
17 | /// The delegate representing the remaining middleware in the request pipeline.
18 | /// A that represents the execution of this middleware.
19 | Task InvokeAsync(HttpContext context, RequestDelegate next);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/IMiddlewareFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace Microsoft.AspNetCore.Http
11 | {
12 | ///
13 | /// Provides methods to create middleware.
14 | ///
15 | public interface IMiddlewareFactory
16 | {
17 | ///
18 | /// Creates a middleware instance for each request.
19 | ///
20 | /// The concrete of the .
21 | /// The instance.
22 | IMiddleware Create(Type middlewareType);
23 |
24 | ///
25 | /// Releases a instance at the end of each request.
26 | ///
27 | /// The instance to release.
28 | void Release(IMiddleware middleware);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Internal/HeaderSegment.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.Extensions.Primitives;
6 |
7 | namespace Microsoft.AspNetCore.Http.Internal
8 | {
9 | public struct HeaderSegment : IEquatable
10 | {
11 | private readonly StringSegment _formatting;
12 | private readonly StringSegment _data;
13 |
14 | //
15 | // Initializes a new instance of the structure.
16 | //
17 | public HeaderSegment(StringSegment formatting, StringSegment data)
18 | {
19 | _formatting = formatting;
20 | _data = data;
21 | }
22 |
23 | public StringSegment Formatting
24 | {
25 | get { return _formatting; }
26 | }
27 |
28 | public StringSegment Data
29 | {
30 | get { return _data; }
31 | }
32 |
33 | public bool Equals(HeaderSegment other)
34 | {
35 | return _formatting.Equals(other._formatting) && _data.Equals(other._data);
36 | }
37 |
38 | public override bool Equals(object obj)
39 | {
40 | if (ReferenceEquals(null, obj))
41 | {
42 | return false;
43 | }
44 |
45 | return obj is HeaderSegment && Equals((HeaderSegment)obj);
46 | }
47 |
48 | public override int GetHashCode()
49 | {
50 | unchecked
51 | {
52 | return (_formatting.GetHashCode() * 397) ^ _data.GetHashCode();
53 | }
54 | }
55 |
56 | public static bool operator ==(HeaderSegment left, HeaderSegment right)
57 | {
58 | return left.Equals(right);
59 | }
60 |
61 | public static bool operator !=(HeaderSegment left, HeaderSegment right)
62 | {
63 | return !left.Equals(right);
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Internal/HostStringHelper.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.AspNetCore.Http.Internal
5 | {
6 | internal class HostStringHelper
7 | {
8 | // Allowed Characters:
9 | // A-Z, a-z, 0-9, .,
10 | // -, %, [, ], :
11 | // Above for IPV6
12 | private static bool[] SafeHostStringChars = {
13 | false, false, false, false, false, false, false, false, // 0x00 - 0x07
14 | false, false, false, false, false, false, false, false, // 0x08 - 0x0F
15 | false, false, false, false, false, false, false, false, // 0x10 - 0x17
16 | false, false, false, false, false, false, false, false, // 0x18 - 0x1F
17 | false, false, false, false, false, true, false, false, // 0x20 - 0x27
18 | false, false, false, false, false, true, true, false, // 0x28 - 0x2F
19 | true, true, true, true, true, true, true, true, // 0x30 - 0x37
20 | true, true, true, false, false, false, false, false, // 0x38 - 0x3F
21 | false, true, true, true, true, true, true, true, // 0x40 - 0x47
22 | true, true, true, true, true, true, true, true, // 0x48 - 0x4F
23 | true, true, true, true, true, true, true, true, // 0x50 - 0x57
24 | true, true, true, true, false, true, false, false, // 0x58 - 0x5F
25 | false, true, true, true, true, true, true, true, // 0x60 - 0x67
26 | true, true, true, true, true, true, true, true, // 0x68 - 0x6F
27 | true, true, true, true, true, true, true, true, // 0x70 - 0x77
28 | true, true, true, false, false, false, false, false, // 0x78 - 0x7F
29 | };
30 |
31 | public static bool IsSafeHostStringChar(char c)
32 | {
33 | return c < SafeHostStringChars.Length && SafeHostStringChars[c];
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Internal/PathStringHelper.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.AspNetCore.Http.Internal
5 | {
6 | internal class PathStringHelper
7 | {
8 | private static bool[] ValidPathChars = {
9 | false, false, false, false, false, false, false, false, // 0x00 - 0x07
10 | false, false, false, false, false, false, false, false, // 0x08 - 0x0F
11 | false, false, false, false, false, false, false, false, // 0x10 - 0x17
12 | false, false, false, false, false, false, false, false, // 0x18 - 0x1F
13 | false, true, false, false, true, false, true, true, // 0x20 - 0x27
14 | true, true, true, true, true, true, true, true, // 0x28 - 0x2F
15 | true, true, true, true, true, true, true, true, // 0x30 - 0x37
16 | true, true, true, true, false, true, false, false, // 0x38 - 0x3F
17 | true, true, true, true, true, true, true, true, // 0x40 - 0x47
18 | true, true, true, true, true, true, true, true, // 0x48 - 0x4F
19 | true, true, true, true, true, true, true, true, // 0x50 - 0x57
20 | true, true, true, false, false, false, false, true, // 0x58 - 0x5F
21 | false, true, true, true, true, true, true, true, // 0x60 - 0x67
22 | true, true, true, true, true, true, true, true, // 0x68 - 0x6F
23 | true, true, true, true, true, true, true, true, // 0x70 - 0x77
24 | true, true, true, false, false, false, true, false, // 0x78 - 0x7F
25 | };
26 |
27 | public static bool IsValidPathChar(char c)
28 | {
29 | return c < ValidPathChars.Length && ValidPathChars[c];
30 | }
31 |
32 | public static bool IsPercentEncodedChar(string str, int index)
33 | {
34 | return index < str.Length - 2
35 | && str[index] == '%'
36 | && IsHexadecimalChar(str[index + 1])
37 | && IsHexadecimalChar(str[index + 2]);
38 | }
39 |
40 | public static bool IsHexadecimalChar(char c)
41 | {
42 | return ('0' <= c && c <= '9')
43 | || ('A' <= c && c <= 'F')
44 | || ('a' <= c && c <= 'f');
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Microsoft.AspNetCore.Http.Abstractions.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ASP.NET Core HTTP object model for HTTP requests and responses and also common extension methods for registering middleware in an IApplicationBuilder.
6 | Commonly used types:
7 | Microsoft.AspNetCore.Builder.IApplicationBuilder
8 | Microsoft.AspNetCore.Http.HttpContext
9 | Microsoft.AspNetCore.Http.HttpRequest
10 | Microsoft.AspNetCore.Http.HttpResponse
11 | netstandard2.0
12 | true
13 | aspnetcore
14 | $(NoWarn);CS1591
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Runtime.CompilerServices;
5 |
6 | [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Http.Abstractions.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/RequestDelegate.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Threading.Tasks;
5 |
6 | namespace Microsoft.AspNetCore.Http
7 | {
8 | ///
9 | /// A function that can process an HTTP request.
10 | ///
11 | /// The for the request.
12 | /// A task that represents the completion of request processing.
13 | public delegate Task RequestDelegate(HttpContext context);
14 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Routing/Endpoint.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.AspNetCore.Http
5 | {
6 | ///
7 | /// Respresents a logical endpoint in an application.
8 | ///
9 | public class Endpoint
10 | {
11 | ///
12 | /// Creates a new instance of .
13 | ///
14 | /// The delegate used to process requests for the endpoint.
15 | ///
16 | /// The endpoint . May be null.
17 | ///
18 | ///
19 | /// The informational display name of the endpoint. May be null.
20 | ///
21 | public Endpoint(
22 | RequestDelegate requestDelegate,
23 | EndpointMetadataCollection metadata,
24 | string displayName)
25 | {
26 | // All are allowed to be null
27 | RequestDelegate = requestDelegate;
28 | Metadata = metadata ?? EndpointMetadataCollection.Empty;
29 | DisplayName = displayName;
30 | }
31 |
32 | ///
33 | /// Gets the informational display name of this endpoint.
34 | ///
35 | public string DisplayName { get; }
36 |
37 | ///
38 | /// Gets the collection of metadata associated with this endpoint.
39 | ///
40 | public EndpointMetadataCollection Metadata { get; }
41 |
42 | ///
43 | /// Gets the delegate used to process requests for the endpoint.
44 | ///
45 | public RequestDelegate RequestDelegate { get; }
46 |
47 | public override string ToString() => DisplayName ?? base.ToString();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Routing/EndpointHttpContextExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.AspNetCore.Http.Features;
6 |
7 | namespace Microsoft.AspNetCore.Http.Endpoints
8 | {
9 | ///
10 | /// Extension methods to expose Endpoint on HttpContext.
11 | ///
12 | public static class EndpointHttpContextExtensions
13 | {
14 | ///
15 | /// Extension method for getting the for the current request.
16 | ///
17 | /// The context.
18 | /// The .
19 | public static Endpoint GetEndpoint(this HttpContext context)
20 | {
21 | if (context == null)
22 | {
23 | throw new ArgumentNullException(nameof(context));
24 | }
25 |
26 | return context.Features.Get()?.Endpoint;
27 | }
28 |
29 | ///
30 | /// Extension method for setting the for the current request.
31 | ///
32 | /// The context.
33 | /// The .
34 | public static void SetEndpoint(this HttpContext context, Endpoint endpoint)
35 | {
36 | if (context == null)
37 | {
38 | throw new ArgumentNullException(nameof(context));
39 | }
40 |
41 | var feature = context.Features.Get();
42 |
43 | if (endpoint != null)
44 | {
45 | if (feature == null)
46 | {
47 | feature = new EndpointFeature();
48 | context.Features.Set(feature);
49 | }
50 |
51 | feature.Endpoint = endpoint;
52 | }
53 | else
54 | {
55 | if (feature == null)
56 | {
57 | // No endpoint to set and no feature on context. Do nothing
58 | return;
59 | }
60 |
61 | feature.Endpoint = null;
62 | }
63 | }
64 |
65 | private class EndpointFeature : IEndpointFeature
66 | {
67 | public Endpoint Endpoint { get; set; }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Routing/IEndpointFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.AspNetCore.Http.Features
5 | {
6 | ///
7 | /// A feature interface for endpoint routing. Use
8 | /// to access an instance associated with the current request.
9 | ///
10 | public interface IEndpointFeature
11 | {
12 | ///
13 | /// Gets or sets the selected for the current
14 | /// request.
15 | ///
16 | Endpoint Endpoint { get; set; }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/Routing/IRouteValuesFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using Microsoft.AspNetCore.Routing;
5 |
6 | namespace Microsoft.AspNetCore.Http.Features
7 | {
8 | ///
9 | /// A feature interface for routing values. Use
10 | /// to access the values associated with the current request.
11 | ///
12 | public interface IRouteValuesFeature
13 | {
14 | ///
15 | /// Gets or sets the associated with the currrent
16 | /// request.
17 | ///
18 | RouteValueDictionary RouteValues { get; set; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Abstractions/WebSocketManager.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Collections.Generic;
5 | using System.Net.WebSockets;
6 | using System.Threading.Tasks;
7 |
8 | namespace Microsoft.AspNetCore.Http
9 | {
10 | ///
11 | /// Manages the establishment of WebSocket connections for a specific HTTP request.
12 | ///
13 | public abstract class WebSocketManager
14 | {
15 | ///
16 | /// Gets a value indicating whether the request is a WebSocket establishment request.
17 | ///
18 | public abstract bool IsWebSocketRequest { get; }
19 |
20 | ///
21 | /// Gets the list of requested WebSocket sub-protocols.
22 | ///
23 | public abstract IList WebSocketRequestedProtocols { get; }
24 |
25 | ///
26 | /// Transitions the request to a WebSocket connection.
27 | ///
28 | /// A task representing the completion of the transition.
29 | public virtual Task AcceptWebSocketAsync()
30 | {
31 | return AcceptWebSocketAsync(subProtocol: null);
32 | }
33 |
34 | ///
35 | /// Transitions the request to a WebSocket connection using the specified sub-protocol.
36 | ///
37 | /// The sub-protocol to use.
38 | /// A task representing the completion of the transition.
39 | public abstract Task AcceptWebSocketAsync(string subProtocol);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Extensions/HttpRequestMultipartExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.Net.Http.Headers;
6 |
7 | namespace Microsoft.AspNetCore.Http.Extensions
8 | {
9 | public static class HttpRequestMultipartExtensions
10 | {
11 | public static string GetMultipartBoundary(this HttpRequest request)
12 | {
13 | if (request == null)
14 | {
15 | throw new ArgumentNullException(nameof(request));
16 | }
17 |
18 | MediaTypeHeaderValue mediaType;
19 | if (!MediaTypeHeaderValue.TryParse(request.ContentType, out mediaType))
20 | {
21 | return string.Empty;
22 | }
23 | return HeaderUtilities.RemoveQuotes(mediaType.Boundary).ToString();
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Extensions/Microsoft.AspNetCore.Http.Extensions.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ASP.NET Core common extension methods for HTTP abstractions, HTTP headers, HTTP request/response, and session state.
5 | netstandard2.0
6 | $(NoWarn);CS1591
7 | true
8 | aspnetcore
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Extensions/ResponseExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.AspNetCore.Http.Features;
6 |
7 | namespace Microsoft.AspNetCore.Http
8 | {
9 | public static class ResponseExtensions
10 | {
11 | public static void Clear(this HttpResponse response)
12 | {
13 | if (response.HasStarted)
14 | {
15 | throw new InvalidOperationException("The response cannot be cleared, it has already started sending.");
16 | }
17 | response.StatusCode = 200;
18 | response.HttpContext.Features.Get().ReasonPhrase = null;
19 | response.Headers.Clear();
20 | if (response.Body.CanSeek)
21 | {
22 | response.Body.SetLength(0);
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Extensions/SessionExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Text;
5 |
6 | namespace Microsoft.AspNetCore.Http
7 | {
8 | public static class SessionExtensions
9 | {
10 | public static void SetInt32(this ISession session, string key, int value)
11 | {
12 | var bytes = new byte[]
13 | {
14 | (byte)(value >> 24),
15 | (byte)(0xFF & (value >> 16)),
16 | (byte)(0xFF & (value >> 8)),
17 | (byte)(0xFF & value)
18 | };
19 | session.Set(key, bytes);
20 | }
21 |
22 | public static int? GetInt32(this ISession session, string key)
23 | {
24 | var data = session.Get(key);
25 | if (data == null || data.Length < 4)
26 | {
27 | return null;
28 | }
29 | return data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
30 | }
31 |
32 | public static void SetString(this ISession session, string key, string value)
33 | {
34 | session.Set(key, Encoding.UTF8.GetBytes(value));
35 | }
36 |
37 | public static string GetString(this ISession session, string key)
38 | {
39 | var data = session.Get(key);
40 | if (data == null)
41 | {
42 | return null;
43 | }
44 | return Encoding.UTF8.GetString(data);
45 | }
46 |
47 | public static byte[] Get(this ISession session, string key)
48 | {
49 | byte[] value = null;
50 | session.TryGetValue(key, out value);
51 | return value;
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/Authentication/AuthenticateContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Security.Claims;
7 |
8 | namespace Microsoft.AspNetCore.Http.Features.Authentication
9 | {
10 | public class AuthenticateContext
11 | {
12 | public AuthenticateContext(string authenticationScheme)
13 | {
14 | if (string.IsNullOrEmpty(authenticationScheme))
15 | {
16 | throw new ArgumentException(nameof(authenticationScheme));
17 | }
18 |
19 | AuthenticationScheme = authenticationScheme;
20 | }
21 |
22 | public string AuthenticationScheme { get; }
23 |
24 | public bool Accepted { get; private set; }
25 |
26 | public ClaimsPrincipal Principal { get; private set; }
27 |
28 | public IDictionary Properties { get; private set; }
29 |
30 | public IDictionary Description { get; private set; }
31 |
32 | public Exception Error { get; private set; }
33 |
34 | public virtual void Authenticated(ClaimsPrincipal principal, IDictionary properties, IDictionary description)
35 | {
36 | Accepted = true;
37 |
38 | Principal = principal;
39 | Properties = properties;
40 | Description = description;
41 |
42 | // Set defaults for fields we don't use in case multiple handlers modified the context.
43 | Error = null;
44 | }
45 |
46 | public virtual void NotAuthenticated()
47 | {
48 | Accepted = true;
49 |
50 | // Set defaults for fields we don't use in case multiple handlers modified the context.
51 | Description = null;
52 | Error = null;
53 | Principal = null;
54 | Properties = null;
55 | }
56 |
57 | public virtual void Failed(Exception error)
58 | {
59 | Accepted = true;
60 |
61 | Error = error;
62 |
63 | // Set defaults for fields we don't use in case multiple handlers modified the context.
64 | Description = null;
65 | Principal = null;
66 | Properties = null;
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/Authentication/ChallengeBehavior.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.AspNetCore.Http.Features.Authentication
5 | {
6 | public enum ChallengeBehavior
7 | {
8 | Automatic,
9 | Unauthorized,
10 | Forbidden
11 | }
12 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/Authentication/ChallengeContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 |
7 | namespace Microsoft.AspNetCore.Http.Features.Authentication
8 | {
9 | public class ChallengeContext
10 | {
11 | public ChallengeContext(string authenticationScheme)
12 | : this(authenticationScheme, properties: null, behavior: ChallengeBehavior.Automatic)
13 | {
14 | }
15 |
16 | public ChallengeContext(string authenticationScheme, IDictionary properties, ChallengeBehavior behavior)
17 | {
18 | if (string.IsNullOrEmpty(authenticationScheme))
19 | {
20 | throw new ArgumentException(nameof(authenticationScheme));
21 | }
22 |
23 | AuthenticationScheme = authenticationScheme;
24 | Properties = properties ?? new Dictionary(StringComparer.Ordinal);
25 | Behavior = behavior;
26 | }
27 |
28 | public string AuthenticationScheme { get; }
29 |
30 | public ChallengeBehavior Behavior { get; }
31 |
32 | public IDictionary Properties { get; }
33 |
34 | public bool Accepted { get; private set; }
35 |
36 | public void Accept()
37 | {
38 | Accepted = true;
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/Authentication/DescribeSchemesContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Collections.Generic;
5 |
6 | namespace Microsoft.AspNetCore.Http.Features.Authentication
7 | {
8 | public class DescribeSchemesContext
9 | {
10 | private List> _results;
11 |
12 | public DescribeSchemesContext()
13 | {
14 | _results = new List>();
15 | }
16 |
17 | public IEnumerable> Results
18 | {
19 | get { return _results; }
20 | }
21 |
22 | public void Accept(IDictionary description)
23 | {
24 | _results.Add(description);
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/Authentication/IAuthenticationHandler.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Threading.Tasks;
5 |
6 | namespace Microsoft.AspNetCore.Http.Features.Authentication
7 | {
8 | public interface IAuthenticationHandler
9 | {
10 | void GetDescriptions(DescribeSchemesContext context);
11 |
12 | Task AuthenticateAsync(AuthenticateContext context);
13 |
14 | Task ChallengeAsync(ChallengeContext context);
15 |
16 | Task SignInAsync(SignInContext context);
17 |
18 | Task SignOutAsync(SignOutContext context);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/Authentication/IHttpAuthenticationFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Security.Claims;
6 |
7 | namespace Microsoft.AspNetCore.Http.Features.Authentication
8 | {
9 | public interface IHttpAuthenticationFeature
10 | {
11 | ClaimsPrincipal User { get; set; }
12 |
13 | [Obsolete("This is obsolete and will be removed in a future version. See https://go.microsoft.com/fwlink/?linkid=845470.")]
14 | IAuthenticationHandler Handler { get; set; }
15 | }
16 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/Authentication/SignInContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Security.Claims;
7 |
8 | namespace Microsoft.AspNetCore.Http.Features.Authentication
9 | {
10 | public class SignInContext
11 | {
12 | public SignInContext(string authenticationScheme, ClaimsPrincipal principal, IDictionary properties)
13 | {
14 | if (string.IsNullOrEmpty(authenticationScheme))
15 | {
16 | throw new ArgumentException(nameof(authenticationScheme));
17 | }
18 |
19 | if (principal == null)
20 | {
21 | throw new ArgumentNullException(nameof(principal));
22 | }
23 |
24 | AuthenticationScheme = authenticationScheme;
25 | Principal = principal;
26 | Properties = properties ?? new Dictionary(StringComparer.Ordinal);
27 | }
28 |
29 | public string AuthenticationScheme { get; }
30 |
31 | public ClaimsPrincipal Principal { get; }
32 |
33 | public IDictionary Properties { get; }
34 |
35 | public bool Accepted { get; private set; }
36 |
37 | public void Accept()
38 | {
39 | Accepted = true;
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/Authentication/SignOutContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 |
7 | namespace Microsoft.AspNetCore.Http.Features.Authentication
8 | {
9 | public class SignOutContext
10 | {
11 | public SignOutContext(string authenticationScheme, IDictionary properties)
12 | {
13 | if (string.IsNullOrEmpty(authenticationScheme))
14 | {
15 | throw new ArgumentException(nameof(authenticationScheme));
16 | }
17 |
18 | AuthenticationScheme = authenticationScheme;
19 | Properties = properties ?? new Dictionary(StringComparer.Ordinal);
20 | }
21 |
22 | public string AuthenticationScheme { get; }
23 |
24 | public IDictionary Properties { get; }
25 |
26 | public bool Accepted { get; private set; }
27 |
28 | public void Accept()
29 | {
30 | Accepted = true;
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/FeatureReference.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.AspNetCore.Http.Features
5 | {
6 | public struct FeatureReference
7 | {
8 | private T _feature;
9 | private int _revision;
10 |
11 | private FeatureReference(T feature, int revision)
12 | {
13 | _feature = feature;
14 | _revision = revision;
15 | }
16 |
17 | public static readonly FeatureReference Default = new FeatureReference(default(T), -1);
18 |
19 | public T Fetch(IFeatureCollection features)
20 | {
21 | if (_revision == features.Revision)
22 | {
23 | return _feature;
24 | }
25 | _feature = (T)features[typeof(T)];
26 | _revision = features.Revision;
27 | return _feature;
28 | }
29 |
30 | public T Update(IFeatureCollection features, T feature)
31 | {
32 | features[typeof(T)] = feature;
33 | _feature = feature;
34 | _revision = features.Revision;
35 | return feature;
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/IFeatureCollection.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 |
7 | namespace Microsoft.AspNetCore.Http.Features
8 | {
9 | ///
10 | /// Represents a collection of HTTP features.
11 | ///
12 | public interface IFeatureCollection : IEnumerable>
13 | {
14 | ///
15 | /// Indicates if the collection can be modified.
16 | ///
17 | bool IsReadOnly { get; }
18 |
19 | ///
20 | /// Incremented for each modification and can be used to verify cached results.
21 | ///
22 | int Revision { get; }
23 |
24 | ///
25 | /// Gets or sets a given feature. Setting a null value removes the feature.
26 | ///
27 | ///
28 | /// The requested feature, or null if it is not present.
29 | object this[Type key] { get; set; }
30 |
31 | ///
32 | /// Retrieves the requested feature from the collection.
33 | ///
34 | /// The feature key.
35 | /// The requested feature, or null if it is not present.
36 | TFeature Get();
37 |
38 | ///
39 | /// Sets the given feature in the collection.
40 | ///
41 | /// The feature key.
42 | /// The feature value.
43 | void Set(TFeature instance);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/IFormFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Threading;
5 | using System.Threading.Tasks;
6 |
7 | namespace Microsoft.AspNetCore.Http.Features
8 | {
9 | public interface IFormFeature
10 | {
11 | ///
12 | /// Indicates if the request has a supported form content-type.
13 | ///
14 | bool HasFormContentType { get; }
15 |
16 | ///
17 | /// The parsed form, if any.
18 | ///
19 | IFormCollection Form { get; set; }
20 |
21 | ///
22 | /// Parses the request body as a form.
23 | ///
24 | ///
25 | IFormCollection ReadForm();
26 |
27 | ///
28 | /// Parses the request body as a form.
29 | ///
30 | ///
31 | ///
32 | Task ReadFormAsync(CancellationToken cancellationToken);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/IFormFile.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.IO;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 |
8 | namespace Microsoft.AspNetCore.Http
9 | {
10 | ///
11 | /// Represents a file sent with the HttpRequest.
12 | ///
13 | public interface IFormFile
14 | {
15 | ///
16 | /// Gets the raw Content-Type header of the uploaded file.
17 | ///
18 | string ContentType { get; }
19 |
20 | ///
21 | /// Gets the raw Content-Disposition header of the uploaded file.
22 | ///
23 | string ContentDisposition { get; }
24 |
25 | ///
26 | /// Gets the header dictionary of the uploaded file.
27 | ///
28 | IHeaderDictionary Headers { get; }
29 |
30 | ///
31 | /// Gets the file length in bytes.
32 | ///
33 | long Length { get; }
34 |
35 | ///
36 | /// Gets the form field name from the Content-Disposition header.
37 | ///
38 | string Name { get; }
39 |
40 | ///
41 | /// Gets the file name from the Content-Disposition header.
42 | ///
43 | string FileName { get; }
44 |
45 | ///
46 | /// Opens the request stream for reading the uploaded file.
47 | ///
48 | Stream OpenReadStream();
49 |
50 | ///
51 | /// Copies the contents of the uploaded file to the stream.
52 | ///
53 | /// The stream to copy the file contents to.
54 | void CopyTo(Stream target);
55 |
56 | ///
57 | /// Asynchronously copies the contents of the uploaded file to the stream.
58 | ///
59 | /// The stream to copy the file contents to.
60 | ///
61 | Task CopyToAsync(Stream target, CancellationToken cancellationToken = default(CancellationToken));
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/IFormFileCollection.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Collections.Generic;
5 |
6 | namespace Microsoft.AspNetCore.Http
7 | {
8 | ///
9 | /// Represents the collection of files sent with the HttpRequest.
10 | ///
11 | public interface IFormFileCollection : IReadOnlyList
12 | {
13 | ///
14 | /// Gets the first file with the specified name.
15 | ///
16 | /// The name of the file to get.
17 | ///
18 | /// The requested file, or null if it is not present.
19 | ///
20 | IFormFile this[string name] { get; }
21 |
22 | ///
23 | /// Gets the first file with the specified name.
24 | ///
25 | /// The name of the file to get.
26 | ///
27 | /// The requested file, or null if it is not present.
28 | ///
29 | IFormFile GetFile(string name);
30 |
31 | ///
32 | /// Gets an containing the files of the
33 | /// with the specified name.
34 | ///
35 | /// The name of the files to get.
36 | ///
37 | /// An containing the files of the object
38 | /// that implements .
39 | ///
40 | IReadOnlyList GetFiles(string name);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/IHeaderDictionary.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Collections.Generic;
5 | using Microsoft.Extensions.Primitives;
6 |
7 | namespace Microsoft.AspNetCore.Http
8 | {
9 | ///
10 | /// Represents HttpRequest and HttpResponse headers
11 | ///
12 | public interface IHeaderDictionary : IDictionary
13 | {
14 | ///
15 | /// IHeaderDictionary has a different indexer contract than IDictionary, where it will return StringValues.Empty for missing entries.
16 | ///
17 | ///
18 | /// The stored value, or StringValues.Empty if the key is not present.
19 | new StringValues this[string key] { get; set; }
20 |
21 | ///
22 | /// Strongly typed access to the Content-Length header. Implementations must keep this in sync with the string representation.
23 | ///
24 | long? ContentLength { get; set; }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/IHttpBodyControlFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.AspNetCore.Http.Features
5 | {
6 | ///
7 | /// Controls the IO behavior for the and
8 | ///
9 | public interface IHttpBodyControlFeature
10 | {
11 | ///
12 | /// Gets or sets a value that controls whether synchronous IO is allowed for the and
13 | ///
14 | bool AllowSynchronousIO { get; set; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/IHttpBufferingFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.AspNetCore.Http.Features
5 | {
6 | public interface IHttpBufferingFeature
7 | {
8 | void DisableRequestBuffering();
9 | void DisableResponseBuffering();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/IHttpConnectionFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Net;
5 |
6 | namespace Microsoft.AspNetCore.Http.Features
7 | {
8 | ///
9 | /// Information regarding the TCP/IP connection carrying the request.
10 | ///
11 | public interface IHttpConnectionFeature
12 | {
13 | ///
14 | /// The unique identifier for the connection the request was received on. This is primarily for diagnostic purposes.
15 | ///
16 | string ConnectionId { get; set; }
17 |
18 | ///
19 | /// The IPAddress of the client making the request. Note this may be for a proxy rather than the end user.
20 | ///
21 | IPAddress RemoteIpAddress { get; set; }
22 |
23 | ///
24 | /// The local IPAddress on which the request was received.
25 | ///
26 | IPAddress LocalIpAddress { get; set; }
27 |
28 | ///
29 | /// The remote port of the client making the request.
30 | ///
31 | int RemotePort { get; set; }
32 |
33 | ///
34 | /// The local port on which the request was received.
35 | ///
36 | int LocalPort { get; set; }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/IHttpMaxRequestBodySizeFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.AspNetCore.Http.Features
5 | {
6 | ///
7 | /// Feature to inspect and modify the maximum request body size for a single request.
8 | ///
9 | public interface IHttpMaxRequestBodySizeFeature
10 | {
11 | ///
12 | /// Indicates whether is read-only.
13 | /// If true, this could mean that the request body has already been read from
14 | /// or that was called.
15 | ///
16 | bool IsReadOnly { get; }
17 |
18 | ///
19 | /// The maximum allowed size of the current request body in bytes.
20 | /// When set to null, the maximum request body size is unlimited.
21 | /// This cannot be modified after the reading the request body has started.
22 | /// This limit does not affect upgraded connections which are always unlimited.
23 | ///
24 | ///
25 | /// Defaults to the server's global max request body size limit.
26 | ///
27 | long? MaxRequestBodySize { get; set; }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/IHttpRequestIdentifierFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 |
6 | namespace Microsoft.AspNetCore.Http.Features
7 | {
8 | ///
9 | /// Feature to identify a request.
10 | ///
11 | public interface IHttpRequestIdentifierFeature
12 | {
13 | ///
14 | /// Identifier to trace a request.
15 | ///
16 | string TraceIdentifier { get; set; }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/IHttpRequestLifetimeFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System.Threading;
5 |
6 | namespace Microsoft.AspNetCore.Http.Features
7 | {
8 | public interface IHttpRequestLifetimeFeature
9 | {
10 | ///
11 | /// A that fires if the request is aborted and
12 | /// the application should cease processing. The token will not fire if the request
13 | /// completes successfully.
14 | ///
15 | CancellationToken RequestAborted { get; set; }
16 |
17 | ///
18 | /// Forcefully aborts the request if it has not already completed. This will result in
19 | /// RequestAborted being triggered.
20 | ///
21 | void Abort();
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Microsoft.AspNetCore.Http.Features/IHttpResponseFeature.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.IO;
6 | using System.Threading.Tasks;
7 |
8 | namespace Microsoft.AspNetCore.Http.Features
9 | {
10 | ///
11 | /// Represents the fields and state of an HTTP response.
12 | ///
13 | public interface IHttpResponseFeature
14 | {
15 | ///
16 | /// The status-code as defined in RFC 7230. The default value is 200.
17 | ///
18 | int StatusCode { get; set; }
19 |
20 | ///
21 | /// The reason-phrase as defined in RFC 7230. Note this field is no longer supported by HTTP/2.
22 | ///
23 | string ReasonPhrase { get; set; }
24 |
25 | ///
26 | /// The response headers to send. Headers with multiple values will be emitted as multiple headers.
27 | ///
28 | IHeaderDictionary Headers { get; set; }
29 |
30 | ///
31 | /// The for writing the response body.
32 | ///
33 | Stream Body { get; set; }
34 |
35 | ///
36 | /// Indicates if the response has started. If true, the ,
37 | /// , and are now immutable, and
38 | /// OnStarting should no longer be called.
39 | ///
40 | bool HasStarted { get; }
41 |
42 | ///
43 | /// Registers a callback to be invoked just before the response starts. This is the
44 | /// last chance to modify the , , or
45 | /// .
46 | ///
47 | /// The callback to invoke when starting the response.
48 | /// The state to pass into the callback.
49 | void OnStarting(Func