├── .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 callback, object state); 50 | 51 | /// 52 | /// Registers a callback to be invoked after a response has fully completed. This is 53 | /// intended for resource cleanup. 54 | /// 55 | /// The callback to invoke after the response has completed. 56 | /// The state to pass into the callback. 57 | void OnCompleted(Func callback, object state); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/IHttpResponseTrailersFeature.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 IHttpResponseTrailersFeature 7 | { 8 | IHeaderDictionary Trailers { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/IHttpSendFileFeature.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.Features 9 | { 10 | /// 11 | /// Provides an efficient mechanism for transferring files from disk to the network. 12 | /// 13 | public interface IHttpSendFileFeature 14 | { 15 | /// 16 | /// Sends the requested file in the response body. This may bypass the IHttpResponseFeature.Body 17 | /// . A response may include multiple writes. 18 | /// 19 | /// The full disk path to the file. 20 | /// The offset in the file to start at. 21 | /// The number of bytes to send, or null to send the remainder of the file. 22 | /// A used to abort the transmission. 23 | /// 24 | Task SendFileAsync(string path, long offset, long? count, CancellationToken cancellation); 25 | } 26 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/IHttpUpgradeFeature.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.Tasks; 6 | 7 | namespace Microsoft.AspNetCore.Http.Features 8 | { 9 | public interface IHttpUpgradeFeature 10 | { 11 | /// 12 | /// Indicates if the server can upgrade this request to an opaque, bidirectional stream. 13 | /// 14 | bool IsUpgradableRequest { get; } 15 | 16 | /// 17 | /// Attempt to upgrade the request to an opaque, bidirectional stream. The response status code 18 | /// and headers need to be set before this is invoked. Check 19 | /// before invoking. 20 | /// 21 | /// 22 | Task UpgradeAsync(); 23 | } 24 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/IHttpWebSocketFeature.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.WebSockets; 5 | using System.Threading.Tasks; 6 | 7 | namespace Microsoft.AspNetCore.Http.Features 8 | { 9 | public interface IHttpWebSocketFeature 10 | { 11 | /// 12 | /// Indicates if this is a WebSocket upgrade request. 13 | /// 14 | bool IsWebSocketRequest { get; } 15 | 16 | /// 17 | /// Attempts to upgrade the request to a . Check 18 | /// before invoking this. 19 | /// 20 | /// 21 | /// 22 | Task AcceptAsync(WebSocketAcceptContext context); 23 | } 24 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/IItemsFeature.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 7 | { 8 | public interface IItemsFeature 9 | { 10 | IDictionary Items { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/IQueryFeature.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 IQueryFeature 7 | { 8 | IQueryCollection Query { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/IRequestCookiesFeature.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 IRequestCookiesFeature 7 | { 8 | IRequestCookieCollection Cookies { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/IResponseCookies.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 | /// A wrapper for the response Set-Cookie header. 8 | /// 9 | public interface IResponseCookies 10 | { 11 | /// 12 | /// Add a new cookie and value. 13 | /// 14 | /// Name of the new cookie. 15 | /// Value of the new cookie. 16 | void Append(string key, string value); 17 | 18 | /// 19 | /// Add a new cookie. 20 | /// 21 | /// Name of the new cookie. 22 | /// Value of the new cookie. 23 | /// included in the new cookie setting. 24 | void Append(string key, string value, CookieOptions options); 25 | 26 | /// 27 | /// Sets an expired cookie. 28 | /// 29 | /// Name of the cookie to expire. 30 | void Delete(string key); 31 | 32 | /// 33 | /// Sets an expired cookie. 34 | /// 35 | /// Name of the cookie to expire. 36 | /// 37 | /// used to discriminate the particular cookie to expire. The 38 | /// and values are especially important. 39 | /// 40 | void Delete(string key, CookieOptions options); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/IResponseCookiesFeature.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 helper for creating the response Set-Cookie header. 8 | /// 9 | public interface IResponseCookiesFeature 10 | { 11 | /// 12 | /// Gets the wrapper for the response Set-Cookie header. 13 | /// 14 | IResponseCookies Cookies { get; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/IServiceProvidersFeature.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 | public interface IServiceProvidersFeature 9 | { 10 | IServiceProvider RequestServices { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/ISessionFeature.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 ISessionFeature 7 | { 8 | ISession Session { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/ITlsConnectionFeature.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.Cryptography.X509Certificates; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace Microsoft.AspNetCore.Http.Features 9 | { 10 | public interface ITlsConnectionFeature 11 | { 12 | /// 13 | /// Synchronously retrieves the client certificate, if any. 14 | /// 15 | X509Certificate2 ClientCertificate { get; set; } 16 | 17 | /// 18 | /// Asynchronously retrieves the client certificate, if any. 19 | /// 20 | /// 21 | Task GetClientCertificateAsync(CancellationToken cancellationToken); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/ITlsTokenBindingFeature.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 | /// Provides information regarding TLS token binding parameters. 8 | /// 9 | /// 10 | /// TLS token bindings help mitigate the risk of impersonation by an attacker in the 11 | /// event an authenticated client's bearer tokens are somehow exfiltrated from the 12 | /// client's machine. See https://datatracker.ietf.org/doc/draft-popov-token-binding/ 13 | /// for more information. 14 | /// 15 | public interface ITlsTokenBindingFeature 16 | { 17 | /// 18 | /// Gets the 'provided' token binding identifier associated with the request. 19 | /// 20 | /// The token binding identifier, or null if the client did not 21 | /// supply a 'provided' token binding or valid proof of possession of the 22 | /// associated private key. The caller should treat this identifier as an 23 | /// opaque blob and should not try to parse it. 24 | byte[] GetProvidedTokenBindingId(); 25 | 26 | /// 27 | /// Gets the 'referred' token binding identifier associated with the request. 28 | /// 29 | /// The token binding identifier, or null if the client did not 30 | /// supply a 'referred' token binding or valid proof of possession of the 31 | /// associated private key. The caller should treat this identifier as an 32 | /// opaque blob and should not try to parse it. 33 | byte[] GetReferredTokenBindingId(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/ITrackingConsentFeature.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 | /// Used to query, grant, and withdraw user consent regarding the storage of user 8 | /// information related to site activity and functionality. 9 | /// 10 | public interface ITrackingConsentFeature 11 | { 12 | /// 13 | /// Indicates if consent is required for the given request. 14 | /// 15 | bool IsConsentNeeded { get; } 16 | 17 | /// 18 | /// Indicates if consent was given. 19 | /// 20 | bool HasConsent { get; } 21 | 22 | /// 23 | /// Indicates either if consent has been given or if consent is not required. 24 | /// 25 | bool CanTrack { get; } 26 | 27 | /// 28 | /// Grants consent for this request. If the response has not yet started then 29 | /// this will also grant consent for future requests. 30 | /// 31 | void GrantConsent(); 32 | 33 | /// 34 | /// Withdraws consent for this request. If the response has not yet started then 35 | /// this will also withdraw consent for future requests. 36 | /// 37 | void WithdrawConsent(); 38 | 39 | /// 40 | /// Creates a consent cookie for use when granting consent from a javascript client. 41 | /// 42 | string CreateConsentCookie(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/Microsoft.AspNetCore.Http.Features.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ASP.NET Core HTTP feature interface definitions. 5 | netstandard2.0 6 | $(NoWarn);CS1591 7 | true 8 | aspnetcore 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/SameSiteMode.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 | // RFC Draft: https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 7 | // This mirrors Microsoft.Net.Http.Headers.SameSiteMode 8 | public enum SameSiteMode 9 | { 10 | None = 0, 11 | Lax, 12 | Strict 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http.Features/WebSocketAcceptContext.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 class WebSocketAcceptContext 7 | { 8 | public virtual string SubProtocol { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Features/Authentication/HttpAuthenticationFeature.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 | 6 | namespace Microsoft.AspNetCore.Http.Features.Authentication 7 | { 8 | public class HttpAuthenticationFeature : IHttpAuthenticationFeature 9 | { 10 | public ClaimsPrincipal User 11 | { 12 | get; 13 | set; 14 | } 15 | 16 | public IAuthenticationHandler Handler 17 | { 18 | get; 19 | set; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Features/DefaultSessionFeature.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 | /// This type exists only for the purpose of unit testing where the user can directly set the 8 | /// property without the need for creating a . 9 | /// 10 | public class DefaultSessionFeature : ISessionFeature 11 | { 12 | public ISession Session { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Features/HttpConnectionFeature.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 | public class HttpConnectionFeature : IHttpConnectionFeature 9 | { 10 | public string ConnectionId { get; set; } 11 | 12 | public IPAddress LocalIpAddress { get; set; } 13 | 14 | public int LocalPort { get; set; } 15 | 16 | public IPAddress RemoteIpAddress { get; set; } 17 | 18 | public int RemotePort { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Features/HttpRequestFeature.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 | 6 | namespace Microsoft.AspNetCore.Http.Features 7 | { 8 | public class HttpRequestFeature : IHttpRequestFeature 9 | { 10 | public HttpRequestFeature() 11 | { 12 | Headers = new HeaderDictionary(); 13 | Body = Stream.Null; 14 | Protocol = string.Empty; 15 | Scheme = string.Empty; 16 | Method = string.Empty; 17 | PathBase = string.Empty; 18 | Path = string.Empty; 19 | QueryString = string.Empty; 20 | RawTarget = string.Empty; 21 | } 22 | 23 | public string Protocol { get; set; } 24 | public string Scheme { get; set; } 25 | public string Method { get; set; } 26 | public string PathBase { get; set; } 27 | public string Path { get; set; } 28 | public string QueryString { get; set; } 29 | public string RawTarget { get; set; } 30 | public IHeaderDictionary Headers { get; set; } 31 | public Stream Body { get; set; } 32 | } 33 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Features/HttpRequestLifetimeFeature.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 class HttpRequestLifetimeFeature : IHttpRequestLifetimeFeature 9 | { 10 | public CancellationToken RequestAborted { get; set; } 11 | 12 | public void Abort() 13 | { 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Features/HttpResponseFeature.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 | public class HttpResponseFeature : IHttpResponseFeature 11 | { 12 | public HttpResponseFeature() 13 | { 14 | StatusCode = 200; 15 | Headers = new HeaderDictionary(); 16 | Body = Stream.Null; 17 | } 18 | 19 | public int StatusCode { get; set; } 20 | 21 | public string ReasonPhrase { get; set; } 22 | 23 | public IHeaderDictionary Headers { get; set; } 24 | 25 | public Stream Body { get; set; } 26 | 27 | public virtual bool HasStarted 28 | { 29 | get { return false; } 30 | } 31 | 32 | public virtual void OnStarting(Func callback, object state) 33 | { 34 | } 35 | 36 | public virtual void OnCompleted(Func callback, object state) 37 | { 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Features/ItemsFeature.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.AspNetCore.Http.Internal; 6 | 7 | namespace Microsoft.AspNetCore.Http.Features 8 | { 9 | public class ItemsFeature : IItemsFeature 10 | { 11 | public ItemsFeature() 12 | { 13 | Items = new ItemsDictionary(); 14 | } 15 | 16 | public IDictionary Items { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Features/RouteValuesFeature.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 for routing values. Use 10 | /// to access the values associated with the current request. 11 | /// 12 | public class RouteValuesFeature : IRouteValuesFeature 13 | { 14 | private RouteValueDictionary _routeValues; 15 | 16 | /// 17 | /// Gets or sets the associated with the currrent 18 | /// request. 19 | /// 20 | public RouteValueDictionary RouteValues 21 | { 22 | get 23 | { 24 | if (_routeValues == null) 25 | { 26 | _routeValues = new RouteValueDictionary(); 27 | } 28 | 29 | return _routeValues; 30 | } 31 | set => _routeValues = value; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Features/ServiceProvidersFeature.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 | public class ServiceProvidersFeature : IServiceProvidersFeature 9 | { 10 | public IServiceProvider RequestServices { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Features/TlsConnectionFeature.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.Cryptography.X509Certificates; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace Microsoft.AspNetCore.Http.Features 9 | { 10 | public class TlsConnectionFeature : ITlsConnectionFeature 11 | { 12 | public X509Certificate2 ClientCertificate { get; set; } 13 | 14 | public Task GetClientCertificateAsync(CancellationToken cancellationToken) 15 | { 16 | return Task.FromResult(ClientCertificate); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/HttpContextAccessor.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 7 | { 8 | public class HttpContextAccessor : IHttpContextAccessor 9 | { 10 | private static AsyncLocal _httpContextCurrent = new AsyncLocal(); 11 | 12 | public HttpContext HttpContext 13 | { 14 | get 15 | { 16 | return _httpContextCurrent.Value?.Context; 17 | } 18 | set 19 | { 20 | var holder = _httpContextCurrent.Value; 21 | if (holder != null) 22 | { 23 | // Clear current HttpContext trapped in the AsyncLocals, as its done. 24 | holder.Context = null; 25 | } 26 | 27 | if (value != null) 28 | { 29 | // Use an object indirection to hold the HttpContext in the AsyncLocal, 30 | // so it can be cleared in all ExecutionContexts when its cleared. 31 | _httpContextCurrent.Value = new HttpContextHolder { Context = value }; 32 | } 33 | } 34 | } 35 | 36 | private class HttpContextHolder 37 | { 38 | public HttpContext Context; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/HttpContextFactory.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.Options; 7 | 8 | namespace Microsoft.AspNetCore.Http 9 | { 10 | public class HttpContextFactory : IHttpContextFactory 11 | { 12 | private readonly IHttpContextAccessor _httpContextAccessor; 13 | private readonly FormOptions _formOptions; 14 | 15 | public HttpContextFactory(IOptions formOptions) 16 | : this(formOptions, httpContextAccessor: null) 17 | { 18 | } 19 | 20 | public HttpContextFactory(IOptions formOptions, IHttpContextAccessor httpContextAccessor) 21 | { 22 | if (formOptions == null) 23 | { 24 | throw new ArgumentNullException(nameof(formOptions)); 25 | } 26 | 27 | _formOptions = formOptions.Value; 28 | _httpContextAccessor = httpContextAccessor; 29 | } 30 | 31 | public HttpContext Create(IFeatureCollection featureCollection) 32 | { 33 | if (featureCollection == null) 34 | { 35 | throw new ArgumentNullException(nameof(featureCollection)); 36 | } 37 | 38 | var httpContext = new DefaultHttpContext(featureCollection); 39 | if (_httpContextAccessor != null) 40 | { 41 | _httpContextAccessor.HttpContext = httpContext; 42 | } 43 | 44 | var formFeature = new FormFeature(httpContext.Request, _formOptions); 45 | featureCollection.Set(formFeature); 46 | 47 | return httpContext; 48 | } 49 | 50 | public void Dispose(HttpContext httpContext) 51 | { 52 | if (_httpContextAccessor != null) 53 | { 54 | _httpContextAccessor.HttpContext = null; 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/HttpServiceCollectionExtensions.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.Extensions.DependencyInjection.Extensions; 7 | 8 | namespace Microsoft.Extensions.DependencyInjection 9 | { 10 | /// 11 | /// Extension methods for configuring HttpContext services. 12 | /// 13 | public static class HttpServiceCollectionExtensions 14 | { 15 | /// 16 | /// Adds a default implementation for the service. 17 | /// 18 | /// The . 19 | /// The service collection. 20 | public static IServiceCollection AddHttpContextAccessor(this IServiceCollection services) 21 | { 22 | if (services == null) 23 | { 24 | throw new ArgumentNullException(nameof(services)); 25 | } 26 | 27 | services.TryAddSingleton(); 28 | return services; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Internal/Constants.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 static class Constants 7 | { 8 | internal const string Http = "http"; 9 | internal const string Https = "https"; 10 | internal const string UnixPipeHostPrefix = "unix:/"; 11 | 12 | internal static class BuilderProperties 13 | { 14 | internal static string ServerFeatures = "server.Features"; 15 | internal static string ApplicationServices = "application.Services"; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Internal/FormFileCollection.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.Internal 8 | { 9 | /// 10 | /// Default implementation of . 11 | /// 12 | public class FormFileCollection : List, IFormFileCollection 13 | { 14 | /// 15 | public IFormFile this[string name] => GetFile(name); 16 | 17 | /// 18 | public IFormFile GetFile(string name) 19 | { 20 | foreach (var file in this) 21 | { 22 | if (string.Equals(name, file.Name, StringComparison.OrdinalIgnoreCase)) 23 | { 24 | return file; 25 | } 26 | } 27 | 28 | return null; 29 | } 30 | 31 | /// 32 | public IReadOnlyList GetFiles(string name) 33 | { 34 | var files = new List(); 35 | 36 | foreach (var file in this) 37 | { 38 | if (string.Equals(name, file.Name, StringComparison.OrdinalIgnoreCase)) 39 | { 40 | files.Add(file); 41 | } 42 | } 43 | 44 | return files; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/Microsoft.AspNetCore.Http.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ASP.NET Core default HTTP feature implementations. 5 | netstandard2.0;netcoreapp2.2 6 | $(NoWarn);CS1591 7 | true 8 | true 9 | aspnetcore 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/MiddlewareFactory.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 | using Microsoft.Extensions.DependencyInjection; 10 | 11 | namespace Microsoft.AspNetCore.Http 12 | { 13 | public class MiddlewareFactory : IMiddlewareFactory 14 | { 15 | // The default middleware factory is just an IServiceProvider proxy. 16 | // This should be registered as a scoped service so that the middleware instances 17 | // don't end up being singletons. 18 | private readonly IServiceProvider _serviceProvider; 19 | 20 | public MiddlewareFactory(IServiceProvider serviceProvider) 21 | { 22 | _serviceProvider = serviceProvider; 23 | } 24 | 25 | public IMiddleware Create(Type middlewareType) 26 | { 27 | return _serviceProvider.GetRequiredService(middlewareType) as IMiddleware; 28 | } 29 | 30 | public void Release(IMiddleware middleware) 31 | { 32 | // The container owns the lifetime of the service 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Http/RequestFormReaderExtensions.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; 6 | using System.Threading.Tasks; 7 | using Microsoft.AspNetCore.Http.Features; 8 | 9 | namespace Microsoft.AspNetCore.Http 10 | { 11 | public static class RequestFormReaderExtensions 12 | { 13 | /// 14 | /// Read the request body as a form with the given options. These options will only be used 15 | /// if the form has not already been read. 16 | /// 17 | /// The request. 18 | /// Options for reading the form. 19 | /// 20 | /// The parsed form. 21 | public static Task ReadFormAsync(this HttpRequest request, FormOptions options, 22 | CancellationToken cancellationToken = new CancellationToken()) 23 | { 24 | if (request == null) 25 | { 26 | throw new ArgumentNullException(nameof(request)); 27 | } 28 | if (options == null) 29 | { 30 | throw new ArgumentNullException(nameof(options)); 31 | } 32 | 33 | if (!request.HasFormContentType) 34 | { 35 | throw new InvalidOperationException("Incorrect Content-Type: " + request.ContentType); 36 | } 37 | 38 | var features = request.HttpContext.Features; 39 | var formFeature = features.Get(); 40 | if (formFeature == null || formFeature.Form == null) 41 | { 42 | // We haven't read the form yet, replace the reader with one using our own options. 43 | features.Set(new FormFeature(request, options)); 44 | } 45 | return request.ReadFormAsync(cancellationToken); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Owin/IOwinEnvironmentFeature.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.Owin 7 | { 8 | public interface IOwinEnvironmentFeature 9 | { 10 | IDictionary Environment { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Owin/Microsoft.AspNetCore.Owin.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ASP.NET Core component for running OWIN middleware in an ASP.NET Core application, and to run ASP.NET Core middleware in an OWIN application. 5 | netstandard2.0 6 | $(NoWarn);CS1591 7 | true 8 | aspnetcore;owin 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Owin/OwinEnvironmentFeature.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.Owin 7 | { 8 | public class OwinEnvironmentFeature : IOwinEnvironmentFeature 9 | { 10 | public IDictionary Environment { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Owin/Utilities.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 | using System.Security.Principal; 8 | using Microsoft.AspNetCore.Http; 9 | using Microsoft.Extensions.Primitives; 10 | 11 | namespace Microsoft.AspNetCore.Owin 12 | { 13 | internal static class Utilities 14 | { 15 | internal static string RemoveQuestionMark(string queryString) 16 | { 17 | if (!string.IsNullOrEmpty(queryString)) 18 | { 19 | if (queryString[0] == '?') 20 | { 21 | return queryString.Substring(1); 22 | } 23 | } 24 | return queryString; 25 | } 26 | 27 | internal static string AddQuestionMark(string queryString) 28 | { 29 | if (!string.IsNullOrEmpty(queryString)) 30 | { 31 | return '?' + queryString; 32 | } 33 | return queryString; 34 | } 35 | 36 | internal static ClaimsPrincipal MakeClaimsPrincipal(IPrincipal principal) 37 | { 38 | if (principal == null) 39 | { 40 | return null; 41 | } 42 | if (principal is ClaimsPrincipal) 43 | { 44 | return principal as ClaimsPrincipal; 45 | } 46 | return new ClaimsPrincipal(principal); 47 | } 48 | 49 | internal static IHeaderDictionary MakeHeaderDictionary(IDictionary dictionary) 50 | { 51 | var wrapper = dictionary as DictionaryStringArrayWrapper; 52 | if (wrapper != null) 53 | { 54 | return wrapper.Inner; 55 | } 56 | return new DictionaryStringValuesWrapper(dictionary); 57 | } 58 | 59 | internal static IDictionary MakeDictionaryStringArray(IHeaderDictionary dictionary) 60 | { 61 | var wrapper = dictionary as DictionaryStringValuesWrapper; 62 | if (wrapper != null) 63 | { 64 | return wrapper.Inner; 65 | } 66 | return new DictionaryStringArrayWrapper(dictionary); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.Owin/WebSockets/OwinWebSocketAcceptContext.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.AspNetCore.Http; 6 | 7 | namespace Microsoft.AspNetCore.Owin 8 | { 9 | public class OwinWebSocketAcceptContext : WebSocketAcceptContext 10 | { 11 | private IDictionary _options; 12 | 13 | public OwinWebSocketAcceptContext() : this(new Dictionary(1)) 14 | { 15 | } 16 | 17 | public OwinWebSocketAcceptContext(IDictionary options) 18 | { 19 | _options = options; 20 | } 21 | 22 | public override string SubProtocol 23 | { 24 | get 25 | { 26 | object obj; 27 | if (_options != null && _options.TryGetValue(OwinConstants.WebSocket.SubProtocol, out obj)) 28 | { 29 | return (string)obj; 30 | } 31 | return null; 32 | } 33 | set 34 | { 35 | if (_options == null) 36 | { 37 | _options = new Dictionary(1); 38 | } 39 | _options[OwinConstants.WebSocket.SubProtocol] = value; 40 | } 41 | } 42 | 43 | public IDictionary Options 44 | { 45 | get { return _options; } 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.WebUtilities/Base64UrlTextEncoder.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.WebUtilities 5 | { 6 | public static class Base64UrlTextEncoder 7 | { 8 | /// 9 | /// Encodes supplied data into Base64 and replaces any URL encodable characters into non-URL encodable 10 | /// characters. 11 | /// 12 | /// Data to be encoded. 13 | /// Base64 encoded string modified with non-URL encodable characters 14 | public static string Encode(byte[] data) 15 | { 16 | return WebEncoders.Base64UrlEncode(data); 17 | } 18 | 19 | /// 20 | /// Decodes supplied string by replacing the non-URL encodable characters with URL encodable characters and 21 | /// then decodes the Base64 string. 22 | /// 23 | /// The string to be decoded. 24 | /// The decoded data. 25 | public static byte[] Decode(string text) 26 | { 27 | return WebEncoders.Base64UrlDecode(text); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.WebUtilities/FormMultipartSection.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.Net.Http.Headers; 7 | 8 | namespace Microsoft.AspNetCore.WebUtilities 9 | { 10 | /// 11 | /// Represents a form multipart section 12 | /// 13 | public class FormMultipartSection 14 | { 15 | private ContentDispositionHeaderValue _contentDispositionHeader; 16 | 17 | /// 18 | /// Creates a new instance of the class 19 | /// 20 | /// The section from which to create the 21 | /// Reparses the content disposition header 22 | public FormMultipartSection(MultipartSection section) 23 | : this(section, section.GetContentDispositionHeader()) 24 | { 25 | } 26 | 27 | /// 28 | /// Creates a new instance of the class 29 | /// 30 | /// The section from which to create the 31 | /// An already parsed content disposition header 32 | public FormMultipartSection(MultipartSection section, ContentDispositionHeaderValue header) 33 | { 34 | if (header == null || !header.IsFormDisposition()) 35 | { 36 | throw new ArgumentException($"Argument must be a form section", nameof(section)); 37 | } 38 | 39 | Section = section; 40 | _contentDispositionHeader = header; 41 | Name = HeaderUtilities.RemoveQuotes(_contentDispositionHeader.Name).ToString(); 42 | } 43 | 44 | /// 45 | /// Gets the original section from which this object was created 46 | /// 47 | public MultipartSection Section { get; } 48 | 49 | /// 50 | /// The form name 51 | /// 52 | public string Name { get; } 53 | 54 | /// 55 | /// Gets the form value 56 | /// 57 | /// The form value 58 | public Task GetValueAsync() 59 | { 60 | return Section.ReadAsStringAsync(); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.WebUtilities/Microsoft.AspNetCore.WebUtilities.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ASP.NET Core utilities, such as for working with forms, multipart messages, and query strings. 5 | netstandard2.0 6 | $(DefineConstants);WebEncoders_In_WebUtilities 7 | $(NoWarn);CS1591 8 | true 9 | aspnetcore 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.WebUtilities/MultipartBoundary.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.Text; 6 | 7 | namespace Microsoft.AspNetCore.WebUtilities 8 | { 9 | internal class MultipartBoundary 10 | { 11 | private readonly int[] _skipTable = new int[256]; 12 | private readonly string _boundary; 13 | private bool _expectLeadingCrlf; 14 | 15 | public MultipartBoundary(string boundary, bool expectLeadingCrlf = true) 16 | { 17 | if (boundary == null) 18 | { 19 | throw new ArgumentNullException(nameof(boundary)); 20 | } 21 | 22 | _boundary = boundary; 23 | _expectLeadingCrlf = expectLeadingCrlf; 24 | Initialize(_boundary, _expectLeadingCrlf); 25 | } 26 | 27 | private void Initialize(string boundary, bool expectLeadingCrlf) 28 | { 29 | if (expectLeadingCrlf) 30 | { 31 | BoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary); 32 | } 33 | else 34 | { 35 | BoundaryBytes = Encoding.UTF8.GetBytes("--" + boundary); 36 | } 37 | FinalBoundaryLength = BoundaryBytes.Length + 2; // Include the final '--' terminator. 38 | 39 | var length = BoundaryBytes.Length; 40 | for (var i = 0; i < _skipTable.Length; ++i) 41 | { 42 | _skipTable[i] = length; 43 | } 44 | for (var i = 0; i < length; ++i) 45 | { 46 | _skipTable[BoundaryBytes[i]] = Math.Max(1, length - 1 - i); 47 | } 48 | } 49 | 50 | public int GetSkipValue(byte input) 51 | { 52 | return _skipTable[input]; 53 | } 54 | 55 | public bool ExpectLeadingCrlf 56 | { 57 | get { return _expectLeadingCrlf; } 58 | set 59 | { 60 | if (value != _expectLeadingCrlf) 61 | { 62 | _expectLeadingCrlf = value; 63 | Initialize(_boundary, _expectLeadingCrlf); 64 | } 65 | } 66 | } 67 | 68 | public byte[] BoundaryBytes { get; private set; } 69 | 70 | public int FinalBoundaryLength { get; private set; } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.WebUtilities/MultipartSection.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.IO; 6 | using Microsoft.Extensions.Primitives; 7 | 8 | namespace Microsoft.AspNetCore.WebUtilities 9 | { 10 | public class MultipartSection 11 | { 12 | public string ContentType 13 | { 14 | get 15 | { 16 | StringValues values; 17 | if (Headers.TryGetValue("Content-Type", out values)) 18 | { 19 | return values; 20 | } 21 | return null; 22 | } 23 | } 24 | 25 | public string ContentDisposition 26 | { 27 | get 28 | { 29 | StringValues values; 30 | if (Headers.TryGetValue("Content-Disposition", out values)) 31 | { 32 | return values; 33 | } 34 | return null; 35 | } 36 | } 37 | 38 | public Dictionary Headers { get; set; } 39 | 40 | public Stream Body { get; set; } 41 | 42 | /// 43 | /// The position where the body starts in the total multipart body. 44 | /// This may not be available if the total multipart body is not seekable. 45 | /// 46 | public long? BaseStreamOffset { get; set; } 47 | } 48 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.WebUtilities/MultipartSectionStreamExtensions.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.Text; 7 | using System.Threading.Tasks; 8 | using Microsoft.Net.Http.Headers; 9 | 10 | namespace Microsoft.AspNetCore.WebUtilities 11 | { 12 | /// 13 | /// Various extension methods for dealing with the section body stream 14 | /// 15 | public static class MultipartSectionStreamExtensions 16 | { 17 | /// 18 | /// Reads the body of the section as a string 19 | /// 20 | /// The section to read from 21 | /// The body steam as string 22 | public static async Task ReadAsStringAsync(this MultipartSection section) 23 | { 24 | if (section == null) 25 | { 26 | throw new ArgumentNullException(nameof(section)); 27 | } 28 | 29 | MediaTypeHeaderValue sectionMediaType; 30 | MediaTypeHeaderValue.TryParse(section.ContentType, out sectionMediaType); 31 | 32 | Encoding streamEncoding = sectionMediaType?.Encoding; 33 | if (streamEncoding == null || streamEncoding == Encoding.UTF7) 34 | { 35 | streamEncoding = Encoding.UTF8; 36 | } 37 | 38 | using (var reader = new StreamReader( 39 | section.Body, 40 | streamEncoding, 41 | detectEncodingFromByteOrderMarks: true, 42 | bufferSize: 1024, 43 | leaveOpen: true)) 44 | { 45 | return await reader.ReadToEndAsync(); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.WebUtilities/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.WebUtilities.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] 7 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.WebUtilities/StreamHelperExtensions.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.Buffers; 5 | using System.IO; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace Microsoft.AspNetCore.WebUtilities 10 | { 11 | public static class StreamHelperExtensions 12 | { 13 | private const int _maxReadBufferSize = 1024 * 4; 14 | 15 | public static Task DrainAsync(this Stream stream, CancellationToken cancellationToken) 16 | { 17 | return stream.DrainAsync(ArrayPool.Shared, null, cancellationToken); 18 | } 19 | 20 | public static Task DrainAsync(this Stream stream, long? limit, CancellationToken cancellationToken) 21 | { 22 | return stream.DrainAsync(ArrayPool.Shared, limit, cancellationToken); 23 | } 24 | 25 | public static async Task DrainAsync(this Stream stream, ArrayPool bytePool, long? limit, CancellationToken cancellationToken) 26 | { 27 | cancellationToken.ThrowIfCancellationRequested(); 28 | var buffer = bytePool.Rent(_maxReadBufferSize); 29 | long total = 0; 30 | try 31 | { 32 | var read = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken); 33 | while (read > 0) 34 | { 35 | // Not all streams support cancellation directly. 36 | cancellationToken.ThrowIfCancellationRequested(); 37 | if (limit.HasValue && limit.GetValueOrDefault() - total < read) 38 | { 39 | throw new InvalidDataException($"The stream exceeded the data limit {limit.GetValueOrDefault()}."); 40 | } 41 | total += read; 42 | read = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken); 43 | } 44 | } 45 | finally 46 | { 47 | bytePool.Return(buffer); 48 | } 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/Microsoft.Net.Http.Headers/ContentDispositionHeaderValueIdentityExtensions.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.Net.Http.Headers 8 | { 9 | /// 10 | /// Various extension methods for for identifying the type of the disposition header 11 | /// 12 | public static class ContentDispositionHeaderValueIdentityExtensions 13 | { 14 | /// 15 | /// Checks if the content disposition header is a file disposition 16 | /// 17 | /// The header to check 18 | /// True if the header is file disposition, false otherwise 19 | public static bool IsFileDisposition(this ContentDispositionHeaderValue header) 20 | { 21 | if (header == null) 22 | { 23 | throw new ArgumentNullException(nameof(header)); 24 | } 25 | 26 | return header.DispositionType.Equals("form-data") 27 | && (!StringSegment.IsNullOrEmpty(header.FileName) || !StringSegment.IsNullOrEmpty(header.FileNameStar)); 28 | } 29 | 30 | /// 31 | /// Checks if the content disposition header is a form disposition 32 | /// 33 | /// The header to check 34 | /// True if the header is form disposition, false otherwise 35 | public static bool IsFormDisposition(this ContentDispositionHeaderValue header) 36 | { 37 | if (header == null) 38 | { 39 | throw new ArgumentNullException(nameof(header)); 40 | } 41 | 42 | return header.DispositionType.Equals("form-data") 43 | && StringSegment.IsNullOrEmpty(header.FileName) && StringSegment.IsNullOrEmpty(header.FileNameStar); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Microsoft.Net.Http.Headers/GenericHeaderParser.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.Net.Http.Headers 8 | { 9 | internal sealed class GenericHeaderParser : BaseHeaderParser 10 | { 11 | internal delegate int GetParsedValueLengthDelegate(StringSegment value, int startIndex, out T parsedValue); 12 | 13 | private GetParsedValueLengthDelegate _getParsedValueLength; 14 | 15 | internal GenericHeaderParser(bool supportsMultipleValues, GetParsedValueLengthDelegate getParsedValueLength) 16 | : base(supportsMultipleValues) 17 | { 18 | if (getParsedValueLength == null) 19 | { 20 | throw new ArgumentNullException(nameof(getParsedValueLength)); 21 | } 22 | 23 | _getParsedValueLength = getParsedValueLength; 24 | } 25 | 26 | protected override int GetParsedValueLength(StringSegment value, int startIndex, out T parsedValue) 27 | { 28 | return _getParsedValueLength(value, startIndex, out parsedValue); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Microsoft.Net.Http.Headers/HeaderQuality.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.Net.Http.Headers 5 | { 6 | public static class HeaderQuality 7 | { 8 | /// 9 | /// Quality factor to indicate a perfect match. 10 | /// 11 | public const double Match = 1.0; 12 | 13 | /// 14 | /// Quality factor to indicate no match. 15 | /// 16 | public const double NoMatch = 0.0; 17 | } 18 | } -------------------------------------------------------------------------------- /src/Microsoft.Net.Http.Headers/HttpParseResult.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.Net.Http.Headers 5 | { 6 | internal enum HttpParseResult 7 | { 8 | Parsed, 9 | NotParsed, 10 | InvalidFormat, 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.Net.Http.Headers/Microsoft.Net.Http.Headers.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | HTTP header parser implementations. 5 | netstandard2.0 6 | $(NoWarn);CS1591 7 | true 8 | true 9 | http 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Microsoft.Net.Http.Headers/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.Net.Http.Headers.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] 7 | -------------------------------------------------------------------------------- /src/Microsoft.Net.Http.Headers/SameSiteMode.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.Net.Http.Headers 5 | { 6 | // RFC Draft: https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 7 | public enum SameSiteMode 8 | { 9 | None = 0, 10 | Lax, 11 | Strict 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | netcoreapp2.2 6 | $(DeveloperBuildTestTfms) 7 | 8 | $(StandardTestTfms);net461 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Authentication.Core.Test/Microsoft.AspNetCore.Authentication.Core.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(StandardTestTfms) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Abstractions.Tests/CookieBuilderTests.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 Xunit; 6 | 7 | namespace Microsoft.AspNetCore.Http.Abstractions.Tests 8 | { 9 | public class CookieBuilderTests 10 | { 11 | [Theory] 12 | [InlineData(CookieSecurePolicy.Always, false, true)] 13 | [InlineData(CookieSecurePolicy.Always, true, true)] 14 | [InlineData(CookieSecurePolicy.SameAsRequest, true, true)] 15 | [InlineData(CookieSecurePolicy.SameAsRequest, false, false)] 16 | [InlineData(CookieSecurePolicy.None, true, false)] 17 | [InlineData(CookieSecurePolicy.None, false, false)] 18 | public void ConfiguresSecurePolicy(CookieSecurePolicy policy, bool requestIsHttps, bool secure) 19 | { 20 | var builder = new CookieBuilder 21 | { 22 | SecurePolicy = policy 23 | }; 24 | var context = new DefaultHttpContext(); 25 | context.Request.IsHttps = requestIsHttps; 26 | var options = builder.Build(context); 27 | 28 | Assert.Equal(secure, options.Secure); 29 | } 30 | 31 | [Fact] 32 | public void ComputesExpiration() 33 | { 34 | Assert.Null(new CookieBuilder().Build(new DefaultHttpContext()).Expires); 35 | 36 | var now = DateTimeOffset.Now; 37 | var options = new CookieBuilder { Expiration = TimeSpan.FromHours(1) }.Build(new DefaultHttpContext(), now); 38 | Assert.Equal(now.AddHours(1), options.Expires); 39 | } 40 | 41 | [Fact] 42 | public void ComputesMaxAge() 43 | { 44 | Assert.Null(new CookieBuilder().Build(new DefaultHttpContext()).MaxAge); 45 | 46 | var now = TimeSpan.FromHours(1); 47 | var options = new CookieBuilder { MaxAge = now }.Build(new DefaultHttpContext()); 48 | Assert.Equal(now, options.MaxAge); 49 | } 50 | 51 | [Fact] 52 | public void CookieBuilderPreservesDefaultPath() 53 | { 54 | Assert.Equal(new CookieOptions().Path, new CookieBuilder().Build(new DefaultHttpContext()).Path); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Abstractions.Tests/EndpointMetadataCollectionTests.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.Text; 7 | using Microsoft.AspNetCore.Http; 8 | using Xunit; 9 | 10 | namespace Microsoft.AspNetCore.Routing 11 | { 12 | public class EndpointMetadataCollectionTests 13 | { 14 | [Fact] 15 | public void Constructor_Enumeration_ContainsValues() 16 | { 17 | // Arrange & Act 18 | var metadata = new EndpointMetadataCollection(new List 19 | { 20 | 1, 21 | 2, 22 | 3, 23 | }); 24 | 25 | // Assert 26 | Assert.Equal(3, metadata.Count); 27 | 28 | Assert.Collection(metadata, 29 | value => Assert.Equal(1, value), 30 | value => Assert.Equal(2, value), 31 | value => Assert.Equal(3, value)); 32 | } 33 | 34 | [Fact] 35 | public void Constructor_ParamsArray_ContainsValues() 36 | { 37 | // Arrange & Act 38 | var metadata = new EndpointMetadataCollection(1, 2, 3); 39 | 40 | // Assert 41 | Assert.Equal(3, metadata.Count); 42 | 43 | Assert.Collection(metadata, 44 | value => Assert.Equal(1, value), 45 | value => Assert.Equal(2, value), 46 | value => Assert.Equal(3, value)); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Abstractions.Tests/FragmentStringTests.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 Xunit; 5 | 6 | namespace Microsoft.AspNetCore.Http.Abstractions.Tests 7 | { 8 | public class FragmentStringTests 9 | { 10 | [Fact] 11 | public void Equals_EmptyFragmentStringAndDefaultFragmentString() 12 | { 13 | // Act and Assert 14 | Assert.Equal(default(FragmentString), FragmentString.Empty); 15 | Assert.Equal(default(FragmentString), FragmentString.Empty); 16 | // explicitly checking == operator 17 | Assert.True(FragmentString.Empty == default(FragmentString)); 18 | Assert.True(default(FragmentString) == FragmentString.Empty); 19 | } 20 | 21 | [Fact] 22 | public void NotEquals_DefaultFragmentStringAndNonNullFragmentString() 23 | { 24 | // Arrange 25 | var fragmentString = new FragmentString("#col=1"); 26 | 27 | // Act and Assert 28 | Assert.NotEqual(default(FragmentString), fragmentString); 29 | } 30 | 31 | [Fact] 32 | public void NotEquals_EmptyFragmentStringAndNonNullFragmentString() 33 | { 34 | // Arrange 35 | var fragmentString = new FragmentString("#col=1"); 36 | 37 | // Act and Assert 38 | Assert.NotEqual(fragmentString, FragmentString.Empty); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Abstractions.Tests/HttpResponseWritingExtensionsTests.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.Tasks; 6 | using Xunit; 7 | 8 | namespace Microsoft.AspNetCore.Http 9 | { 10 | public class HttpResponseWritingExtensionsTests 11 | { 12 | [Fact] 13 | public async Task WritingText_WriteText() 14 | { 15 | HttpContext context = CreateRequest(); 16 | await context.Response.WriteAsync("Hello World"); 17 | 18 | Assert.Equal(11, context.Response.Body.Length); 19 | } 20 | 21 | [Fact] 22 | public async Task WritingText_MultipleWrites() 23 | { 24 | HttpContext context = CreateRequest(); 25 | await context.Response.WriteAsync("Hello World"); 26 | await context.Response.WriteAsync("Hello World"); 27 | 28 | Assert.Equal(22, context.Response.Body.Length); 29 | } 30 | 31 | private HttpContext CreateRequest() 32 | { 33 | HttpContext context = new DefaultHttpContext(); 34 | context.Response.Body = new MemoryStream(); 35 | return context; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Abstractions.Tests/Microsoft.AspNetCore.Http.Abstractions.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(StandardTestTfms) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Extensions.Tests/Microsoft.AspNetCore.Http.Extensions.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(StandardTestTfms) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Extensions.Tests/ResponseExtensionTests.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 | using Microsoft.AspNetCore.Http.Features; 8 | using Xunit; 9 | 10 | namespace Microsoft.AspNetCore.Http.Extensions 11 | { 12 | public class ResponseExtensionTests 13 | { 14 | [Fact] 15 | public void Clear_ResetsResponse() 16 | { 17 | var context = new DefaultHttpContext(); 18 | context.Response.StatusCode = 201; 19 | context.Response.Headers["custom"] = "value"; 20 | context.Response.Body.Write(new byte[100], 0, 100); 21 | 22 | context.Response.Clear(); 23 | 24 | Assert.Equal(200, context.Response.StatusCode); 25 | Assert.Equal(string.Empty, context.Response.Headers["custom"].ToString()); 26 | Assert.Equal(0, context.Response.Body.Length); 27 | } 28 | 29 | [Fact] 30 | public void Clear_AlreadyStarted_Throws() 31 | { 32 | var context = new DefaultHttpContext(); 33 | context.Features.Set(new StartedResponseFeature()); 34 | 35 | Assert.Throws(() => context.Response.Clear()); 36 | } 37 | 38 | private class StartedResponseFeature : IHttpResponseFeature 39 | { 40 | public Stream Body { get; set; } 41 | 42 | public bool HasStarted { get { return true; } } 43 | 44 | public IHeaderDictionary Headers { get; set; } 45 | 46 | public string ReasonPhrase { get; set; } 47 | 48 | public int StatusCode { get; set; } 49 | 50 | public void OnCompleted(Func callback, object state) 51 | { 52 | throw new NotImplementedException(); 53 | } 54 | 55 | public void OnStarting(Func callback, object state) 56 | { 57 | throw new NotImplementedException(); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Extensions.Tests/SendFileResponseExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. See License.txt in the project root for license information. 2 | 3 | using System.IO; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Http.Features; 7 | using Xunit; 8 | 9 | namespace Microsoft.AspNetCore.Http.Extensions.Tests 10 | { 11 | public class SendFileResponseExtensionsTests 12 | { 13 | [Fact] 14 | public Task SendFileWhenFileNotFoundThrows() 15 | { 16 | var response = new DefaultHttpContext().Response; 17 | return Assert.ThrowsAsync(() => response.SendFileAsync("foo")); 18 | } 19 | 20 | [Fact] 21 | public async Task SendFileWorks() 22 | { 23 | var context = new DefaultHttpContext(); 24 | var response = context.Response; 25 | var fakeFeature = new FakeSendFileFeature(); 26 | context.Features.Set(fakeFeature); 27 | 28 | await response.SendFileAsync("bob", 1, 3, CancellationToken.None); 29 | 30 | Assert.Equal("bob", fakeFeature.name); 31 | Assert.Equal(1, fakeFeature.offset); 32 | Assert.Equal(3, fakeFeature.length); 33 | Assert.Equal(CancellationToken.None, fakeFeature.token); 34 | } 35 | 36 | private class FakeSendFileFeature : IHttpSendFileFeature 37 | { 38 | public string name = null; 39 | public long offset = 0; 40 | public long? length = null; 41 | public CancellationToken token; 42 | 43 | public Task SendFileAsync(string path, long offset, long? length, CancellationToken cancellation) 44 | { 45 | this.name = path; 46 | this.offset = offset; 47 | this.length = length; 48 | this.token = cancellation; 49 | return Task.FromResult(0); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Features.Tests/FeatureCollectionTests.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 Xunit; 5 | 6 | namespace Microsoft.AspNetCore.Http.Features 7 | { 8 | public class FeatureCollectionTests 9 | { 10 | [Fact] 11 | public void AddedInterfaceIsReturned() 12 | { 13 | var interfaces = new FeatureCollection(); 14 | var thing = new Thing(); 15 | 16 | interfaces[typeof(IThing)] = thing; 17 | 18 | object thing2 = interfaces[typeof(IThing)]; 19 | Assert.Equal(thing2, thing); 20 | } 21 | 22 | [Fact] 23 | public void IndexerAlsoAddsItems() 24 | { 25 | var interfaces = new FeatureCollection(); 26 | var thing = new Thing(); 27 | 28 | interfaces[typeof(IThing)] = thing; 29 | 30 | Assert.Equal(interfaces[typeof(IThing)], thing); 31 | } 32 | 33 | [Fact] 34 | public void SetNullValueRemoves() 35 | { 36 | var interfaces = new FeatureCollection(); 37 | var thing = new Thing(); 38 | 39 | interfaces[typeof(IThing)] = thing; 40 | Assert.Equal(interfaces[typeof(IThing)], thing); 41 | 42 | interfaces[typeof(IThing)] = null; 43 | 44 | object thing2 = interfaces[typeof(IThing)]; 45 | Assert.Null(thing2); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Features.Tests/IThing.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 IThing 7 | { 8 | string Hello(); 9 | } 10 | } -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Features.Tests/Microsoft.AspNetCore.Http.Features.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(StandardTestTfms) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Features.Tests/Thing.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 class Thing : IThing 7 | { 8 | public string Hello() 9 | { 10 | return "World"; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Tests/Features/FakeResponseFeature.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.Threading.Tasks; 7 | 8 | namespace Microsoft.AspNetCore.Http.Features 9 | { 10 | public class FakeResponseFeature : HttpResponseFeature 11 | { 12 | List, object>> _onCompletedCallbacks = new List, object>>(); 13 | 14 | public override void OnCompleted(Func callback, object state) 15 | { 16 | _onCompletedCallbacks.Add(new Tuple, object>(callback, state)); 17 | } 18 | 19 | public async Task CompleteAsync() 20 | { 21 | var callbacks = _onCompletedCallbacks; 22 | _onCompletedCallbacks = null; 23 | foreach (var callback in callbacks) 24 | { 25 | await callback.Item1(callback.Item2); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Tests/Features/HttpRequestIdentifierFeatureTests.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 Xunit; 5 | 6 | namespace Microsoft.AspNetCore.Http.Features 7 | { 8 | public class HttpRequestIdentifierFeatureTests 9 | { 10 | [Fact] 11 | public void TraceIdentifier_ReturnsId() 12 | { 13 | var feature = new HttpRequestIdentifierFeature(); 14 | 15 | var id = feature.TraceIdentifier; 16 | 17 | Assert.NotNull(id); 18 | } 19 | 20 | [Fact] 21 | public void TraceIdentifier_ReturnsStableId() 22 | { 23 | var feature = new HttpRequestIdentifierFeature(); 24 | 25 | var id1 = feature.TraceIdentifier; 26 | var id2 = feature.TraceIdentifier; 27 | 28 | Assert.Equal(id1, id2); 29 | } 30 | 31 | [Fact] 32 | public void TraceIdentifier_ReturnsUniqueIdForDifferentInstances() 33 | { 34 | var feature1 = new HttpRequestIdentifierFeature(); 35 | var feature2 = new HttpRequestIdentifierFeature(); 36 | 37 | var id1 = feature1.TraceIdentifier; 38 | var id2 = feature2.TraceIdentifier; 39 | 40 | Assert.NotEqual(id1, id2); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Tests/Features/NonSeekableReadStream.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; 7 | using System.Threading.Tasks; 8 | 9 | namespace Microsoft.AspNetCore.Http.Features 10 | { 11 | public class NonSeekableReadStream : Stream 12 | { 13 | private Stream _inner; 14 | 15 | public NonSeekableReadStream(byte[] data) 16 | : this(new MemoryStream(data)) 17 | { 18 | } 19 | 20 | public NonSeekableReadStream(Stream inner) 21 | { 22 | _inner = inner; 23 | } 24 | 25 | public override bool CanRead => _inner.CanRead; 26 | 27 | public override bool CanSeek => false; 28 | 29 | public override bool CanWrite => false; 30 | 31 | public override long Length 32 | { 33 | get { throw new NotSupportedException(); } 34 | } 35 | 36 | public override long Position 37 | { 38 | get { throw new NotSupportedException(); } 39 | set { throw new NotSupportedException(); } 40 | } 41 | 42 | public override void Flush() 43 | { 44 | throw new NotImplementedException(); 45 | } 46 | 47 | public override long Seek(long offset, SeekOrigin origin) 48 | { 49 | throw new NotSupportedException(); 50 | } 51 | 52 | public override void SetLength(long value) 53 | { 54 | throw new NotSupportedException(); 55 | } 56 | 57 | public override void Write(byte[] buffer, int offset, int count) 58 | { 59 | throw new NotSupportedException(); 60 | } 61 | 62 | public override int Read(byte[] buffer, int offset, int count) 63 | { 64 | return _inner.Read(buffer, offset, count); 65 | } 66 | 67 | public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) 68 | { 69 | return _inner.ReadAsync(buffer, offset, count, cancellationToken); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Tests/Features/QueryFeatureTests.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 Xunit; 5 | 6 | namespace Microsoft.AspNetCore.Http.Features 7 | { 8 | public class QueryFeatureTests 9 | { 10 | [Fact] 11 | public void QueryReturnsParsedQueryCollection() 12 | { 13 | // Arrange 14 | var features = new FeatureCollection(); 15 | var request = new HttpRequestFeature(); 16 | request.QueryString = "foo=bar"; 17 | features[typeof(IHttpRequestFeature)] = request; 18 | 19 | var provider = new QueryFeature(features); 20 | 21 | // Act 22 | var queryCollection = provider.Query; 23 | 24 | // Assert 25 | Assert.Equal("bar", queryCollection["foo"]); 26 | } 27 | 28 | [Theory] 29 | [InlineData("?q", "q")] 30 | [InlineData("?q&", "q")] 31 | [InlineData("?q1=abc&q2", "q2")] 32 | [InlineData("?q=", "q")] 33 | [InlineData("?q=&", "q")] 34 | public void KeyWithoutValuesAddedToQueryCollection(string queryString, string emptyParam) 35 | { 36 | var features = new FeatureCollection(); 37 | var request = new HttpRequestFeature(); 38 | request.QueryString = queryString; 39 | features[typeof(IHttpRequestFeature)] = request; 40 | 41 | var provider = new QueryFeature(features); 42 | 43 | var queryCollection = provider.Query; 44 | 45 | Assert.True(queryCollection.Keys.Contains(emptyParam)); 46 | Assert.Equal(string.Empty, queryCollection[emptyParam]); 47 | } 48 | 49 | [Theory] 50 | [InlineData("?&&")] 51 | [InlineData("?&")] 52 | [InlineData("&&")] 53 | public void EmptyKeysNotAddedToQueryCollection(string queryString) 54 | { 55 | var features = new FeatureCollection(); 56 | var request = new HttpRequestFeature(); 57 | request.QueryString = queryString; 58 | features[typeof(IHttpRequestFeature)] = request; 59 | 60 | var provider = new QueryFeature(features); 61 | 62 | var queryCollection = provider.Query; 63 | 64 | Assert.Equal(0, queryCollection.Count); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Tests/HttpContextFactoryTests.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 Microsoft.AspNetCore.Http.Features; 7 | using Microsoft.Extensions.Options; 8 | using Xunit; 9 | 10 | namespace Microsoft.AspNetCore.Http 11 | { 12 | public class HttpContextFactoryTests 13 | { 14 | [Fact] 15 | public void CreateHttpContextSetsHttpContextAccessor() 16 | { 17 | // Arrange 18 | var accessor = new HttpContextAccessor(); 19 | var contextFactory = new HttpContextFactory(Options.Create(new FormOptions()), accessor); 20 | 21 | // Act 22 | var context = contextFactory.Create(new FeatureCollection()); 23 | 24 | // Assert 25 | Assert.Same(context, accessor.HttpContext); 26 | } 27 | 28 | [Fact] 29 | public void DisposeHttpContextSetsHttpContextAccessorToNull() 30 | { 31 | // Arrange 32 | var accessor = new HttpContextAccessor(); 33 | var contextFactory = new HttpContextFactory(Options.Create(new FormOptions()), accessor); 34 | 35 | // Act 36 | var context = contextFactory.Create(new FeatureCollection()); 37 | 38 | // Assert 39 | Assert.Same(context, accessor.HttpContext); 40 | 41 | contextFactory.Dispose(context); 42 | 43 | Assert.Null(accessor.HttpContext); 44 | } 45 | 46 | [Fact] 47 | public void AllowsCreatingContextWithoutSettingAccessor() 48 | { 49 | // Arrange 50 | var contextFactory = new HttpContextFactory(Options.Create(new FormOptions())); 51 | 52 | // Act & Assert 53 | var context = contextFactory.Create(new FeatureCollection()); 54 | contextFactory.Dispose(context); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Tests/HttpServiceCollectionExtensionsTests.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.DependencyInjection; 6 | using Xunit; 7 | 8 | namespace Microsoft.AspNetCore.Http.Tests 9 | { 10 | public class HttpServiceCollectionExtensionsTests 11 | { 12 | [Fact] 13 | public void AddHttpContextAccessor_AddsWithCorrectLifetime() 14 | { 15 | // Arrange 16 | var services = new ServiceCollection(); 17 | 18 | // Act 19 | services.AddHttpContextAccessor(); 20 | 21 | // Assert 22 | var descriptor = services[0]; 23 | Assert.Equal(ServiceLifetime.Singleton, descriptor.Lifetime); 24 | Assert.Equal(typeof(HttpContextAccessor), descriptor.ImplementationType); 25 | } 26 | 27 | [Fact] 28 | public void AddHttpContextAccessor_ThrowsWithoutServices() 29 | { 30 | Assert.Throws("services", () => HttpServiceCollectionExtensions.AddHttpContextAccessor(null)); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Tests/Internal/BufferingHelperTests.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 Xunit; 6 | 7 | namespace Microsoft.AspNetCore.Http.Internal 8 | { 9 | public class BufferingHelperTests 10 | { 11 | [Fact] 12 | public void GetTempDirectory_Returns_Valid_Location() 13 | { 14 | var tempDirectory = BufferingHelper.TempDirectory; 15 | Assert.NotNull(tempDirectory); 16 | Assert.True(Directory.Exists(tempDirectory)); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Tests/Microsoft.AspNetCore.Http.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(StandardTestTfms) 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Tests/PipeTest.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.IO.Pipelines; 7 | 8 | namespace Microsoft.AspNetCore.Http.Tests 9 | { 10 | public abstract class PipeTest : IDisposable 11 | { 12 | protected const int MaximumSizeHigh = 65; 13 | 14 | public MemoryStream MemoryStream { get; set; } 15 | 16 | public PipeWriter Writer { get; set; } 17 | 18 | protected PipeTest() 19 | { 20 | MemoryStream = new MemoryStream(); 21 | Writer = new StreamPipeWriter(MemoryStream, 4096, new TestMemoryPool()); 22 | } 23 | 24 | public void Dispose() 25 | { 26 | Writer.Complete(); 27 | } 28 | 29 | public byte[] Read() 30 | { 31 | Writer.FlushAsync().GetAwaiter().GetResult(); 32 | return ReadWithoutFlush(); 33 | } 34 | 35 | public byte[] ReadWithoutFlush() 36 | { 37 | MemoryStream.Position = 0; 38 | var buffer = new byte[MemoryStream.Length]; 39 | var result = MemoryStream.Read(buffer, 0, (int)MemoryStream.Length); 40 | return buffer; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Http.Tests/RequestCookiesCollectionTests.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.Linq; 5 | using Microsoft.AspNetCore.Http.Internal; 6 | using Microsoft.Extensions.Primitives; 7 | using Xunit; 8 | 9 | namespace Microsoft.AspNetCore.Http.Tests 10 | { 11 | public class RequestCookiesCollectionTests 12 | { 13 | public static TheoryData UnEscapesKeyValues_Data 14 | { 15 | get 16 | { 17 | // key, value, expected 18 | return new TheoryData 19 | { 20 | { "key=value", "key", "value" }, 21 | { "key%2C=%21value", "key,", "!value" }, 22 | { "ke%23y%2C=val%5Eue", "ke#y,", "val^ue" }, 23 | { "base64=QUI%2BREU%2FRw%3D%3D", "base64", "QUI+REU/Rw==" }, 24 | { "base64=QUI+REU/Rw==", "base64", "QUI+REU/Rw==" }, 25 | }; 26 | } 27 | } 28 | 29 | [Theory] 30 | [MemberData(nameof(UnEscapesKeyValues_Data))] 31 | public void UnEscapesKeyValues( 32 | string input, 33 | string expectedKey, 34 | string expectedValue) 35 | { 36 | var cookies = RequestCookieCollection.Parse(new StringValues(input)); 37 | 38 | Assert.Equal(1, cookies.Count); 39 | Assert.Equal(expectedKey, cookies.Keys.Single()); 40 | Assert.Equal(expectedValue, cookies[expectedKey]); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.Owin.Tests/Microsoft.AspNetCore.Owin.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(StandardTestTfms) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.WebUtilities.Tests/FormReaderAsyncTest.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.Threading.Tasks; 6 | using Microsoft.Extensions.Primitives; 7 | 8 | namespace Microsoft.AspNetCore.WebUtilities 9 | { 10 | public class FormReaderAsyncTest : FormReaderTests 11 | { 12 | protected override async Task> ReadFormAsync(FormReader reader) 13 | { 14 | return await reader.ReadFormAsync(); 15 | } 16 | 17 | protected override async Task?> ReadPair(FormReader reader) 18 | { 19 | return await reader.ReadNextPairAsync(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.WebUtilities.Tests/Microsoft.AspNetCore.WebUtilities.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(StandardTestTfms) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.WebUtilities.Tests/NonSeekableReadStream.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; 7 | using System.Threading.Tasks; 8 | 9 | namespace Microsoft.AspNetCore.WebUtilities 10 | { 11 | public class NonSeekableReadStream : Stream 12 | { 13 | private Stream _inner; 14 | 15 | public NonSeekableReadStream(byte[] data) 16 | : this(new MemoryStream(data)) 17 | { 18 | } 19 | 20 | public NonSeekableReadStream(Stream inner) 21 | { 22 | _inner = inner; 23 | } 24 | 25 | public override bool CanRead => _inner.CanRead; 26 | 27 | public override bool CanSeek => false; 28 | 29 | public override bool CanWrite => false; 30 | 31 | public override long Length 32 | { 33 | get { throw new NotSupportedException(); } 34 | } 35 | 36 | public override long Position 37 | { 38 | get { throw new NotSupportedException(); } 39 | set { throw new NotSupportedException(); } 40 | } 41 | 42 | public override void Flush() 43 | { 44 | throw new NotImplementedException(); 45 | } 46 | 47 | public override long Seek(long offset, SeekOrigin origin) 48 | { 49 | throw new NotSupportedException(); 50 | } 51 | 52 | public override void SetLength(long value) 53 | { 54 | throw new NotSupportedException(); 55 | } 56 | 57 | public override void Write(byte[] buffer, int offset, int count) 58 | { 59 | throw new NotSupportedException(); 60 | } 61 | 62 | public override int Read(byte[] buffer, int offset, int count) 63 | { 64 | count = Math.Max(count, 1); 65 | return _inner.Read(buffer, offset, count); 66 | } 67 | 68 | public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) 69 | { 70 | count = Math.Max(count, 1); 71 | return _inner.ReadAsync(buffer, offset, count, cancellationToken); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/Microsoft.AspNetCore.WebUtilities.Tests/WebEncodersTests.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 Xunit; 6 | 7 | namespace Microsoft.AspNetCore.WebUtilities 8 | { 9 | public class WebEncodersTests 10 | { 11 | 12 | [Theory] 13 | [InlineData("", 1, 0)] 14 | [InlineData("", 0, 1)] 15 | [InlineData("0123456789", 9, 2)] 16 | [InlineData("0123456789", Int32.MaxValue, 2)] 17 | [InlineData("0123456789", 9, -1)] 18 | public void Base64UrlDecode_BadOffsets(string input, int offset, int count) 19 | { 20 | // Act & assert 21 | Assert.ThrowsAny(() => 22 | { 23 | var retVal = WebEncoders.Base64UrlDecode(input, offset, count); 24 | }); 25 | } 26 | 27 | [Theory] 28 | [InlineData(0, 1, 0)] 29 | [InlineData(0, 0, 1)] 30 | [InlineData(10, 9, 2)] 31 | [InlineData(10, Int32.MaxValue, 2)] 32 | [InlineData(10, 9, -1)] 33 | public void Base64UrlEncode_BadOffsets(int inputLength, int offset, int count) 34 | { 35 | // Arrange 36 | byte[] input = new byte[inputLength]; 37 | 38 | // Act & assert 39 | Assert.ThrowsAny(() => 40 | { 41 | var retVal = WebEncoders.Base64UrlEncode(input, offset, count); 42 | }); 43 | } 44 | 45 | [Fact] 46 | public void DataOfVariousLengthRoundTripCorrectly() 47 | { 48 | for (int length = 0; length != 256; ++length) 49 | { 50 | var data = new byte[length]; 51 | for (int index = 0; index != length; ++index) 52 | { 53 | data[index] = (byte)(5 + length + (index * 23)); 54 | } 55 | string text = WebEncoders.Base64UrlEncode(data); 56 | byte[] result = WebEncoders.Base64UrlDecode(text); 57 | 58 | for (int index = 0; index != length; ++index) 59 | { 60 | Assert.Equal(data[index], result[index]); 61 | } 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /test/Microsoft.Net.Http.Headers.Tests/Microsoft.Net.Http.Headers.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(StandardTestTfms) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /version.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 3.0.0 4 | alpha1 5 | $(VersionPrefix) 6 | $(VersionPrefix)-$(VersionSuffix)-final 7 | t000 8 | a- 9 | $(FeatureBranchVersionPrefix)$(VersionSuffix)-$([System.Text.RegularExpressions.Regex]::Replace('$(FeatureBranchVersionSuffix)', '[^\w-]', '-')) 10 | $(VersionSuffix)-$(BuildNumber) 11 | 12 | 13 | --------------------------------------------------------------------------------