diff --git a/.appveyor.yml b/.appveyor.yml
new file mode 100644
index 000000000..776f337d8
--- /dev/null
+++ b/.appveyor.yml
@@ -0,0 +1,20 @@
+init:
+ - git config --global core.autocrlf true
+branches:
+ only:
+ - main
+ - /^(.*\/)?ci-.*$/
+ - /^rel\/.*/
+configuration:
+ - CodeAnalysis
+ - Release
+matrix:
+ fast_finish: true
+before_build:
+ - cmd: .\build.cmd EnableSkipStrongNames
+build_script:
+ - cmd: .\build.cmd UnitTest /P:Configuration=%Configuration%
+clone_depth: 1
+test: off
+deploy: off
+os: Visual Studio 2017
diff --git a/.azuredevops/dependabot.yml b/.azuredevops/dependabot.yml
new file mode 100644
index 000000000..e99cd24bd
--- /dev/null
+++ b/.azuredevops/dependabot.yml
@@ -0,0 +1,3 @@
+version: 2
+enable-campaigned-updates: false
+enable-security-updates: false
diff --git a/.config/CredScanSuppressions.json b/.config/CredScanSuppressions.json
new file mode 100644
index 000000000..8db08e538
--- /dev/null
+++ b/.config/CredScanSuppressions.json
@@ -0,0 +1,29 @@
+{
+ "tool": "Credential Scanner",
+ "suppressions": [
+ {
+ "placeholder": "abcdefg",
+ "_justification": "This is a fake password used in test code."
+ },
+ {
+ "placeholder": "Pa$$AAECAw==",
+ "_justification": "This is a fake password used in test code."
+ },
+ {
+ "placeholder": "ALyuoraY/cIWD1hjo+K81/pf83qo6Q6T+UBYcXN9P3A9WHLvEY10f+lwW5qPG6h9xw==",
+ "_justification": "This is a fake hashed password used in test code."
+ },
+ {
+ "placeholder": "abcdefg123",
+ "_justification": "This is a fake password used in test code."
+ },
+ {
+ "placeholder": "3e29b24f825e737d97aed5eb62df5076",
+ "_justification": "This is a fake password used in test code."
+ },
+ {
+ "placeholder": "My Password",
+ "_justification": "This is a fake password used in test code."
+ }
+ ]
+}
\ No newline at end of file
diff --git a/.config/tsaoptions.json b/.config/tsaoptions.json
new file mode 100644
index 000000000..cb7d8b10a
--- /dev/null
+++ b/.config/tsaoptions.json
@@ -0,0 +1,12 @@
+{
+ "areaPath": "DevDiv\\ASP.NET Core\\Policy Violations",
+ "codebaseName": "AspNetWebStack",
+ "instanceUrl": "https://devdiv.visualstudio.com/",
+ "iterationPath": "DevDiv",
+ "notificationAliases": [
+ "aspnetcore-build@microsoft.com"
+ ],
+ "projectName": "DEVDIV",
+ "repositoryName": "AspNetWebStack",
+ "template": "TFSDEVDIV"
+}
diff --git a/.gitignore b/.gitignore
index 4d0b89238..9f67f0ee8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,20 +1,20 @@
-[Bb]in
-[Oo]bj
-[Tt]est[Rr]esults
-*.suo
-*.user
+.msbuild/
+.vs/
+bin/
+obj/
+packages/
+
*.[Cc]ache
-*[Rr]esharper*
-packages
-NuGet.exe
-_[Ss]cripts
-*.exe
+*.binlog
*.dll
-*.nupkg
*.dot[Cc]over
-*.vsp
-*.psess
+*.exe
+*.nupkg
*.orig
+*.psess
*.sln.ide
-.vs/
-project.lock.json
\ No newline at end of file
+*.suo
+*.user
+*.vsp
+*[Rr]esharper*
+*launchSettings.json
diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config
deleted file mode 100644
index 6ff25f633..000000000
--- a/.nuget/NuGet.Config
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.nuget/packages.config b/.nuget/packages.config
index d666c4dd7..a8fe9612a 100644
--- a/.nuget/packages.config
+++ b/.nuget/packages.config
@@ -2,6 +2,6 @@
-
-
+
+
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 000000000..a9a61ca73
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,11 @@
+language: csharp
+sudo: false
+dist: trusty
+mono: none
+os:
+ - linux
+branches:
+ only:
+ - not.a.branch
+script:
+ - echo Skipping builds for now.
diff --git a/CODE-OF-CONDUCT.md b/CODE-OF-CONDUCT.md
new file mode 100644
index 000000000..775f221c9
--- /dev/null
+++ b/CODE-OF-CONDUCT.md
@@ -0,0 +1,6 @@
+# Code of Conduct
+
+This project has adopted the code of conduct defined by the Contributor Covenant
+to clarify expected behavior in our community.
+
+For more information, see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 87a1e8276..89c98a590 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -2,7 +2,6 @@
One of the easiest ways to contribute is to participate in discussions and discuss issues. You can also contribute by submitting pull requests with code changes.
-
## Bugs and feature requests?
For non-security related bugs please log a new issue in this repo.
@@ -12,10 +11,10 @@ Security issues and bugs should be reported privately, via email, to the Microso
## Other discussions
Our team members also monitor several other discussion forums:
-* [ASP.NET Core forum](https://forums.asp.net/1255.aspx/1?ASP+NET+5)
-* [StackOverflow](https://stackoverflow.com/) with the [`asp.net-core`](https://stackoverflow.com/questions/tagged/asp.net-core), [`asp.net-core-mvc`](https://stackoverflow.com/questions/tagged/asp.net-core-mvc), or [`entity-framework-core`](https://stackoverflow.com/questions/tagged/entity-framework-core) tags.
-* [JabbR chat room](https://jabbr.net/#/rooms/AspNetCore) for real-time discussions with the community and the people who work on the project
-
+* [ASP.NET MVC forum](https://forums.asp.net/1146.aspx/1?MVC)
+* [ASP.NET Web API forum](https://forums.asp.net/1246.aspx/1?Web+API)
+* [ASP.NET Web Pages forum](https://forums.asp.net/1224.aspx/1?ASP+NET+Web+Pages)
+* [StackOverflow](https://stackoverflow.com/) with the [`asp.net`](https://stackoverflow.com/questions/tagged/asp.net), [`asp.net-mvc`](https://stackoverflow.com/questions/tagged/asp.net-mvc), [`asp.net-web-api`](https://stackoverflow.com/questions/tagged/asp.net-web-api), [`asp.net-webpages`](https://stackoverflow.com/questions/tagged/asp.net-webpages) or [`razor`](https://stackoverflow.com/questions/tagged/razor) tags.
## Filing issues
When filing issues, please use our [bug filing templates](https://github.com/aspnet/Home/wiki/Functional-bug-template).
@@ -32,7 +31,6 @@ Here are questions you can answer before you file a bug to make sure you're not
GitHub supports [markdown](https://help.github.com/articles/github-flavored-markdown/), so when filing bugs make sure you check the formatting before clicking submit.
-
## Contributing code and content
You will need to sign a [Contributor License Agreement](https://cla2.dotnetfoundation.org/) before submitting your pull request. To complete the Contributor License Agreement (CLA), you will need to submit a request via the form and then electronically sign the Contributor License Agreement when you receive the email containing the link to the document. This needs to only be done once for any .NET Foundation OSS project.
@@ -58,4 +56,3 @@ Addresses #bugnumber (in this specific format)
- Tests only need to be present for issues that need to be verified by QA (e.g. not tasks)
- If there is a scenario that is far too hard to test there does not need to be a test for it.
- "Too hard" is determined by the team as a whole.
-
diff --git a/Directory.Build.props b/Directory.Build.props
new file mode 100644
index 000000000..fef50e3d3
--- /dev/null
+++ b/Directory.Build.props
@@ -0,0 +1,16 @@
+
+
+
+
+
+ 16.0
+
+ true
+
+ false
+
+
+
diff --git a/Directory.Build.targets b/Directory.Build.targets
new file mode 100644
index 000000000..080cbd855
--- /dev/null
+++ b/Directory.Build.targets
@@ -0,0 +1,3 @@
+
+
+
diff --git a/NuGet.Config b/NuGet.Config
new file mode 100644
index 000000000..837d83954
--- /dev/null
+++ b/NuGet.Config
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index a6a2a88de..f4c49434b 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,6 @@
-ASP.NET MVC, Web API, Web Pages, and Razor
-===
+# ASP.NET MVC, Web API, Web Pages, and Razor
-## Note: This repo is for ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x. For ASP.NET Core MVC, check the [MVC repo](https://github.com/aspnet/Mvc).
+## Note: This repo is for ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x. For ASP.NET Core MVC, check the [AspNetCore repo](https://github.com/aspnet/AspNetCore).
ASP.NET MVC is a web framework that gives you a powerful, patterns-based way to build dynamic websites and Web APIs. ASP.NET MVC enables a clean separation of concerns and gives you full control over markup.
@@ -12,6 +11,19 @@ This repo includes:
* ASP.NET Web Pages 3.x
* ASP.NET Razor 3.x
-### Nightly builds
+### Contributing
-The latest built and tested packages from this repo are available on this MyGet feed: https://myget.org/gallery/aspnetwebstacknightly
+Check out the [contributing](CONTRIBUTING.md) page to see the best places to log issues and start discussions.
+
+### Tags and releases
+
+Git tag or branch|Other products|MVC package versions|Web API package (product) versions|Web Pages package versions
+--------|--------------|------------|------------|------------
+[v2.0.4](https://github.com/aspnet/AspNetWebStack/tree/v2.0.4)||4.0.40804|4.0.30506|2.0.30506
+[v2.1](https://github.com/aspnet/AspNetWebStack/tree/v2.1)|ASP.NET and Web Tools 2012.2, VS 2012 Update 2 (not on http://nuget.org)|v4 2012.2 Update RTM|v1 2012.2 Update RTM|v2 2012.2 Update RTM
+[v3.0.2](https://github.com/aspnet/AspNetWebStack/tree/v3.0.2)||5.0.2|5.0.1 (2.0.1)|3.0.1
+[v3.1.3](https://github.com/aspnet/AspNetWebStack/tree/v3.1.3)||5.1.3|5.1.2 (2.1.2)|3.1.2
+[v3.2.6](https://github.com/aspnet/AspNetWebStack/tree/v3.2.6)||5.2.6|5.2.6|3.2.6
+[v3.2.7](https://github.com/aspnet/AspNetWebStack/tree/v3.2.7)||5.2.7|5.2.7|3.2.7
+[v3.2.8](https://github.com/aspnet/AspNetWebStack/tree/v3.2.8)||5.2.8|5.2.8|3.2.8
+[main](https://github.com/aspnet/AspNetWebStack/tree/main)|New work e.g. MVC 5.2.9-preview1||||
diff --git a/Runtime.NetFramework.slnf b/Runtime.NetFramework.slnf
new file mode 100644
index 000000000..7b79711ff
--- /dev/null
+++ b/Runtime.NetFramework.slnf
@@ -0,0 +1,57 @@
+{
+ "solution": {
+ "path": "Runtime.sln",
+ "projects": [
+ "src\\Microsoft.AspNet.Facebook\\Microsoft.AspNet.Facebook.csproj",
+ "src\\Microsoft.Web.Helpers\\Microsoft.Web.Helpers.csproj",
+ "src\\Microsoft.Web.Mvc\\Microsoft.Web.Mvc.csproj",
+ "src\\Microsoft.Web.WebPages.OAuth\\Microsoft.Web.WebPages.OAuth.csproj",
+ "src\\System.Net.Http.Formatting\\System.Net.Http.Formatting.csproj",
+ "src\\System.Web.Cors\\System.Web.Cors.csproj",
+ "src\\System.Web.Helpers\\System.Web.Helpers.csproj",
+ "src\\System.Web.Http.Cors\\System.Web.Http.Cors.csproj",
+ "src\\System.Web.Http.Owin\\System.Web.Http.Owin.csproj",
+ "src\\System.Web.Http.SelfHost\\System.Web.Http.SelfHost.csproj",
+ "src\\System.Web.Http.SignalR\\System.Web.Http.SignalR.csproj",
+ "src\\System.Web.Http.Tracing\\System.Web.Http.Tracing.csproj",
+ "src\\System.Web.Http.WebHost\\System.Web.Http.WebHost.csproj",
+ "src\\System.Web.Http\\System.Web.Http.csproj",
+ "src\\System.Web.Mvc\\System.Web.Mvc.csproj",
+ "src\\System.Web.Razor\\System.Web.Razor.csproj",
+ "src\\System.Web.WebPages.Administration\\System.Web.WebPages.Administration.csproj",
+ "src\\System.Web.WebPages.Deployment\\System.Web.WebPages.Deployment.csproj",
+ "src\\System.Web.WebPages.Razor\\System.Web.WebPages.Razor.csproj",
+ "src\\System.Web.WebPages\\System.Web.WebPages.csproj",
+ "src\\WebApiHelpPage\\VB\\WebApiHelpPageVB.vbproj",
+ "src\\WebApiHelpPage\\WebApiHelpPage.csproj",
+ "src\\WebMatrix.Data\\WebMatrix.Data.csproj",
+ "src\\WebMatrix.WebData\\WebMatrix.WebData.csproj",
+ "test\\Microsoft.AspNet.Facebook.Test\\Microsoft.AspNet.Facebook.Test.csproj",
+ "test\\Microsoft.TestCommon\\Microsoft.TestCommon.csproj",
+ "test\\Microsoft.Web.Helpers.Test\\Microsoft.Web.Helpers.Test.csproj",
+ "test\\Microsoft.Web.Mvc.Test\\Microsoft.Web.Mvc.Test.csproj",
+ "test\\Microsoft.Web.WebPages.OAuth.Test\\Microsoft.Web.WebPages.OAuth.Test.csproj",
+ "test\\System.Net.Http.Formatting.Test\\System.Net.Http.Formatting.Test.csproj",
+ "test\\System.Web.Cors.Test\\System.Web.Cors.Test.csproj",
+ "test\\System.Web.Helpers.Test\\System.Web.Helpers.Test.csproj",
+ "test\\System.Web.Http.Cors.Test\\System.Web.Http.Cors.Test.csproj",
+ "test\\System.Web.Http.Integration.Test\\System.Web.Http.Integration.Test.csproj",
+ "test\\System.Web.Http.Owin.Test\\System.Web.Http.Owin.Test.csproj",
+ "test\\System.Web.Http.SelfHost.Test\\System.Web.Http.SelfHost.Test.csproj",
+ "test\\System.Web.Http.SignalR.Test\\System.Web.Http.SignalR.Test.csproj",
+ "test\\System.Web.Http.Test\\System.Web.Http.Test.csproj",
+ "test\\System.Web.Http.Tracing.Test\\System.Web.Http.Tracing.Test.csproj",
+ "test\\System.Web.Http.WebHost.Test\\System.Web.Http.WebHost.Test.csproj",
+ "test\\System.Web.Mvc.Test\\System.Web.Mvc.Test.csproj",
+ "test\\System.Web.Razor.Test\\System.Web.Razor.Test.csproj",
+ "test\\System.Web.WebPages.Administration.Test\\System.Web.WebPages.Administration.Test.csproj",
+ "test\\System.Web.WebPages.Deployment.Test\\System.Web.WebPages.Deployment.Test.csproj",
+ "test\\System.Web.WebPages.Razor.Test\\System.Web.WebPages.Razor.Test.csproj",
+ "test\\System.Web.WebPages.Test\\System.Web.WebPages.Test.csproj",
+ "test\\WebApiHelpPage.Test\\WebApiHelpPage.Test.csproj",
+ "test\\WebApiHelpPage.VB.Test\\WebApiHelpPage.VB.Test.csproj",
+ "test\\WebMatrix.Data.Test\\WebMatrix.Data.Test.csproj",
+ "test\\WebMatrix.WebData.Test\\WebMatrix.WebData.Test.csproj"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/Runtime.NetStandard.slnf b/Runtime.NetStandard.slnf
new file mode 100644
index 000000000..b8270ab3e
--- /dev/null
+++ b/Runtime.NetStandard.slnf
@@ -0,0 +1,12 @@
+{
+ "solution": {
+ "path": "Runtime.sln",
+ "projects": [
+ "src\\System.Net.Http.Formatting.ns1_3\\System.Net.Http.Formatting.ns1_3.csproj",
+ "src\\System.Net.Http.Formatting.ns2_0\\System.Net.Http.Formatting.ns2_0.csproj",
+ "test\\Microsoft.TestCommon\\Microsoft.TestCommon.csproj",
+ "test\\System.Net.Http.Formatting.ns1_3.Test\\System.Net.Http.Formatting.ns1_3.Test.csproj",
+ "test\\System.Net.Http.Formatting.ns2_0.Test\\System.Net.Http.Formatting.ns2_0.Test.csproj"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/Runtime.msbuild b/Runtime.msbuild
index 0f4fc9eee..815aaf93e 100644
--- a/Runtime.msbuild
+++ b/Runtime.msbuild
@@ -8,25 +8,16 @@
Releasetruetrue
- truetruefalse
+ false
+ false$(MSBuildThisFileDirectory)bin\$(Configuration)\test\TestResults\$(MSBuildThisFileDirectory)packages\Microsoft.Web.SkipStrongNames.1.0.0\tools\SkipStrongNames.exe$(MSBuildThisFileDirectory)tools\SkipStrongNames.xml.nuget\NuGet.exe
-
-
- $(BuildInParallel)
-
-
- $(BuildInParallel)
- true
-
-
-
@@ -47,9 +38,8 @@
@@ -59,55 +49,100 @@
-
+
+
+ <_Testing_NetStandard1_3 Include="true;false" />
+
+
-
-
-
+
+
+
+
+
+
+
-
+
+
- $(MsBuildThisFileDirectory)tools\src\Microsoft.Web.FxCop\
- $(MsBuildThisFileDirectory)packages\CustomFxCopRules
+ $(MSBuildThisFileDirectory)tools\src\Microsoft.Web.FxCop\
+ $(MSBuildThisFileDirectory)packages\CustomFxCopRules
-
+
-
-
-
+
+
+
+
+
+
+ Projects="Runtime.sln"
+ BuildInParallel="$(BuildInParallel)"
+ Targets="Build"
+ Properties="Configuration=$(Configuration);CodeAnalysis=$(CodeAnalysis);StyleCopEnabled=$(StyleCopEnabled);
+ VisualStudioVersion=$(VisualStudioVersion)" />
-
-
-
+
-
-
- TestAssembly=%(TestDLLsXunit.FullPath);XmlPath=$(TestResultsDirectory)%(TestDLLsXunit.FileName)-XunitResults.xml
-
+ <_TestDLLsXunit Include="bin\$(Configuration)\test\*.Test.dll;
+ bin\$(Configuration)\test\*\net4*\*.Test.dll" />
+ <_XunitProject Include="tools\WebStack.testing.targets">
+ TestAssembly=%(_TestDLLsXunit.FullPath);
+ XmlPath=$(TestResultsDirectory)%(_TestDLLsXunit.FileName)-XunitResults.xml
+
+
+ <_VSTestDLLs Include="bin\$(Configuration)\test\ns1_3\**\*.Test.dll;
+ bin\$(Configuration)\test\ns2_0\**\*.Test.dll"
+ Exclude="bin\$(Configuration)\test\*\net4*\*.Test.dll" />
+ <_XunitProject Include="tools\WebStack.testing.targets">
+ TestAssembly=%(_VSTestDLLs.FullPath);
+ XmlPath=$(TestResultsDirectory)%(_VSTestDLLs.FileName)-$([System.String]::Copy('%(_VSTestDLLs.RecursiveDir)').Trim('\\'))-XunitResults.xml;
+ UseVSTest=true
+
-
+
-
+
+
+
@@ -117,7 +152,11 @@
-
+
+
+
+
diff --git a/Runtime.sln b/Runtime.sln
index 53af9bb27..56de063a7 100644
--- a/Runtime.sln
+++ b/Runtime.sln
@@ -1,8 +1,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.30501.0
-MinimumVisualStudioVersion = 10.0.40219.1
+# Visual Studio 15
+VisualStudioVersion = 15.0.27016.1
+MinimumVisualStudioVersion = 15.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A9836F9E-6DB3-4D9F-ADCA-CF42D8C8BA93}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{C40883CD-366D-4534-8B58-3EA0D13136DF}"
@@ -57,7 +57,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Web.Http.Test", "tes
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http.Formatting", "src\System.Net.Http.Formatting\System.Net.Http.Formatting.csproj", "{668E9021-CE84-49D9-98FB-DF125A9FCDB0}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.TestCommon", "test\Microsoft.TestCommon\Microsoft.TestCommon.csproj", "{FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestCommon", "test\Microsoft.TestCommon\Microsoft.TestCommon.csproj", "{FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http.Formatting.Test", "test\System.Net.Http.Formatting.Test\System.Net.Http.Formatting.Test.csproj", "{7AF77741-9158-4D5F-8782-8F21FADF025F}"
EndProject
@@ -95,9 +95,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Web.Http.Owin", "src
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Web.Http.Owin.Test", "test\System.Web.Http.Owin.Test\System.Web.Http.Owin.Test.csproj", "{C19267DD-3984-430C-AE18-4034F85DE4E5}"
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{CB34D534-9A09-4EE4-B350-C1C23AFBF5EE}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution items", "Solution items", "{CB34D534-9A09-4EE4-B350-C1C23AFBF5EE}"
ProjectSection(SolutionItems) = preProject
- .nuget\NuGet.Config = .nuget\NuGet.Config
+ global.json = global.json
+ NuGet.Config = NuGet.Config
.nuget\packages.config = .nuget\packages.config
EndProjectSection
EndProject
@@ -113,6 +114,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Facebook",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Facebook.Test", "test\Microsoft.AspNet.Facebook.Test\Microsoft.AspNet.Facebook.Test.csproj", "{C3BEF382-C7C4-454D-B017-1EAC03E9A82C}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.Http.Formatting.ns1_3", "src\System.Net.Http.Formatting.ns1_3\System.Net.Http.Formatting.ns1_3.csproj", "{5ABD9968-F3A3-4967-B768-A6142F69759E}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.Http.Formatting.ns2_0", "src\System.Net.Http.Formatting.ns2_0\System.Net.Http.Formatting.ns2_0.csproj", "{9AAFB58C-B8C1-4D7F-80E6-7B95C94A829B}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.Http.Formatting.ns1_3.Test", "test\System.Net.Http.Formatting.ns1_3.Test\System.Net.Http.Formatting.ns1_3.Test.csproj", "{A1A20049-04C2-4676-93CF-92449C4BBAA9}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.Http.Formatting.ns2_0.Test", "test\System.Net.Http.Formatting.ns2_0.Test\System.Net.Http.Formatting.ns2_0.Test.csproj", "{6C320AD9-F380-4F8B-85F9-0689F88766EC}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
CodeAnalysis|Any CPU = CodeAnalysis|Any CPU
@@ -420,6 +429,30 @@ Global
{C3BEF382-C7C4-454D-B017-1EAC03E9A82C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3BEF382-C7C4-454D-B017-1EAC03E9A82C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3BEF382-C7C4-454D-B017-1EAC03E9A82C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5ABD9968-F3A3-4967-B768-A6142F69759E}.CodeAnalysis|Any CPU.ActiveCfg = CodeAnalysis|Any CPU
+ {5ABD9968-F3A3-4967-B768-A6142F69759E}.CodeAnalysis|Any CPU.Build.0 = CodeAnalysis|Any CPU
+ {5ABD9968-F3A3-4967-B768-A6142F69759E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5ABD9968-F3A3-4967-B768-A6142F69759E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5ABD9968-F3A3-4967-B768-A6142F69759E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5ABD9968-F3A3-4967-B768-A6142F69759E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9AAFB58C-B8C1-4D7F-80E6-7B95C94A829B}.CodeAnalysis|Any CPU.ActiveCfg = CodeAnalysis|Any CPU
+ {9AAFB58C-B8C1-4D7F-80E6-7B95C94A829B}.CodeAnalysis|Any CPU.Build.0 = CodeAnalysis|Any CPU
+ {9AAFB58C-B8C1-4D7F-80E6-7B95C94A829B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9AAFB58C-B8C1-4D7F-80E6-7B95C94A829B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9AAFB58C-B8C1-4D7F-80E6-7B95C94A829B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9AAFB58C-B8C1-4D7F-80E6-7B95C94A829B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A1A20049-04C2-4676-93CF-92449C4BBAA9}.CodeAnalysis|Any CPU.ActiveCfg = CodeAnalysis|Any CPU
+ {A1A20049-04C2-4676-93CF-92449C4BBAA9}.CodeAnalysis|Any CPU.Build.0 = CodeAnalysis|Any CPU
+ {A1A20049-04C2-4676-93CF-92449C4BBAA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A1A20049-04C2-4676-93CF-92449C4BBAA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A1A20049-04C2-4676-93CF-92449C4BBAA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A1A20049-04C2-4676-93CF-92449C4BBAA9}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6C320AD9-F380-4F8B-85F9-0689F88766EC}.CodeAnalysis|Any CPU.ActiveCfg = CodeAnalysis|Any CPU
+ {6C320AD9-F380-4F8B-85F9-0689F88766EC}.CodeAnalysis|Any CPU.Build.0 = CodeAnalysis|Any CPU
+ {6C320AD9-F380-4F8B-85F9-0689F88766EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6C320AD9-F380-4F8B-85F9-0689F88766EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6C320AD9-F380-4F8B-85F9-0689F88766EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6C320AD9-F380-4F8B-85F9-0689F88766EC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -475,5 +508,12 @@ Global
{1E89A3E9-0A7F-418F-B4BE-6E38A6315373} = {C40883CD-366D-4534-8B58-3EA0D13136DF}
{821A136C-7C6F-44C6-A9E6-C39B5BFB1483} = {A9836F9E-6DB3-4D9F-ADCA-CF42D8C8BA93}
{C3BEF382-C7C4-454D-B017-1EAC03E9A82C} = {C40883CD-366D-4534-8B58-3EA0D13136DF}
+ {5ABD9968-F3A3-4967-B768-A6142F69759E} = {A9836F9E-6DB3-4D9F-ADCA-CF42D8C8BA93}
+ {9AAFB58C-B8C1-4D7F-80E6-7B95C94A829B} = {A9836F9E-6DB3-4D9F-ADCA-CF42D8C8BA93}
+ {A1A20049-04C2-4676-93CF-92449C4BBAA9} = {C40883CD-366D-4534-8B58-3EA0D13136DF}
+ {6C320AD9-F380-4F8B-85F9-0689F88766EC} = {C40883CD-366D-4534-8B58-3EA0D13136DF}
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {A855CFDC-9BEE-43A9-A3EA-4C4624A747DB}
EndGlobalSection
EndGlobal
diff --git a/RuntimePortable.sln b/RuntimePortable.sln
deleted file mode 100644
index 89fc0c66d..000000000
--- a/RuntimePortable.sln
+++ /dev/null
@@ -1,66 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2012
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A9836F9E-6DB3-4D9F-ADCA-CF42D8C8BA93}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{C40883CD-366D-4534-8B58-3EA0D13136DF}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.TestCommon", "test\Microsoft.TestCommon\Microsoft.TestCommon.csproj", "{FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http.Formatting.NetCore", "src\System.Net.Http.Formatting.NetCore\System.Net.Http.Formatting.NetCore.csproj", "{C7060639-719B-4BD2-8A37-2F146B5A0668}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http.Formatting.NetCore.Test", "test\System.Net.Http.Formatting.NetCore.Test\System.Net.Http.Formatting.NetCore.Test.csproj", "{8DA61DAC-FF7E-4CA1-93A0-6148DB66FD08}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http.Formatting.NetStandard", "src\System.Net.Http.Formatting.NetStandard\System.Net.Http.Formatting.NetStandard.csproj", "{636CA76A-C85C-42E2-B4AA-88046279B3CA}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http.Formatting.NetStandard.Test", "test\System.Net.Http.Formatting.NetStandard.Test\System.Net.Http.Formatting.NetStandard.Test.csproj", "{DECB05DF-B33A-44A0-B5DE-B14A8CE0740F}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- CodeAnalysis|Any CPU = CodeAnalysis|Any CPU
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}.CodeAnalysis|Any CPU.ActiveCfg = CodeAnalysis|Any CPU
- {FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}.CodeAnalysis|Any CPU.Build.0 = CodeAnalysis|Any CPU
- {FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0}.Release|Any CPU.Build.0 = Release|Any CPU
- {C7060639-719B-4BD2-8A37-2F146B5A0668}.CodeAnalysis|Any CPU.ActiveCfg = CodeAnalysis|Any CPU
- {C7060639-719B-4BD2-8A37-2F146B5A0668}.CodeAnalysis|Any CPU.Build.0 = CodeAnalysis|Any CPU
- {C7060639-719B-4BD2-8A37-2F146B5A0668}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {C7060639-719B-4BD2-8A37-2F146B5A0668}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {C7060639-719B-4BD2-8A37-2F146B5A0668}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {C7060639-719B-4BD2-8A37-2F146B5A0668}.Release|Any CPU.Build.0 = Release|Any CPU
- {8DA61DAC-FF7E-4CA1-93A0-6148DB66FD08}.CodeAnalysis|Any CPU.ActiveCfg = CodeAnalysis|Any CPU
- {8DA61DAC-FF7E-4CA1-93A0-6148DB66FD08}.CodeAnalysis|Any CPU.Build.0 = CodeAnalysis|Any CPU
- {8DA61DAC-FF7E-4CA1-93A0-6148DB66FD08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {8DA61DAC-FF7E-4CA1-93A0-6148DB66FD08}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {8DA61DAC-FF7E-4CA1-93A0-6148DB66FD08}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {8DA61DAC-FF7E-4CA1-93A0-6148DB66FD08}.Release|Any CPU.Build.0 = Release|Any CPU
- {636CA76A-C85C-42E2-B4AA-88046279B3CA}.CodeAnalysis|Any CPU.ActiveCfg = CodeAnalysis|Any CPU
- {636CA76A-C85C-42E2-B4AA-88046279B3CA}.CodeAnalysis|Any CPU.Build.0 = CodeAnalysis|Any CPU
- {636CA76A-C85C-42E2-B4AA-88046279B3CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {636CA76A-C85C-42E2-B4AA-88046279B3CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {636CA76A-C85C-42E2-B4AA-88046279B3CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {636CA76A-C85C-42E2-B4AA-88046279B3CA}.Release|Any CPU.Build.0 = Release|Any CPU
- {DECB05DF-B33A-44A0-B5DE-B14A8CE0740F}.CodeAnalysis|Any CPU.ActiveCfg = CodeAnalysis|Any CPU
- {DECB05DF-B33A-44A0-B5DE-B14A8CE0740F}.CodeAnalysis|Any CPU.Build.0 = CodeAnalysis|Any CPU
- {DECB05DF-B33A-44A0-B5DE-B14A8CE0740F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {DECB05DF-B33A-44A0-B5DE-B14A8CE0740F}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {DECB05DF-B33A-44A0-B5DE-B14A8CE0740F}.Release|Any CPU.ActiveCfg = Debug|Any CPU
- {DECB05DF-B33A-44A0-B5DE-B14A8CE0740F}.Release|Any CPU.Build.0 = Debug|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(NestedProjects) = preSolution
- {C7060639-719B-4BD2-8A37-2F146B5A0668} = {A9836F9E-6DB3-4D9F-ADCA-CF42D8C8BA93}
- {FCCC4CB7-BAF7-4A57-9F89-E5766FE536C0} = {C40883CD-366D-4534-8B58-3EA0D13136DF}
- {8DA61DAC-FF7E-4CA1-93A0-6148DB66FD08} = {C40883CD-366D-4534-8B58-3EA0D13136DF}
- {636CA76A-C85C-42E2-B4AA-88046279B3CA} = {A9836F9E-6DB3-4D9F-ADCA-CF42D8C8BA93}
- {DECB05DF-B33A-44A0-B5DE-B14A8CE0740F} = {C40883CD-366D-4534-8B58-3EA0D13136DF}
- EndGlobalSection
-EndGlobal
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 000000000..edbf5411a
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,9 @@
+# Security Policy
+
+## Reporting a Vulnerability
+
+Security issues and bugs should be reported privately to the Microsoft Security Response Center (MSRC), either by emailing secure@microsoft.com or via the portal at https://msrc.microsoft.com.
+You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your
+original message. Further information, including the MSRC PGP key, can be found in the [MSRC Report an Issue FAQ](https://www.microsoft.com/en-us/msrc/faqs-report-an-issue).
+
+Please do not open issues for anything you think might have a security implication.
\ No newline at end of file
diff --git a/Tools.sln b/Tools.sln
index 968050b6c..aae4eaa5a 100644
--- a/Tools.sln
+++ b/Tools.sln
@@ -1,8 +1,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25420.1
-MinimumVisualStudioVersion = 10.0.40219.1
+# Visual Studio 15
+VisualStudioVersion = 15.0.27016.1
+MinimumVisualStudioVersion = 15.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Web.FxCop", "tools\src\Microsoft.Web.FxCop\Microsoft.Web.FxCop.csproj", "{F439D4E6-3FAC-4C30-9585-6D258133A2BF}"
EndProject
Global
@@ -19,4 +19,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {F8728741-0321-4EF6-9359-7DF2DCE6E99E}
+ EndGlobalSection
EndGlobal
diff --git a/azure-pipelines-public.yml b/azure-pipelines-public.yml
new file mode 100644
index 000000000..7089d6acb
--- /dev/null
+++ b/azure-pipelines-public.yml
@@ -0,0 +1,33 @@
+parameters:
+ # Test only the Release build by default.
+- name: ReleaseBuildTarget
+ displayName: 'Build which target for Release?'
+ type: string
+ values: [ Build, Integration, UnitTest ]
+ default: UnitTest
+- name: OtherBuildTarget
+ displayName: 'Build which target for Debug/CodeAnalysis?'
+ type: string
+ values: [ Build, Integration, UnitTest ]
+ default: Build
+
+variables:
+- name: DOTNET_CLI_TELEMETRY_OPTOUT
+ value: 1
+- name: DOTNET_NOLOGO
+ value: 1
+ # Run CodeQL3000 tasks in a separate internal pipeline; not needed here.
+- name: Codeql.SkipTaskAutoInjection
+ value: true
+
+trigger: [main]
+pr: ['*']
+
+stages:
+- stage: build
+ displayName: Build
+ jobs:
+ - template: /eng/templates/default-build.yml
+ parameters:
+ ReleaseBuildTarget: ${{ parameters.ReleaseBuildTarget }}
+ OtherBuildTarget: ${{ parameters.OtherBuildTarget }}
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
new file mode 100644
index 000000000..6f110512d
--- /dev/null
+++ b/azure-pipelines.yml
@@ -0,0 +1,53 @@
+parameters:
+ # Test only the Release build by default.
+- name: ReleaseBuildTarget
+ displayName: 'Build which target for Release?'
+ type: string
+ values: [ Build, Integration, UnitTest ]
+ default: Build
+- name: OtherBuildTarget
+ displayName: 'Build which target for Debug/CodeAnalysis?'
+ type: string
+ values: [ Build, Integration, UnitTest ]
+ default: Build
+
+variables:
+- name: DOTNET_CLI_TELEMETRY_OPTOUT
+ value: 1
+- name: DOTNET_NOLOGO
+ value: 1
+ # Run CodeQL3000 tasks in a separate internal pipeline; not needed here.
+- name: Codeql.SkipTaskAutoInjection
+ value: true
+
+trigger: [main]
+pr: ['*']
+
+resources:
+ repositories:
+ # Repo: 1ESPipelineTemplates/1ESPipelineTemplates
+ - repository: 1esPipelines
+ type: git
+ name: 1ESPipelineTemplates/1ESPipelineTemplates
+ ref: refs/tags/release
+
+extends:
+ template: v1/1ES.Official.PipelineTemplate.yml@1esPipelines
+ parameters:
+ sdl:
+ policheck:
+ enabled: true
+ tsa:
+ enabled: true
+ pool:
+ name: NetCore1ESPool-Svc-Internal
+ image: 1es-windows-2019
+ os: windows
+ stages:
+ - stage: build
+ displayName: Build
+ jobs:
+ - template: /eng/templates/default-build.yml@self
+ parameters:
+ ReleaseBuildTarget: ${{ parameters.ReleaseBuildTarget }}
+ OtherBuildTarget: ${{ parameters.OtherBuildTarget }}
diff --git a/build.cmd b/build.cmd
index 4afef96e7..5802269fe 100644
--- a/build.cmd
+++ b/build.cmd
@@ -1,41 +1,104 @@
@echo off
-pushd %~dp0
setlocal
-if exist bin goto build
+if exist bin goto Build
mkdir bin
:Build
-REM Find the most recent 32bit MSBuild.exe on the system. Require v12.0 (installed with VS2013) or later since .NET 4.0
-REM is not supported. Also handle x86 operating systems, where %ProgramFiles(x86)% is not defined. Always quote the
-REM %MSBuild% value when setting the variable and never quote %MSBuild% references.
-set MSBuild="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
-if not exist %MSBuild% @set MSBuild="%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe"
-if not exist %MSBuild% @set MSBuild="%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe"
-if not exist %MSBuild% @set MSBuild="%ProgramFiles%\MSBuild\12.0\Bin\MSBuild.exe"
+REM Require VS2019 (v16.0) on the system. Use `vswhere` for the search because it can find all VS installations.
+set vswhere="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
+if not exist %vswhere% (
+ set vswhere="%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe"
+)
+if not exist %vswhere% (
+ REM vswhere.exe not in normal locations; check the Path.
+ for %%X in (vswhere.exe) do (
+ set vswhere="%%~$PATH:X"
+ )
+)
+if not exist %vswhere% (
+ echo Could not find vswhere.exe. Please run this from a Visual Studio developer prompt.
+ goto BuildFail
+)
+
+set InstallDir=
+for /f "usebackq tokens=*" %%i in (`%vswhere% -version 16 -latest -prerelease -products * ^
+ -requires Microsoft.Net.Component.4.5.TargetingPack ^
+ -requires Microsoft.Net.Component.4.5.2.TargetingPack ^
+ -requires Microsoft.Net.Component.4.6.2.TargetingPack ^
+ -property installationPath`) do (
+ set "InstallDir=%%i"
+)
+
+if not DEFINED InstallDir (
+ echo "Could not find a VS2019 installation with the necessary components (targeting packs for v4.5, v4.5.2, and v4.6.2)."
+ echo Please install VS2019 or the missing components.
+ goto BuildFail
+)
+
+REM Find a 64bit MSBuild and add it to path. Require v17.4 or later due to our .NET SDK choice.
+REM Check for VS2022 first.
+set InstallDir=
+for /f "usebackq tokens=*" %%i in (`%vswhere% -version 17.4 -latest -prerelease -products * ^
+ -requires Microsoft.Component.MSBuild ^
+ -property installationPath`) do (
+ set "InstallDir=%%i"
+)
+
+if DEFINED InstallDir (
+ REM Add MSBuild to the path.
+ set "PATH=%InstallDir%\MSBuild\Current\Bin;%PATH%"
+ goto FoundMSBuild
+)
+
+REM Otherwise find or install an xcopy-able MSBuild.
+echo "Could not find a VS2022 installation with the necessary components (MSBuild). Falling back..."
+
+set "MSBuildVersion=17.4.1"
+set "Command=[System.Threading.Thread]::CurrentThread.CurrentCulture = ''"
+set "Command=%Command%; [System.Threading.Thread]::CurrentThread.CurrentUICulture = ''"
+set "Command=%Command%; try { & '%~dp0eng\GetXCopyMSBuild.ps1' %MSBuildVersion%; exit $LASTEXITCODE }"
+set "Command=%Command% catch { write-host $_; exit 1 }"
+PowerShell -NoProfile -NoLogo -ExecutionPolicy Bypass -Command "%Command%"
+if %ERRORLEVEL% neq 0 goto BuildFail
+REM Add MSBuild to the path.
+set "PATH=%~dp0.msbuild\%MSBuildVersion%\tools\MSBuild\Current\Bin;%PATH%"
+
+:FoundMSBuild
+REM Configure NuGet operations to work w/in this repo i.e. do not pollute system packages folder.
+REM Note this causes two copies of packages restored using packages.config to land in this folder e.g.
+REM StyleCpy.5.0.0/ and stylecop/5.0.0/.
+set "NUGET_PACKAGES=%~dp0packages"
+
+REM Are we running in a local dev environment (not on CI)?
+if DEFINED CI (set Desktop=false) else if DEFINED TEAMCITY_VERSION (set Desktop=false) else (set Desktop=true)
+
+pushd %~dp0
if "%1" == "" goto BuildDefaults
-%MSBuild% Runtime.msbuild /m /nr:false /t:%* /p:Platform="Any CPU" /p:Desktop=true /v:M /fl /flp:LogFile=bin\msbuild.log;Verbosity=Normal
+MSBuild "%~dp0Runtime.msbuild" /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^
+ /fl /fileLoggerParameters:LogFile=bin\msbuild.log;Verbosity=Normal /consoleLoggerParameters:Summary /t:%*
if %ERRORLEVEL% neq 0 goto BuildFail
goto BuildSuccess
:BuildDefaults
-%MSBuild% Runtime.msbuild /m /nr:false /p:Platform="Any CPU" /p:Desktop=true /v:M /fl /flp:LogFile=bin\msbuild.log;Verbosity=detailed
+MSBuild "%~dp0Runtime.msbuild" /m /nr:false /p:Platform="Any CPU" /p:Desktop=%Desktop% /v:M ^
+ /fl /fileLoggerParameters:LogFile=bin\msbuild.log;Verbosity=Normal /consoleLoggerParameters:Summary
if %ERRORLEVEL% neq 0 goto BuildFail
goto BuildSuccess
:BuildFail
echo.
echo *** BUILD FAILED ***
-goto End
+popd
+endlocal
+exit /B 999
:BuildSuccess
echo.
echo **** BUILD SUCCESSFUL ***
-goto end
-
-:End
popd
endlocal
+exit /B 0
diff --git a/eng/GetXCopyMSBuild.ps1 b/eng/GetXCopyMSBuild.ps1
new file mode 100644
index 000000000..667839289
--- /dev/null
+++ b/eng/GetXCopyMSBuild.ps1
@@ -0,0 +1,43 @@
+# Lifted from https://github.com/dotnet/arcade/blob/main/eng/common/tools.ps1
+
+[CmdletBinding(DefaultParameterSetName='Groups')]
+param(
+ [string]$Version = '17.4.1'
+)
+
+Set-StrictMode -Version 2
+$ErrorActionPreference = 'Stop'
+
+function Create-Directory ([string[]] $path) {
+ New-Item -Path $path -Force -ItemType 'Directory' | Out-Null
+}
+
+function Unzip([string]$zipfile, [string]$outpath) {
+ Add-Type -AssemblyName System.IO.Compression.FileSystem
+ [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
+}
+
+function InitializeXCopyMSBuild([string]$packageVersion, [bool]$install, [string]$ToolsDir) {
+ $packageName = 'RoslynTools.MSBuild'
+ $packageDir = Join-Path $ToolsDir $packageVersion
+ $packagePath = Join-Path $packageDir "$packageName.$packageVersion.nupkg"
+
+ if (!(Test-Path $packageDir)) {
+ if (!$install) {
+ return $null
+ }
+
+ Create-Directory $packageDir
+
+ Write-Host "Downloading $packageName $packageVersion"
+ $ProgressPreference = 'SilentlyContinue' # Don't display the console progress UI - it's a huge perf hit
+ Invoke-WebRequest "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/flat2/$packageName/$packageVersion/$packageName.$packageVersion.nupkg" -OutFile $packagePath
+
+ Unzip $packagePath $packageDir
+ }
+
+ return Join-Path $packageDir 'tools'
+}
+
+$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot '..\')
+InitializeXCopyMSBuild -packageVersion $Version -install $true -ToolsDir (join-path $RepoRoot .msbuild)
diff --git a/eng/templates/default-build.yml b/eng/templates/default-build.yml
new file mode 100644
index 000000000..7000a4dad
--- /dev/null
+++ b/eng/templates/default-build.yml
@@ -0,0 +1,95 @@
+parameters:
+ ReleaseBuildTarget: ''
+ OtherBuildTarget: ''
+
+jobs:
+- job: build
+ displayName: Build
+ ${{ if eq(variables['System.TeamProject'], 'public') }}:
+ pool:
+ name: NetCore-Svc-Public
+ demands: ImageOverride -equals windows.vs2019.amd64.open
+ timeoutInMinutes: 30
+
+ strategy:
+ matrix:
+ Release:
+ _BuildTarget: ${{ parameters.ReleaseBuildTarget }}
+ _Configuration: Release
+ _StyleCopEnabled: true
+ # Do CG work only in internal pipelines.
+ skipComponentGovernanceDetection: ${{ eq(variables['System.TeamProject'], 'public') }}
+ Debug:
+ _BuildTarget: ${{ parameters.OtherBuildTarget }}
+ _Configuration: Debug
+ _StyleCopEnabled: false
+ # Do not redo CG work. Configuration changes in this part of the matrix are not relevant to CG.
+ skipComponentGovernanceDetection: true
+ CodeAnalysis:
+ _BuildTarget: ${{ parameters.OtherBuildTarget }}
+ _Configuration: CodeAnalysis
+ _StyleCopEnabled: false
+ # Do not redo CG work. Configuration changes in this part of the matrix are not relevant to CG.
+ skipComponentGovernanceDetection: true
+
+ steps:
+ - checkout: self
+ clean: true
+ displayName: Checkout
+
+ - task: UseDotNet@2
+ displayName: Get .NET SDK
+ inputs:
+ useGlobalJson: true
+ - task: UseDotNet@2
+ displayName: Get .NET 2.1 runtime
+ inputs:
+ packageType: runtime
+ version: '2.1.x'
+
+ - script: .\build.cmd EnableSkipStrongNames
+ displayName: Enable SkipStrongNames
+ - script: .\build.cmd $(_BuildTarget) ^
+ /binaryLogger:artifacts/msbuild.binlog /p:Configuration=$(_Configuration) /p:StyleCopEnabled=$(_StyleCopEnabled) ^
+ /fileLoggerParameters:LogFile=artifacts/msbuild.log;Summary;Verbosity=minimal
+ displayName: Build
+
+ - ${{ if eq(variables['System.TeamProject'], 'public') }}:
+ - task: PublishBuildArtifacts@1
+ displayName: Upload test results
+ condition: and(always(), ne(variables._BuildTarget, 'Build'))
+ continueOnError: true
+ inputs:
+ pathtoPublish: ./bin/$(_Configuration)/Test/TestResults/
+ artifactName: $(_Configuration) Test Results $(System.JobId)
+ artifactType: Container
+ parallel: true
+ - task: PublishTestResults@2
+ condition: and(always(), ne(variables._BuildTarget, 'Build'))
+ continueOnError: true
+ displayName: Publish test results
+ inputs:
+ mergeTestResults: true
+ searchFolder: ./bin/$(_Configuration)/Test/TestResults/
+ testResultsFiles: '*.xml'
+ testRunner: xUnit
+ testRunTitle: $(_Configuration)
+ - task: PublishBuildArtifacts@1
+ displayName: Upload logs
+ condition: always()
+ continueOnError: true
+ inputs:
+ pathtoPublish: ./artifacts/
+ artifactName: $(_Configuration) Logs $(System.JobId)
+ artifactType: Container
+ parallel: true
+ - ${{ if eq(variables['System.TeamProject'], 'internal') }}:
+ - task: 1ES.PublishPipelineArtifact@1
+ inputs:
+ condition: and(always(), ne(variables._BuildTarget, 'Build'))
+ path: ./bin/$(_Configuration)/Test/TestResults/
+ artifact: $(_Configuration) Test Results $(System.JobId)
+ - task: 1ES.PublishPipelineArtifact@1
+ inputs:
+ path: ./artifacts/
+ artifact: $(_Configuration) Logs $(System.JobId)
diff --git a/es-metadata.yml b/es-metadata.yml
new file mode 100644
index 000000000..9061e1181
--- /dev/null
+++ b/es-metadata.yml
@@ -0,0 +1,8 @@
+schemaVersion: 0.0.1
+isProduction: true
+accountableOwners:
+ service: 4db45fa9-fb0f-43ce-b523-ad1da773dfbc
+routing:
+ defaultAreaPath:
+ org: devdiv
+ path: DevDiv\ASP.NET Core
diff --git a/global.json b/global.json
index f992be3d4..0f75e8a6f 100644
--- a/global.json
+++ b/global.json
@@ -1,5 +1,6 @@
{
"sdk": {
- "version": "1.0.4"
+ "version": "6.0.405",
+ "rollForward": "major"
}
-}
\ No newline at end of file
+}
diff --git a/packages/repositories.config b/packages/repositories.config
index 8bede8eeb..18d08a3de 100644
--- a/packages/repositories.config
+++ b/packages/repositories.config
@@ -3,7 +3,6 @@
-
@@ -17,11 +16,9 @@
-
-
diff --git a/src/CodeAnalysisDictionary.xml b/src/CodeAnalysisDictionary.xml
index fdd4e0ea7..26ab4a8af 100644
--- a/src/CodeAnalysisDictionary.xml
+++ b/src/CodeAnalysisDictionary.xml
@@ -55,6 +55,13 @@
ModelNameBSONUntyped
+ Behavior
+ Callback
+ Canceled
+ Color
+ Fallback
+ Markup
+ PreflightWebPage
diff --git a/src/Common/CollectionExtensions.cs b/src/Common/CollectionExtensions.cs
index c89d4ad98..bfd1eb61d 100644
--- a/src/Common/CollectionExtensions.cs
+++ b/src/Common/CollectionExtensions.cs
@@ -27,7 +27,7 @@ public static T[] AppendAndReallocate(this T[] array, T value)
}
///
- /// Return the enumerable as an Array, copying if required. Optimized for common case where it is an Array.
+ /// Return the enumerable as an Array, copying if required. Optimized for common case where it is an Array.
/// Avoid mutating the return value.
///
public static T[] AsArray(this IEnumerable values)
@@ -43,7 +43,7 @@ public static T[] AsArray(this IEnumerable values)
}
///
- /// Return the enumerable as a Collection of T, copying if required. Optimized for the common case where it is
+ /// Return the enumerable as a Collection of T, copying if required. Optimized for the common case where it is
/// a Collection of T and avoiding a copy if it implements IList of T. Avoid mutating the return value.
///
public static Collection AsCollection(this IEnumerable enumerable)
@@ -78,9 +78,9 @@ public static IList AsIList(this IEnumerable enumerable)
}
return new List(enumerable);
}
-
+
///
- /// Return the enumerable as a List of T, copying if required. Optimized for common case where it is an List of T
+ /// Return the enumerable as a List of T, copying if required. Optimized for common case where it is an List of T
/// or a ListWrapperCollection of T. Avoid mutating the return value.
///
public static List AsList(this IEnumerable enumerable)
diff --git a/src/Common/CommonWebApiResources.Designer.cs b/src/Common/CommonWebApiResources.Designer.cs
index 4ceb3f115..6e1e476d6 100644
--- a/src/Common/CommonWebApiResources.Designer.cs
+++ b/src/Common/CommonWebApiResources.Designer.cs
@@ -24,15 +24,15 @@ namespace System.Web.Http.Properties {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class CommonWebApiResources {
-
+
private static global::System.Resources.ResourceManager resourceMan;
-
+
private static global::System.Globalization.CultureInfo resourceCulture;
-
+
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal CommonWebApiResources() {
}
-
+
///
/// Returns the cached ResourceManager instance used by this class.
///
@@ -40,7 +40,7 @@ internal CommonWebApiResources() {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
-#if NETFX_CORE
+#if NETSTANDARD1_3
var assembly = typeof(CommonWebApiResources).GetTypeInfo().Assembly;
#else
var assembly = typeof(CommonWebApiResources).Assembly;
@@ -59,7 +59,7 @@ internal CommonWebApiResources() {
return resourceMan;
}
}
-
+
///
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
@@ -73,7 +73,7 @@ internal CommonWebApiResources() {
resourceCulture = value;
}
}
-
+
///
/// Looks up a localized string similar to Relative URI values are not supported: '{0}'. The URI must be absolute..
///
@@ -82,7 +82,7 @@ internal static string ArgumentInvalidAbsoluteUri {
return ResourceManager.GetString("ArgumentInvalidAbsoluteUri", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Unsupported URI scheme: '{0}'. The URI scheme must be either '{1}' or '{2}'..
///
@@ -91,7 +91,7 @@ internal static string ArgumentInvalidHttpUriScheme {
return ResourceManager.GetString("ArgumentInvalidHttpUriScheme", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Value must be greater than or equal to {0}..
///
@@ -100,7 +100,7 @@ internal static string ArgumentMustBeGreaterThanOrEqualTo {
return ResourceManager.GetString("ArgumentMustBeGreaterThanOrEqualTo", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Value must be less than or equal to {0}..
///
@@ -109,7 +109,7 @@ internal static string ArgumentMustBeLessThanOrEqualTo {
return ResourceManager.GetString("ArgumentMustBeLessThanOrEqualTo", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The argument '{0}' is null or empty..
///
@@ -118,7 +118,7 @@ internal static string ArgumentNullOrEmpty {
return ResourceManager.GetString("ArgumentNullOrEmpty", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to URI must not contain a query component or a fragment identifier..
///
@@ -127,7 +127,7 @@ internal static string ArgumentUriHasQueryOrFragment {
return ResourceManager.GetString("ArgumentUriHasQueryOrFragment", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The value of argument '{0}' ({1}) is invalid for Enum type '{2}'..
///
diff --git a/src/Common/Error.cs b/src/Common/Error.cs
index 0e8c83465..85449c142 100644
--- a/src/Common/Error.cs
+++ b/src/Common/Error.cs
@@ -74,7 +74,7 @@ internal static ArgumentException ArgumentUriNotAbsolute(string parameterName, U
}
///
- /// Creates an with a message saying that the argument must be an absolute URI
+ /// Creates an with a message saying that the argument must be an absolute URI
/// without a query or fragment identifier and then logs it with .
///
/// The name of the parameter that caused the current exception.
@@ -225,11 +225,7 @@ internal static OperationCanceledException OperationCanceled(string messageForma
/// The logged .
internal static ArgumentException InvalidEnumArgument(string parameterName, int invalidValue, Type enumClass)
{
-#if NETFX_CORE
- return new ArgumentException(Error.Format(CommonWebApiResources.InvalidEnumArgument, parameterName, invalidValue, enumClass.Name), parameterName);
-#else
return new InvalidEnumArgumentException(parameterName, invalidValue, enumClass);
-#endif
}
///
@@ -265,5 +261,24 @@ internal static NotSupportedException NotSupported(string messageFormat, params
{
return new NotSupportedException(Error.Format(messageFormat, messageArgs));
}
+
+#if NETSTANDARD1_3 // InvalidEnumArgumentException not available in netstandard1.3.
+ internal class InvalidEnumArgumentException : ArgumentException
+ {
+ public InvalidEnumArgumentException() : this(null)
+ { }
+
+ public InvalidEnumArgumentException(string message) : base(message)
+ { }
+
+ public InvalidEnumArgumentException(string message, Exception innerException) : base(message, innerException)
+ { }
+
+ public InvalidEnumArgumentException(string argumentName, int invalidValue, Type enumClass) : base(
+ Error.Format(CommonWebApiResources.InvalidEnumArgument, argumentName, invalidValue, enumClass.Name),
+ argumentName)
+ { }
+ }
+#endif
}
}
diff --git a/src/Common/UriQueryUtility.cs b/src/Common/UriQueryUtility.cs
deleted file mode 100644
index 53675e11a..000000000
--- a/src/Common/UriQueryUtility.cs
+++ /dev/null
@@ -1,278 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.Diagnostics.Contracts;
-using System.Net;
-using System.Text;
-
-namespace System.Web.Http
-{
- ///
- /// Helpers for encoding, decoding, and parsing URI query components. In .Net 4.5
- /// please use the WebUtility class.
- ///
- internal static class UriQueryUtility
- {
- public static string UrlEncode(string str)
- {
- if (str == null)
- {
- return null;
- }
-
-#if NETFX_CORE
- return WebUtility.UrlEncode(str);
-#else
- byte[] bytes = Encoding.UTF8.GetBytes(str);
- return Encoding.ASCII.GetString(UrlEncode(bytes, 0, bytes.Length, alwaysCreateNewReturnValue: false));
-#endif
- }
-
- public static string UrlDecode(string str)
- {
- if (str == null)
- {
- return null;
- }
-
-#if NETFX_CORE
- return WebUtility.UrlDecode(str);
-#else
- return UrlDecodeInternal(str, Encoding.UTF8);
-#endif
- }
-
-#if !NETFX_CORE
- private static byte[] UrlEncode(byte[] bytes, int offset, int count, bool alwaysCreateNewReturnValue)
- {
- byte[] encoded = UrlEncode(bytes, offset, count);
-
- return (alwaysCreateNewReturnValue && (encoded != null) && (encoded == bytes))
- ? (byte[])encoded.Clone()
- : encoded;
- }
-
- private static byte[] UrlEncode(byte[] bytes, int offset, int count)
- {
- if (!ValidateUrlEncodingParameters(bytes, offset, count))
- {
- return null;
- }
-
- int cSpaces = 0;
- int cUnsafe = 0;
-
- // count them first
- for (int i = 0; i < count; i++)
- {
- char ch = (char)bytes[offset + i];
-
- if (ch == ' ')
- cSpaces++;
- else if (!IsUrlSafeChar(ch))
- cUnsafe++;
- }
-
- // nothing to expand?
- if (cSpaces == 0 && cUnsafe == 0)
- return bytes;
-
- // expand not 'safe' characters into %XX, spaces to +s
- byte[] expandedBytes = new byte[count + cUnsafe * 2];
- int pos = 0;
-
- for (int i = 0; i < count; i++)
- {
- byte b = bytes[offset + i];
- char ch = (char)b;
-
- if (IsUrlSafeChar(ch))
- {
- expandedBytes[pos++] = b;
- }
- else if (ch == ' ')
- {
- expandedBytes[pos++] = (byte)'+';
- }
- else
- {
- expandedBytes[pos++] = (byte)'%';
- expandedBytes[pos++] = (byte)IntToHex((b >> 4) & 0xf);
- expandedBytes[pos++] = (byte)IntToHex(b & 0x0f);
- }
- }
-
- return expandedBytes;
- }
-
- private static string UrlDecodeInternal(string value, Encoding encoding)
- {
- if (value == null)
- {
- return null;
- }
-
- int count = value.Length;
- UrlDecoder helper = new UrlDecoder(count, encoding);
-
- // go through the string's chars collapsing %XX and %uXXXX and
- // appending each char as char, with exception of %XX constructs
- // that are appended as bytes
-
- for (int pos = 0; pos < count; pos++)
- {
- char ch = value[pos];
-
- if (ch == '+')
- {
- ch = ' ';
- }
- else if (ch == '%' && pos < count - 2)
- {
- int h1 = HexToInt(value[pos + 1]);
- int h2 = HexToInt(value[pos + 2]);
-
- if (h1 >= 0 && h2 >= 0)
- {
- // valid 2 hex chars
- byte b = (byte)((h1 << 4) | h2);
- pos += 2;
-
- // don't add as char
- helper.AddByte(b);
- continue;
- }
- }
-
- if ((ch & 0xFF80) == 0)
- helper.AddByte((byte)ch); // 7 bit have to go as bytes because of Unicode
- else
- helper.AddChar(ch);
- }
-
- return helper.GetString();
- }
-
- private static int HexToInt(char h)
- {
- return (h >= '0' && h <= '9') ? h - '0' :
- (h >= 'a' && h <= 'f') ? h - 'a' + 10 :
- (h >= 'A' && h <= 'F') ? h - 'A' + 10 :
- -1;
- }
-
- private static char IntToHex(int n)
- {
- Contract.Assert(n < 0x10);
-
- if (n <= 9)
- return (char)(n + (int)'0');
- else
- return (char)(n - 10 + (int)'a');
- }
-
- // Set of safe chars, from RFC 1738.4 minus '+'
- private static bool IsUrlSafeChar(char ch)
- {
- if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9')
- return true;
-
- switch (ch)
- {
- case '-':
- case '_':
- case '.':
- case '!':
- case '*':
- case '(':
- case ')':
- return true;
- }
-
- return false;
- }
-
- private static bool ValidateUrlEncodingParameters(byte[] bytes, int offset, int count)
- {
- if (bytes == null && count == 0)
- return false;
- if (bytes == null)
- {
- throw Error.ArgumentNull("bytes");
- }
- if (offset < 0 || offset > bytes.Length)
- {
- throw new ArgumentOutOfRangeException("offset");
- }
- if (count < 0 || offset + count > bytes.Length)
- {
- throw new ArgumentOutOfRangeException("count");
- }
-
- return true;
- }
-
- // Internal class to facilitate URL decoding -- keeps char buffer and byte buffer, allows appending of either chars or bytes
- private class UrlDecoder
- {
- private int _bufferSize;
-
- // Accumulate characters in a special array
- private int _numChars;
- private char[] _charBuffer;
-
- // Accumulate bytes for decoding into characters in a special array
- private int _numBytes;
- private byte[] _byteBuffer;
-
- // Encoding to convert chars to bytes
- private Encoding _encoding;
-
- private void FlushBytes()
- {
- if (_numBytes > 0)
- {
- _numChars += _encoding.GetChars(_byteBuffer, 0, _numBytes, _charBuffer, _numChars);
- _numBytes = 0;
- }
- }
-
- internal UrlDecoder(int bufferSize, Encoding encoding)
- {
- _bufferSize = bufferSize;
- _encoding = encoding;
-
- _charBuffer = new char[bufferSize];
- // byte buffer created on demand
- }
-
- internal void AddChar(char ch)
- {
- if (_numBytes > 0)
- FlushBytes();
-
- _charBuffer[_numChars++] = ch;
- }
-
- internal void AddByte(byte b)
- {
- if (_byteBuffer == null)
- _byteBuffer = new byte[_bufferSize];
-
- _byteBuffer[_numBytes++] = b;
- }
-
- internal String GetString()
- {
- if (_numBytes > 0)
- FlushBytes();
-
- if (_numChars > 0)
- return new String(_charBuffer, 0, _numChars);
- else
- return String.Empty;
- }
- }
-#endif
- }
-}
\ No newline at end of file
diff --git a/src/CommonAssemblyInfo.cs b/src/CommonAssemblyInfo.cs
index 62d86c357..de4e5d379 100644
--- a/src/CommonAssemblyInfo.cs
+++ b/src/CommonAssemblyInfo.cs
@@ -19,17 +19,22 @@
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: AssemblyMetadata("Serviceable", "True")]
-// ===========================================================================
-// DO NOT EDIT OR REMOVE ANYTHING BELOW THIS COMMENT.
-// Version numbers are automatically generated based on regular expressions.
-// ===========================================================================
+// ===================================================================================
+// TAKE CARE WHEN EDITING OR REMOVING ANYTHING BELOW THIS COMMENT.
+// BUILD_GENERATED_VERSION will be set in any CI build. Versions below are not used.
+// ===================================================================================
-#if ASPNETMVC && ASPNETWEBPAGES
-#error Runtime projects cannot define both ASPNETMVC and ASPNETWEBPAGES
+#if (ASPNETMVC && (ASPNETWEBPAGES || ASPNETFACEBOOK || ASPNETHTTPFORMATTING)) || (ASPNETWEBPAGES && (ASPNETFACEBOOK || ASPNETHTTPFORMATTING)) || (ASPNETFACEBOOK && ASPNETHTTPFORMATTING)
+#error Runtime projects cannot define more than one of ASPNETMVC, ASPNETWEBPAGES, ASPNETFACEBOOK, or ASPNETHTTPFORMATTING
+#elif ASPNETHTTPFORMATTING
+#if !BUILD_GENERATED_VERSION
+[assembly: AssemblyVersion("6.0.0.0")] // ASPNETHTTPFORMATTING
+[assembly: AssemblyFileVersion("6.0.0.0")] // ASPNETHTTPFORMATTING
+#endif
#elif ASPNETMVC
#if !BUILD_GENERATED_VERSION
-[assembly: AssemblyVersion("5.2.4.0")] // ASPNETMVC
-[assembly: AssemblyFileVersion("5.2.4.0")] // ASPNETMVC
+[assembly: AssemblyVersion("5.3.0.0")] // ASPNETMVC
+[assembly: AssemblyFileVersion("5.3.0.0")] // ASPNETMVC
#endif
[assembly: AssemblyProduct("Microsoft ASP.NET MVC")]
#elif ASPNETWEBPAGES
@@ -45,5 +50,5 @@
#endif
[assembly: AssemblyProduct("Microsoft ASP.NET Facebook")]
#else
-#error Runtime projects must define either ASPNETMVC or ASPNETWEBPAGES
+#error Runtime projects must define ASPNETMVC, ASPNETWEBPAGES or ASPNETFACEBOOK
#endif
diff --git a/src/CommonAssemblyInfo.vb b/src/CommonAssemblyInfo.vb
index 613b66814..d5dac6315 100644
--- a/src/CommonAssemblyInfo.vb
+++ b/src/CommonAssemblyInfo.vb
@@ -20,6 +20,6 @@ Imports System.Runtime.InteropServices
' Version numbers are automatically generated based on regular expressions.
' ===========================================================================
- 'ASPNETMVC
- 'ASPNETMVC
+ 'ASPNETMVC
+ 'ASPNETMVC
\ No newline at end of file
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
new file mode 100644
index 000000000..6785fd164
--- /dev/null
+++ b/src/Directory.Build.props
@@ -0,0 +1,9 @@
+
+
+
+
+ true
+ false
+ v4.5
+
+
diff --git a/src/Microsoft.AspNet.Facebook/Microsoft.AspNet.Facebook.csproj b/src/Microsoft.AspNet.Facebook/Microsoft.AspNet.Facebook.csproj
index a25890bc8..12642c354 100644
--- a/src/Microsoft.AspNet.Facebook/Microsoft.AspNet.Facebook.csproj
+++ b/src/Microsoft.AspNet.Facebook/Microsoft.AspNet.Facebook.csproj
@@ -26,9 +26,10 @@
False..\..\packages\Facebook.6.4.2\lib\net45\Facebook.dll
-
+
+ ..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dllFalse
- ..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll
+ False
diff --git a/src/Microsoft.AspNet.Facebook/packages.config b/src/Microsoft.AspNet.Facebook/packages.config
index 613e222f9..102ce84aa 100644
--- a/src/Microsoft.AspNet.Facebook/packages.config
+++ b/src/Microsoft.AspNet.Facebook/packages.config
@@ -2,5 +2,5 @@
-
+
\ No newline at end of file
diff --git a/src/Strict.ruleset b/src/Strict.ruleset
index 5a2a69ba9..a0c61fcb5 100644
--- a/src/Strict.ruleset
+++ b/src/Strict.ruleset
@@ -6,5 +6,7 @@
+
+
\ No newline at end of file
diff --git a/src/System.Net.Http.Formatting.NetCore/GlobalSuppressions.cs b/src/System.Net.Http.Formatting.NetCore/GlobalSuppressions.cs
deleted file mode 100644
index 778d614cd..000000000
--- a/src/System.Net.Http.Formatting.NetCore/GlobalSuppressions.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.Diagnostics.CodeAnalysis;
-
-[assembly: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")]
-[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Net.Http.Headers", Justification = "We follow the layout of System.Net.Http.")]
-[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Net.Http.Handlers", Justification = "Handlers provide an extensibility hook which we want to keep in a separate namespace.")]
-[assembly: SuppressMessage("Microsoft.Design", "CA1014:MarkAssembliesWithClsCompliant", Scope = "module", Target = "system.net.http.formatting.dll", Justification = "CLSCompliant is not applicable to the portable version of the assembly.")]
-[assembly: SuppressMessage("Microsoft.Web.FxCop", "MW1000:UnusedResourceUsageRule", Scope = "module", Target = "system.net.http.formatting.dll", Justification = "The resources are only used in the non-portable version of the assembly.")]
diff --git a/src/System.Net.Http.Formatting.NetCore/Internal/ConcurrentDictionary.cs b/src/System.Net.Http.Formatting.NetCore/Internal/ConcurrentDictionary.cs
deleted file mode 100644
index 3df580802..000000000
--- a/src/System.Net.Http.Formatting.NetCore/Internal/ConcurrentDictionary.cs
+++ /dev/null
@@ -1,192 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-#if NETFX_CORE // This file should only be included by the NetCore version of the formatting project, but adding a guard here just in case.
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.Net.Http.Internal
-{
- // TODO: Remove this class after BCL makes their portable library version.
- internal sealed class ConcurrentDictionary : IDictionary
- {
- private Dictionary _dictionary = new Dictionary();
- private object _lock = new object();
-
- public ICollection Keys
- {
- get
- {
- throw new NotImplementedException();
- }
- }
-
- public ICollection Values
- {
- get
- {
- throw new NotImplementedException();
- }
- }
-
- public int Count
- {
- get
- {
- throw new NotImplementedException();
- }
- }
-
- public bool IsReadOnly
- {
- get
- {
- return ((IDictionary)_dictionary).IsReadOnly;
- }
- }
-
- public TValue this[TKey key]
- {
- get
- {
- throw new NotImplementedException();
- }
- set
- {
- throw new NotImplementedException();
- }
- }
-
- public void Add(TKey key, TValue value)
- {
- throw new NotImplementedException();
- }
-
- public bool ContainsKey(TKey key)
- {
- lock (_lock)
- {
- return _dictionary.ContainsKey(key);
- }
- }
-
- public bool Remove(TKey key)
- {
- throw new NotImplementedException();
- }
-
- public bool TryGetValue(TKey key, out TValue value)
- {
- lock (_lock)
- {
- return _dictionary.TryGetValue(key, out value);
- }
- }
-
- public void Add(KeyValuePair item)
- {
- throw new NotImplementedException();
- }
-
- public void Clear()
- {
- throw new NotImplementedException();
- }
-
- public bool Contains(KeyValuePair item)
- {
- throw new NotImplementedException();
- }
-
- public void CopyTo(KeyValuePair[] array, int arrayIndex)
- {
- throw new NotImplementedException();
- }
-
- public bool Remove(KeyValuePair item)
- {
- throw new NotImplementedException();
- }
-
- public IEnumerator> GetEnumerator()
- {
- throw new NotImplementedException();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- throw new NotImplementedException();
- }
-
- // ConcurrentDictionary members
- public bool TryRemove(TKey key, out TValue removedValue)
- {
- lock (_lock)
- {
- if (_dictionary.TryGetValue(key, out removedValue))
- {
- return _dictionary.Remove(key);
- }
-
- return false;
- }
- }
-
- public TValue GetOrAdd(TKey key, Func addValueFactory)
- {
- lock (_lock)
- {
- TValue value;
-
- if (!_dictionary.TryGetValue(key, out value))
- {
- value = addValueFactory.Invoke(key);
- _dictionary.Add(key, value);
- }
-
- return value;
- }
- }
-
- public bool TryAdd(TKey key, TValue value)
- {
- lock (_lock)
- {
- if (_dictionary.ContainsKey(key))
- {
- return false;
- }
-
- _dictionary.Add(key, value);
- return true;
- }
- }
-
- public TValue AddOrUpdate(TKey key, TValue addValue, Func updateValueFactory)
- {
- lock (_lock)
- {
- TValue value;
-
- // update
- if (_dictionary.TryGetValue(key, out value))
- {
- value = updateValueFactory.Invoke(key, value);
- _dictionary[key] = value;
- return value;
- }
-
- // add
- _dictionary.Add(key, addValue);
- return addValue;
- }
- }
- }
-}
-#endif
\ No newline at end of file
diff --git a/src/System.Net.Http.Formatting.NetCore/System.Net.Http.Formatting.NetCore.csproj b/src/System.Net.Http.Formatting.NetCore/System.Net.Http.Formatting.NetCore.csproj
deleted file mode 100644
index c3d0a0827..000000000
--- a/src/System.Net.Http.Formatting.NetCore/System.Net.Http.Formatting.NetCore.csproj
+++ /dev/null
@@ -1,274 +0,0 @@
-
-
-
-
- {C7060639-719B-4BD2-8A37-2F146B5A0668}
- Library
- Properties
- System.Net.Http
- System.Net.Http.Formatting
- $(OutputPath)NetCore\
- $(OutputPath)$(AssemblyName).xml
- $(CodeAnalysis)
- ..\Strict.ruleset
- /assemblycomparemode:StrongNameIgnoringVersion
- false
- $(DefineConstants);NETFX_CORE;ASPNETMVC;NOT_CLS_COMPLIANT
- Profile259
- {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- 11.0
- 1591
- v4.5
-
-
-
- Properties\CommonAssemblyInfo.cs
-
-
- Common\Error.cs
-
-
- Common\TaskHelpers.cs
-
-
- Common\TaskHelpersExtensions.cs
-
-
- Common\UriQueryUtility.cs
-
-
- Common\CollectionExtensions.cs
-
-
- Common\ListWrapperCollection.cs
-
-
- FormattingUtilities.cs
-
-
- Formatting\BaseJsonMediaTypeFormatter.cs
-
-
- Formatting\BsonMediaTypeFormatter.cs
-
-
- Formatting\DelegatingEnumerable.cs
-
-
- Formatting\FormDataCollection.cs
-
-
- Formatting\FormUrlEncodedJson.cs
-
-
- Formatting\IFormatterLogger.cs
-
-
- Formatting\JsonMediaTypeFormatter.cs
-
-
- Formatting\MediaTypeConstants.cs
-
-
- Formatting\MediaTypeFormatter.cs
-
-
- Formatting\MediaTypeFormatterCollection.cs
-
-
- Formatting\MediaTypeHeaderValueExtensions.cs
-
-
- Formatting\MediaTypeHeaderValueRange.cs
-
-
- Formatting\ParsedMediaTypeHeaderValue.cs
-
-
- Formatting\Parsers\FormUrlEncodedParser.cs
-
-
- Formatting\Parsers\HttpRequestHeaderParser.cs
-
-
- Formatting\Parsers\HttpRequestLineParser.cs
-
-
- Formatting\Parsers\HttpResponseHeaderParser.cs
-
-
- Formatting\Parsers\HttpStatusLineParser.cs
-
-
- Formatting\Parsers\InternetMessageFormatHeaderParser.cs
-
-
- Formatting\Parsers\MimeMultipartBodyPartParser.cs
-
-
- Formatting\Parsers\MimeMultipartParser.cs
-
-
- Formatting\Parsers\ParserState.cs
-
-
- Formatting\StringComparisonHelper.cs
-
-
- Formatting\XmlMediaTypeFormatter.cs
-
-
- HttpValueCollection.cs
-
-
- UriExtensions.cs
-
-
-
- Handlers\HttpProgressEventArgs.cs
-
-
- Handlers\ProgressContent.cs
-
-
- Handlers\ProgressMessageHandler.cs
-
-
- Handlers\ProgressStream.cs
-
-
- HttpClientExtensions.cs
-
-
- HttpClientFactory.cs
-
-
- HttpContentExtensions.cs
-
-
- HttpContentMessageExtensions.cs
-
-
- HttpContentMultipartExtensions.cs
-
-
- HttpHeaderExtensions.cs
-
-
- HttpMessageContent.cs
-
-
- HttpUnsortedHeaders.cs
-
-
- HttpUnsortedRequest.cs
-
-
- HttpUnsortedResponse.cs
-
-
- Internal\AsyncResult.cs
-
-
- Internal\DelegatingStream.cs
-
-
- Internal\ReadOnlyStreamWithEncodingPreamble.cs
-
-
- Internal\TypeExtensions.cs
-
-
- MimeBodyPart.cs
-
-
- MultipartFileData.cs
-
-
- MultipartMemoryStreamProvider.cs
-
-
- MultipartRelatedStreamProvider.cs
-
-
- MultipartStreamProvider.cs
-
-
- ObjectContent.cs
-
-
- ObjectContentOfT.cs
-
-
- PushStreamContent.cs
-
-
- Properties\AssemblyInfo.cs
-
-
- Properties\TransparentCommonAssemblyInfo.cs
- True
- True
- Resources.resx
-
-
- UnsupportedMediaTypeException.cs
-
-
-
-
-
-
- Properties\CommonWebApiResources.Designer.cs
- True
- True
- CommonWebApiResources.resx
-
-
-
-
- Properties\CommonWebApiResources.resx
- ResXFileCodeGenerator
- CommonWebApiResources.Designer.cs
-
-
-
-
- Properties\Resources.resx
- ResXFileCodeGenerator
- Resources.Designer.cs
- Designer
-
-
-
-
- CodeAnalysisDictionary.xml
-
-
-
-
-
-
-
- ..\..\packages\Newtonsoft.Json.6.0.4\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll
-
-
- ..\..\packages\Microsoft.Net.Http.2.2.13\lib\portable-net40+sl4+win8+wp71\System.Net.Http.dll
-
-
- ..\..\packages\Microsoft.Net.Http.2.2.13\lib\portable-net40+sl4+win8+wp71\System.Net.Http.Extensions.dll
-
-
- ..\..\packages\Microsoft.Net.Http.2.2.13\lib\portable-net40+sl4+win8+wp71\System.Net.Http.Primitives.dll
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/System.Net.Http.Formatting.NetCore/packages.config b/src/System.Net.Http.Formatting.NetCore/packages.config
deleted file mode 100644
index 658b8185c..000000000
--- a/src/System.Net.Http.Formatting.NetCore/packages.config
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj b/src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj
deleted file mode 100644
index 49eb0f3a9..000000000
--- a/src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj
+++ /dev/null
@@ -1,258 +0,0 @@
-
-
-
-
- {636CA76A-C85C-42E2-B4AA-88046279B3CA}
- Library
- Properties
- System.Net.Http
- System.Net.Http.Formatting
- $(OutputPath)NetStandard\
- $(OutputPath)$(AssemblyName).xml
- $(CodeAnalysis)
- ..\Strict.ruleset
- /assemblycomparemode:StrongNameIgnoringVersion
- false
- $(DefineConstants);NETFX_CORE;ASPNETMVC;NOT_CLS_COMPLIANT;NETSTANDARD1_1
- {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- 14.0
- 1591
- v5.0
-
-
-
- Properties\CommonAssemblyInfo.cs
-
-
- Common\Error.cs
-
-
- Common\TaskHelpers.cs
-
-
- Common\TaskHelpersExtensions.cs
-
-
- Common\UriQueryUtility.cs
-
-
- Common\CollectionExtensions.cs
-
-
- Common\ListWrapperCollection.cs
-
-
- FormattingUtilities.cs
-
-
- Formatting\BaseJsonMediaTypeFormatter.cs
-
-
- Formatting\BsonMediaTypeFormatter.cs
-
-
- Formatting\DelegatingEnumerable.cs
-
-
- Formatting\FormDataCollection.cs
-
-
- Formatting\FormUrlEncodedJson.cs
-
-
- Formatting\IFormatterLogger.cs
-
-
- Formatting\JsonMediaTypeFormatter.cs
-
-
- Formatting\MediaTypeConstants.cs
-
-
- Formatting\MediaTypeFormatter.cs
-
-
- Formatting\MediaTypeFormatterCollection.cs
-
-
- Formatting\MediaTypeHeaderValueExtensions.cs
-
-
- Formatting\MediaTypeHeaderValueRange.cs
-
-
- Formatting\ParsedMediaTypeHeaderValue.cs
-
-
- Formatting\Parsers\FormUrlEncodedParser.cs
-
-
- Formatting\Parsers\HttpRequestHeaderParser.cs
-
-
- Formatting\Parsers\HttpRequestLineParser.cs
-
-
- Formatting\Parsers\HttpResponseHeaderParser.cs
-
-
- Formatting\Parsers\HttpStatusLineParser.cs
-
-
- Formatting\Parsers\InternetMessageFormatHeaderParser.cs
-
-
- Formatting\Parsers\MimeMultipartBodyPartParser.cs
-
-
- Formatting\Parsers\MimeMultipartParser.cs
-
-
- Formatting\Parsers\ParserState.cs
-
-
- Formatting\StringComparisonHelper.cs
-
-
- Formatting\XmlMediaTypeFormatter.cs
-
-
- Internal\HttpValueCollection.cs
-
-
- UriExtensions.cs
-
-
- GlobalSuppressions.cs
-
-
- Handlers\HttpProgressEventArgs.cs
-
-
- Handlers\ProgressContent.cs
-
-
- Handlers\ProgressMessageHandler.cs
-
-
- Handlers\ProgressStream.cs
-
-
- HttpClientExtensions.cs
-
-
- HttpClientFactory.cs
-
-
- HttpContentExtensions.cs
-
-
- HttpContentMessageExtensions.cs
-
-
- HttpContentMultipartExtensions.cs
-
-
- HttpHeaderExtensions.cs
-
-
- HttpMessageContent.cs
-
-
- HttpUnsortedHeaders.cs
-
-
- HttpUnsortedRequest.cs
-
-
- HttpUnsortedResponse.cs
-
-
- Internal\AsyncResult.cs
-
-
- Internal\DelegatingStream.cs
-
-
- Internal\ReadOnlyStreamWithEncodingPreamble.cs
-
-
- Internal\TypeExtensions.cs
-
-
- MimeBodyPart.cs
-
-
- MultipartFileData.cs
-
-
- MultipartMemoryStreamProvider.cs
-
-
- MultipartRelatedStreamProvider.cs
-
-
- MultipartStreamProvider.cs
-
-
- ObjectContent.cs
-
-
- ObjectContentOfT.cs
-
-
- PushStreamContent.cs
-
-
- Properties\AssemblyInfo.cs
-
-
- Properties\Resources.Designer.cs
- True
- True
- Resources.resx
-
-
- UnsupportedMediaTypeException.cs
-
-
- Internal\ConcurrentDictionary.cs
-
-
- MediaTypeHeaderValueExtensions.cs
-
-
-
-
- Properties\CommonWebApiResources.Designer.cs
- True
- True
- CommonWebApiResources.resx
-
-
-
-
- Properties\CommonWebApiResources.resx
- ResXFileCodeGenerator
- CommonWebApiResources.Designer.cs
-
-
-
-
- Properties\Resources.resx
- ResXFileCodeGenerator
- Resources.Designer.cs
- Designer
-
-
-
-
- CodeAnalysisDictionary.xml
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/System.Net.Http.Formatting.NetStandard/project.json b/src/System.Net.Http.Formatting.NetStandard/project.json
deleted file mode 100644
index 0f162d655..000000000
--- a/src/System.Net.Http.Formatting.NetStandard/project.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "supports": {},
- "dependencies": {
- "NETStandard.Library": "1.6.0",
- "Newtonsoft.Json": "9.0.1",
- "System.ComponentModel.EventBasedAsync": "4.0.11",
- "System.Diagnostics.Contracts": "4.0.1",
- "System.Runtime.Serialization.Xml": "4.1.1",
- "System.Xml.XmlSerializer": "4.0.11"
- },
- "frameworks": {
- "netstandard1.1": {}
- }
-}
\ No newline at end of file
diff --git a/src/System.Net.Http.Formatting.ns1_3/ICloneable.cs b/src/System.Net.Http.Formatting.ns1_3/ICloneable.cs
new file mode 100644
index 000000000..1fc5b88c5
--- /dev/null
+++ b/src/System.Net.Http.Formatting.ns1_3/ICloneable.cs
@@ -0,0 +1,9 @@
+// No ICloneable interface in .NET Standard 1.3.
+
+namespace System
+{
+ internal interface ICloneable
+ {
+ object Clone();
+ }
+}
diff --git a/src/System.Net.Http.Formatting.NetCore/MediaTypeHeaderValueExtensions.cs b/src/System.Net.Http.Formatting.ns1_3/MediaTypeHeaderValueExtensions.cs
similarity index 100%
rename from src/System.Net.Http.Formatting.NetCore/MediaTypeHeaderValueExtensions.cs
rename to src/System.Net.Http.Formatting.ns1_3/MediaTypeHeaderValueExtensions.cs
diff --git a/src/System.Net.Http.Formatting.ns1_3/System.Net.Http.Formatting.ns1_3.csproj b/src/System.Net.Http.Formatting.ns1_3/System.Net.Http.Formatting.ns1_3.csproj
new file mode 100644
index 000000000..cb723ee1d
--- /dev/null
+++ b/src/System.Net.Http.Formatting.ns1_3/System.Net.Http.Formatting.ns1_3.csproj
@@ -0,0 +1,73 @@
+
+
+
+ netstandard1.3
+ System.Net.Http
+ System.Net.Http.Formatting
+ $(OutputPath)ns1_3\
+ $(OutputPath)$(AssemblyName).xml
+ false
+ $(DefineConstants);ASPNETHTTPFORMATTING
+ 1591
+ false
+ $(Configurations);CodeAnalysis
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ %(RecursiveDir)\%(Filename).cs
+
+
+
+ True
+ CommonWebApiResources.resx
+ True
+ Properties\CommonWebApiResources.Designer.cs
+
+
+ ResXFileCodeGenerator
+ CommonWebApiResources.Designer.cs
+ Properties\CommonWebApiResources.resx
+
+
+
+ True
+ Resources.resx
+ True
+ Properties\Resources.Designer.cs
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+ Properties\Resources.resx
+ Designer
+
+
+
+
+
diff --git a/src/System.Net.Http.Formatting.ns2_0/System.Net.Http.Formatting.ns2_0.csproj b/src/System.Net.Http.Formatting.ns2_0/System.Net.Http.Formatting.ns2_0.csproj
new file mode 100644
index 000000000..b31b98d40
--- /dev/null
+++ b/src/System.Net.Http.Formatting.ns2_0/System.Net.Http.Formatting.ns2_0.csproj
@@ -0,0 +1,64 @@
+
+
+
+ netstandard2.0
+ System.Net.Http
+ System.Net.Http.Formatting
+ $(OutputPath)ns2_0\
+ $(OutputPath)$(AssemblyName).xml
+ false
+ $(DefineConstants);ASPNETHTTPFORMATTING
+ 1591
+ false
+ $(Configurations);CodeAnalysis
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ %(RecursiveDir)\%(Filename).cs
+
+
+
+ True
+ CommonWebApiResources.resx
+ True
+ Properties\CommonWebApiResources.Designer.cs
+
+
+ ResXFileCodeGenerator
+ CommonWebApiResources.Designer.cs
+ Properties\CommonWebApiResources.resx
+
+
+
+ True
+ Resources.resx
+ True
+ Properties\Resources.Designer.cs
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+ Properties\Resources.resx
+ Designer
+
+
+
+
+
diff --git a/src/System.Net.Http.Formatting/ByteRangeStreamContent.cs b/src/System.Net.Http.Formatting/ByteRangeStreamContent.cs
index 587a0fd7f..40edaddb8 100644
--- a/src/System.Net.Http.Formatting/ByteRangeStreamContent.cs
+++ b/src/System.Net.Http.Formatting/ByteRangeStreamContent.cs
@@ -13,8 +13,8 @@ namespace System.Net.Http
{
///
/// implementation which provides a byte range view over a stream used to generate HTTP
- /// 206 (Partial Content) byte range responses. The supports one or more
- /// byte ranges regardless of whether the ranges are consecutive or not. If there is only one range then a
+ /// 206 (Partial Content) byte range responses. The supports one or more
+ /// byte ranges regardless of whether the ranges are consecutive or not. If there is only one range then a
/// single partial response body containing a Content-Range header is generated. If there are more than one
/// ranges then a multipart/byteranges response is generated where each body part contains a range indicated
/// by the associated Content-Range header field.
@@ -33,9 +33,9 @@ public class ByteRangeStreamContent : HttpContent
///
/// implementation which provides a byte range view over a stream used to generate HTTP
- /// 206 (Partial Content) byte range responses. If none of the requested ranges overlap with the current extend
- /// of the selected resource represented by the parameter then an
- /// is thrown indicating the valid Content-Range of the content.
+ /// 206 (Partial Content) byte range responses. If none of the requested ranges overlap with the current extend
+ /// of the selected resource represented by the parameter then an
+ /// is thrown indicating the valid Content-Range of the content.
///
/// The stream over which to generate a byte range view.
/// The range or ranges, typically obtained from the Range HTTP request header field.
@@ -47,9 +47,9 @@ public ByteRangeStreamContent(Stream content, RangeHeaderValue range, string med
///
/// implementation which provides a byte range view over a stream used to generate HTTP
- /// 206 (Partial Content) byte range responses. If none of the requested ranges overlap with the current extend
- /// of the selected resource represented by the parameter then an
- /// is thrown indicating the valid Content-Range of the content.
+ /// 206 (Partial Content) byte range responses. If none of the requested ranges overlap with the current extend
+ /// of the selected resource represented by the parameter then an
+ /// is thrown indicating the valid Content-Range of the content.
///
/// The stream over which to generate a byte range view.
/// The range or ranges, typically obtained from the Range HTTP request header field.
@@ -62,9 +62,9 @@ public ByteRangeStreamContent(Stream content, RangeHeaderValue range, string med
///
/// implementation which provides a byte range view over a stream used to generate HTTP
- /// 206 (Partial Content) byte range responses. If none of the requested ranges overlap with the current extend
- /// of the selected resource represented by the parameter then an
- /// is thrown indicating the valid Content-Range of the content.
+ /// 206 (Partial Content) byte range responses. If none of the requested ranges overlap with the current extend
+ /// of the selected resource represented by the parameter then an
+ /// is thrown indicating the valid Content-Range of the content.
///
/// The stream over which to generate a byte range view.
/// The range or ranges, typically obtained from the Range HTTP request header field.
@@ -76,9 +76,9 @@ public ByteRangeStreamContent(Stream content, RangeHeaderValue range, MediaTypeH
///
/// implementation which provides a byte range view over a stream used to generate HTTP
- /// 206 (Partial Content) byte range responses. If none of the requested ranges overlap with the current extend
- /// of the selected resource represented by the parameter then an
- /// is thrown indicating the valid Content-Range of the content.
+ /// 206 (Partial Content) byte range responses. If none of the requested ranges overlap with the current extend
+ /// of the selected resource represented by the parameter then an
+ /// is thrown indicating the valid Content-Range of the content.
///
/// The stream over which to generate a byte range view.
/// The range or ranges, typically obtained from the Range HTTP request header field.
diff --git a/src/System.Net.Http.Formatting/Formatting/BaseJsonMediaTypeFormatter.cs b/src/System.Net.Http.Formatting/Formatting/BaseJsonMediaTypeFormatter.cs
index b30a22edf..c25bdba46 100644
--- a/src/System.Net.Http.Formatting/Formatting/BaseJsonMediaTypeFormatter.cs
+++ b/src/System.Net.Http.Formatting/Formatting/BaseJsonMediaTypeFormatter.cs
@@ -10,9 +10,7 @@
using System.Threading.Tasks;
using System.Web.Http;
using Newtonsoft.Json;
-#if !NETFX_CORE
using Newtonsoft.Json.Serialization;
-#endif
namespace System.Net.Http.Formatting
{
@@ -21,12 +19,10 @@ namespace System.Net.Http.Formatting
///
public abstract class BaseJsonMediaTypeFormatter : MediaTypeFormatter
{
- // Though MaxDepth is not supported in portable library, we still override JsonReader's MaxDepth
+ // Though MaxDepth is not supported in netstandard1.3, we still override JsonReader's MaxDepth
private int _maxDepth = FormattingUtilities.DefaultMaxDepth;
-#if !NETFX_CORE // DataContractResolver is not supported in portable library
private readonly IContractResolver _defaultContractResolver;
-#endif
private JsonSerializerSettings _jsonSerializerSettings;
@@ -36,9 +32,7 @@ public abstract class BaseJsonMediaTypeFormatter : MediaTypeFormatter
protected BaseJsonMediaTypeFormatter()
{
// Initialize serializer settings
-#if !NETFX_CORE // DataContractResolver is not supported in portable library
_defaultContractResolver = new JsonContractResolver(this);
-#endif
_jsonSerializerSettings = CreateDefaultSerializerSettings();
// Set default supported character encodings
@@ -50,19 +44,15 @@ protected BaseJsonMediaTypeFormatter()
/// Initializes a new instance of the class.
///
/// The instance to copy settings from.
-#if !NETFX_CORE
[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors",
Justification = "MaxDepth is sealed in existing subclasses and its documentation carries warnings.")]
-#endif
protected BaseJsonMediaTypeFormatter(BaseJsonMediaTypeFormatter formatter)
: base(formatter)
{
Contract.Assert(formatter != null);
SerializerSettings = formatter.SerializerSettings;
-#if !NETFX_CORE // MaxDepth is not supported in portable library and so _maxDepth never changes there
MaxDepth = formatter._maxDepth;
-#endif
}
///
@@ -82,7 +72,6 @@ public JsonSerializerSettings SerializerSettings
}
}
-#if !NETFX_CORE // MaxDepth is not supported in portable library
///
/// Gets or sets the maximum depth allowed by this formatter.
///
@@ -106,22 +95,15 @@ public virtual int MaxDepth
_maxDepth = value;
}
}
-#endif
///
/// Creates a instance with the default settings used by the .
///
-#if NETFX_CORE
- [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "This could only be static half the time.")]
-#endif
public JsonSerializerSettings CreateDefaultSerializerSettings()
{
return new JsonSerializerSettings()
{
-#if !NETFX_CORE // DataContractResolver is not supported in portable library
ContractResolver = _defaultContractResolver,
-#endif
-
MissingMemberHandling = MissingMemberHandling.Ignore,
// Do not change this setting
diff --git a/src/System.Net.Http.Formatting/Formatting/BsonMediaTypeFormatter.cs b/src/System.Net.Http.Formatting/Formatting/BsonMediaTypeFormatter.cs
index 8b686f0c5..fe6fdef23 100644
--- a/src/System.Net.Http.Formatting/Formatting/BsonMediaTypeFormatter.cs
+++ b/src/System.Net.Http.Formatting/Formatting/BsonMediaTypeFormatter.cs
@@ -60,7 +60,6 @@ public static MediaTypeHeaderValue DefaultMediaType
}
}
-#if !NETFX_CORE // MaxDepth and DBNull not supported in portable library; no need to override there
///
public sealed override int MaxDepth
{
@@ -101,7 +100,6 @@ public override Task
public class JsonMediaTypeFormatter : BaseJsonMediaTypeFormatter
{
-#if !NETFX_CORE // DataContractJsonSerializer and MediaTypeMappings are not supported in portable library
- private ConcurrentDictionary _dataContractSerializerCache = new ConcurrentDictionary();
- private XmlDictionaryReaderQuotas _readerQuotas = FormattingUtilities.CreateDefaultReaderQuotas();
- private RequestHeaderMapping _requestHeaderMapping;
-#endif
+ private readonly ConcurrentDictionary _dataContractSerializerCache = new ConcurrentDictionary();
+ private readonly XmlDictionaryReaderQuotas _readerQuotas = FormattingUtilities.CreateDefaultReaderQuotas();
+ private readonly RequestHeaderMapping _requestHeaderMapping;
///
/// Initializes a new instance of the class.
@@ -45,10 +37,8 @@ public JsonMediaTypeFormatter()
SupportedMediaTypes.Add(MediaTypeConstants.ApplicationJsonMediaType);
SupportedMediaTypes.Add(MediaTypeConstants.TextJsonMediaType);
-#if !NETFX_CORE // MediaTypeMappings are not supported in portable library
_requestHeaderMapping = new XmlHttpRequestHeaderMapping();
MediaTypeMappings.Add(_requestHeaderMapping);
-#endif
}
///
@@ -60,10 +50,7 @@ protected JsonMediaTypeFormatter(JsonMediaTypeFormatter formatter)
{
Contract.Assert(formatter != null);
-#if !NETFX_CORE // UseDataContractJsonSerializer is not supported in portable library
UseDataContractJsonSerializer = formatter.UseDataContractJsonSerializer;
-#endif
-
Indent = formatter.Indent;
}
@@ -84,7 +71,6 @@ public static MediaTypeHeaderValue DefaultMediaType
get { return MediaTypeConstants.ApplicationJsonMediaType; }
}
-#if !NETFX_CORE // DataContractJsonSerializer is not supported in portable library
///
/// Gets or sets a value indicating whether to use by default.
///
@@ -92,14 +78,12 @@ public static MediaTypeHeaderValue DefaultMediaType
/// true if use by default; otherwise, false. The default is false.
///
public bool UseDataContractJsonSerializer { get; set; }
-#endif
///
- /// Gets or sets a value indicating whether to indent elements when writing data.
+ /// Gets or sets a value indicating whether to indent elements when writing data.
///
public bool Indent { get; set; }
-#if !NETFX_CORE // MaxDepth not supported in portable library; no need to override there
///
public sealed override int MaxDepth
{
@@ -113,7 +97,6 @@ public sealed override int MaxDepth
_readerQuotas.MaxDepth = value;
}
}
-#endif
///
public override JsonReader CreateJsonReader(Type type, Stream readStream, Encoding effectiveEncoding)
@@ -163,7 +146,6 @@ public override JsonWriter CreateJsonWriter(Type type, Stream writeStream, Encod
return jsonWriter;
}
-#if !NETFX_CORE // DataContractJsonSerializer not supported in portable library; no need to override there
///
public override bool CanReadType(Type type)
{
@@ -233,10 +215,21 @@ public override object ReadFromStream(Type type, Stream readStream, Encoding eff
if (UseDataContractJsonSerializer)
{
DataContractJsonSerializer dataContractSerializer = GetDataContractSerializer(type);
- using (XmlReader reader = JsonReaderWriterFactory.CreateJsonReader(new NonClosingDelegatingStream(readStream), effectiveEncoding, _readerQuotas, null))
- {
- return dataContractSerializer.ReadObject(reader);
- }
+
+#if NETSTANDARD1_3 // Unreachable when targeting netstandard1.3. Return just to satisfy the compiler.
+ return null;
+#else
+ // DCS encodings are limited to UTF8, UTF16BE, and UTF16LE. Convert to UTF8 as we read.
+ Stream innerStream =
+ string.Equals(effectiveEncoding.WebName, Utf8Encoding.WebName, StringComparison.OrdinalIgnoreCase) ?
+ new NonClosingDelegatingStream(readStream) :
+ new TranscodingStream(readStream, effectiveEncoding, Utf8Encoding, leaveOpen: true);
+
+ // XmlDictionaryReader will always dispose of innerStream when we dispose of the reader.
+ using XmlDictionaryReader reader =
+ JsonReaderWriterFactory.CreateJsonReader(innerStream, Utf8Encoding, _readerQuotas, onClose: null);
+ return dataContractSerializer.ReadObject(reader);
+#endif
}
else
{
@@ -294,10 +287,18 @@ public override void WriteToStream(Type type, object value, Stream writeStream,
}
}
- DataContractJsonSerializer dataContractSerializer = GetDataContractSerializer(type);
- using (XmlWriter writer = JsonReaderWriterFactory.CreateJsonWriter(writeStream, effectiveEncoding, ownsStream: false))
+ WritePreamble(writeStream, effectiveEncoding);
+ if (string.Equals(effectiveEncoding.WebName, Utf8Encoding.WebName, StringComparison.OrdinalIgnoreCase))
{
- dataContractSerializer.WriteObject(writer, value);
+ WriteObject(writeStream, type, value);
+ }
+ else
+ {
+ // JsonReaderWriterFactory is internal and DataContractJsonSerializer only writes UTF8 for the
+ // netstandard1.3 project. In addition, DCS encodings are limited to UTF8, UTF16BE, and UTF16LE.
+ // Convert to UTF8 as we write.
+ using var innerStream = new TranscodingStream(writeStream, effectiveEncoding, Utf8Encoding, leaveOpen: true);
+ WriteObject(innerStream, type, value);
}
}
else
@@ -306,11 +307,35 @@ public override void WriteToStream(Type type, object value, Stream writeStream,
}
}
+ private void WriteObject(Stream stream, Type type, object value)
+ {
+ DataContractJsonSerializer dataContractSerializer = GetDataContractSerializer(type);
+
+#if !NETSTANDARD1_3 // Unreachable when targeting netstandard1.3.
+ // Do not dispose of the stream. WriteToStream handles that where it's needed.
+ using XmlWriter writer = JsonReaderWriterFactory.CreateJsonWriter(stream, Utf8Encoding, ownsStream: false);
+ dataContractSerializer.WriteObject(writer, value);
+#endif
+ }
+
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Catch all is around an extensibile method")]
private DataContractJsonSerializer CreateDataContractSerializer(Type type, bool throwOnError)
{
Contract.Assert(type != null);
+#if NETSTANDARD1_3 // XsdDataContractExporter is not supported in netstandard1.3
+ if (throwOnError)
+ {
+ throw new PlatformNotSupportedException(Error.Format(
+ Properties.Resources.JsonMediaTypeFormatter_DCS_NotSupported,
+ nameof(UseDataContractJsonSerializer)));
+ }
+ else
+ {
+ return null;
+ }
+#else
+
DataContractJsonSerializer serializer = null;
Exception exception = null;
@@ -318,6 +343,7 @@ private DataContractJsonSerializer CreateDataContractSerializer(Type type, bool
{
// Verify that type is a valid data contract by forcing the serializer to try to create a data contract
FormattingUtilities.XsdDataContractExporter.GetRootElementName(type);
+
serializer = CreateDataContractSerializer(type);
}
catch (Exception caught)
@@ -342,6 +368,7 @@ private DataContractJsonSerializer CreateDataContractSerializer(Type type, bool
}
return serializer;
+#endif
}
///
@@ -378,6 +405,5 @@ private DataContractJsonSerializer GetDataContractSerializer(Type type)
return serializer;
}
-#endif
}
}
diff --git a/src/System.Net.Http.Formatting/Formatting/MediaTypeFormatter.cs b/src/System.Net.Http.Formatting/Formatting/MediaTypeFormatter.cs
index dd7731e1d..20eace069 100644
--- a/src/System.Net.Http.Formatting/Formatting/MediaTypeFormatter.cs
+++ b/src/System.Net.Http.Formatting/Formatting/MediaTypeFormatter.cs
@@ -1,17 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-#if !NETFX_CORE // In portable library we have our own implementation of Concurrent Dictionary which is in the internal namespace
using System.Collections.Concurrent;
-#endif
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
-#if NETFX_CORE // In portable library we have our own implementation of Concurrent Dictionary which is in the internal namespace
-using System.Net.Http.Internal;
-#endif
using System.Reflection;
using System.Text;
using System.Threading;
@@ -25,6 +20,8 @@ namespace System.Net.Http.Formatting
///
public abstract class MediaTypeFormatter
{
+ private protected static readonly Encoding Utf8Encoding =
+ new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
private const int DefaultMinHttpCollectionKeys = 1;
private const int DefaultMaxHttpCollectionKeys = 1000; // same default as ASPNET
private const string IWellKnownComparerTypeName = "System.IWellKnownStringEqualityComparer, mscorlib, Version=4.0.0.0, PublicKeyToken=b77a5c561934e089";
@@ -36,10 +33,8 @@ public abstract class MediaTypeFormatter
private readonly List _supportedMediaTypes;
private readonly List _supportedEncodings;
-#if !NETFX_CORE // No MediaTypeMappings in portable library or IRequiredMemberSelector (no model state on client)
private readonly List _mediaTypeMappings;
private IRequiredMemberSelector _requiredMemberSelector;
-#endif
///
/// Initializes a new instance of the class.
@@ -50,10 +45,8 @@ protected MediaTypeFormatter()
SupportedMediaTypes = new MediaTypeHeaderValueCollection(_supportedMediaTypes);
_supportedEncodings = new List();
SupportedEncodings = new Collection(_supportedEncodings);
-#if !NETFX_CORE // No MediaTypeMappings in portable library
_mediaTypeMappings = new List();
MediaTypeMappings = new Collection(_mediaTypeMappings);
-#endif
}
///
@@ -71,15 +64,13 @@ protected MediaTypeFormatter(MediaTypeFormatter formatter)
SupportedMediaTypes = formatter.SupportedMediaTypes;
_supportedEncodings = formatter._supportedEncodings;
SupportedEncodings = formatter.SupportedEncodings;
-#if !NETFX_CORE // No MediaTypeMappings in portable library or IRequiredMemberSelector (no model state on client)
_mediaTypeMappings = formatter._mediaTypeMappings;
MediaTypeMappings = formatter.MediaTypeMappings;
_requiredMemberSelector = formatter._requiredMemberSelector;
-#endif
}
///
- /// Gets or sets the maximum number of keys stored in a NameValueCollection.
+ /// Gets or sets the maximum number of keys stored in a NameValueCollection.
///
public static int MaxHttpCollectionKeys
{
@@ -117,7 +108,7 @@ internal List SupportedMediaTypesInternal
///
/// Gets the mutable collection of character encodings supported by
/// this instance. The encodings are
- /// used when reading or writing data.
+ /// used when reading or writing data.
///
public Collection SupportedEncodings { get; private set; }
@@ -126,7 +117,6 @@ internal List SupportedEncodingsInternal
get { return _supportedEncodings; }
}
-#if !NETFX_CORE // No MediaTypeMappings in portable library
///
/// Gets the mutable collection of elements used
/// by this instance to determine the
@@ -138,9 +128,7 @@ internal List MediaTypeMappingsInternal
{
get { return _mediaTypeMappings; }
}
-#endif
-#if !NETFX_CORE // IRequiredMemberSelector is not in portable libraries because there is no model state on the client.
///
/// Gets or sets the used to determine required members.
///
@@ -155,7 +143,6 @@ public virtual IRequiredMemberSelector RequiredMemberSelector
_requiredMemberSelector = value;
}
}
-#endif
internal virtual bool CanWriteAnyTypes
{
@@ -504,6 +491,15 @@ public static object GetDefaultValueForType(Type type)
return null;
}
+ private protected static void WritePreamble(Stream stream, Encoding encoding)
+ {
+ byte[] bytes = encoding.GetPreamble();
+ if (bytes.Length > 0)
+ {
+ stream.Write(bytes, 0, bytes.Length);
+ }
+ }
+
///
/// Collection class that validates it contains only instances
/// that are not null and not media ranges.
diff --git a/src/System.Net.Http.Formatting/Formatting/MediaTypeFormatterCollection.cs b/src/System.Net.Http.Formatting/Formatting/MediaTypeFormatterCollection.cs
index 2a54f050a..864eacded 100644
--- a/src/System.Net.Http.Formatting/Formatting/MediaTypeFormatterCollection.cs
+++ b/src/System.Net.Http.Formatting/Formatting/MediaTypeFormatterCollection.cs
@@ -59,7 +59,6 @@ public JsonMediaTypeFormatter JsonFormatter
get { return Items.OfType().FirstOrDefault(); }
}
-#if !NETFX_CORE // FormUrlEncodedMediaTypeFormatter is not supported in portable library.
///
/// Gets the to use for application/x-www-form-urlencoded data.
///
@@ -67,7 +66,6 @@ public FormUrlEncodedMediaTypeFormatter FormUrlEncodedFormatter
{
get { return Items.OfType().FirstOrDefault(); }
}
-#endif
internal MediaTypeFormatter[] WritingFormatters
{
@@ -200,10 +198,8 @@ public MediaTypeFormatter FindWriter(Type type, MediaTypeHeaderValue mediaType)
public static bool IsTypeExcludedFromValidation(Type type)
{
return
-#if !NETFX_CORE
typeof(XmlNode).IsAssignableFrom(type) ||
typeof(FormDataCollection).IsAssignableFrom(type) ||
-#endif
FormattingUtilities.IsJTokenType(type) ||
typeof(XObject).IsAssignableFrom(type) ||
typeof(Type).IsAssignableFrom(type) ||
@@ -259,10 +255,12 @@ private static IEnumerable CreateDefaultFormatters()
return new MediaTypeFormatter[]
{
new JsonMediaTypeFormatter(),
- new XmlMediaTypeFormatter(),
-#if !NETFX_CORE
- new FormUrlEncodedMediaTypeFormatter()
+ new XmlMediaTypeFormatter()
+#if NETSTANDARD1_3 // XsdDataContractExporter is not supported in netstandard1.3. Cannot use DCS.
+ { UseXmlSerializer = true }
#endif
+ ,
+ new FormUrlEncodedMediaTypeFormatter()
};
}
diff --git a/src/System.Net.Http.Formatting/Formatting/MediaTypeHeaderValueExtensions.cs b/src/System.Net.Http.Formatting/Formatting/MediaTypeHeaderValueExtensions.cs
index a0cae45d0..7f58a0d18 100644
--- a/src/System.Net.Http.Formatting/Formatting/MediaTypeHeaderValueExtensions.cs
+++ b/src/System.Net.Http.Formatting/Formatting/MediaTypeHeaderValueExtensions.cs
@@ -17,8 +17,8 @@ internal static class MediaTypeHeaderValueExtensions
///
/// Determines whether two instances match. The instance
/// is said to match if and only if
- /// is a strict subset of the values and parameters of .
- /// That is, if the media type and media type parameters of are all present
+ /// is a strict subset of the values and parameters of .
+ /// That is, if the media type and media type parameters of are all present
/// and match those of then it is a match even though may have additional
/// parameters.
///
@@ -34,8 +34,8 @@ public static bool IsSubsetOf(this MediaTypeHeaderValue mediaType1, MediaTypeHea
///
/// Determines whether two instances match. The instance
/// is said to match if and only if
- /// is a strict subset of the values and parameters of .
- /// That is, if the media type and media type parameters of are all present
+ /// is a strict subset of the values and parameters of .
+ /// That is, if the media type and media type parameters of are all present
/// and match those of then it is a match even though may have additional
/// parameters.
///
@@ -75,12 +75,12 @@ public static bool IsSubsetOf(this MediaTypeHeaderValue mediaType1, MediaTypeHea
}
}
- // So far we either have a full match or a subset match. Now check that all of
+ // So far we either have a full match or a subset match. Now check that all of
// mediaType1's parameters are present and equal in mediatype2
// Optimize for the common case where the parameters inherit from Collection and cache the count which is faster for Collection.
Collection parameters1 = mediaType1.Parameters.AsCollection();
int parameterCount1 = parameters1.Count;
- Collection parameters2 = mediaType2.Parameters.AsCollection();
+ Collection parameters2 = mediaType2.Parameters.AsCollection();
int parameterCount2 = parameters2.Count;
for (int i = 0; i < parameterCount1; i++)
{
diff --git a/src/System.Net.Http.Formatting/Formatting/MediaTypeWithQualityHeaderValueComparer.cs b/src/System.Net.Http.Formatting/Formatting/MediaTypeWithQualityHeaderValueComparer.cs
index 549d2272f..277759254 100644
--- a/src/System.Net.Http.Formatting/Formatting/MediaTypeWithQualityHeaderValueComparer.cs
+++ b/src/System.Net.Http.Formatting/Formatting/MediaTypeWithQualityHeaderValueComparer.cs
@@ -8,7 +8,7 @@
namespace System.Net.Http.Formatting
{
/// Implementation of that can compare accept media type header fields
- /// based on their quality values (a.k.a q-values). See
+ /// based on their quality values (a.k.a q-values). See
/// for a comparer for other content negotiation
/// header field q-values.
internal class MediaTypeWithQualityHeaderValueComparer : IComparer
@@ -26,8 +26,8 @@ public static MediaTypeWithQualityHeaderValueComparer QualityComparer
///
/// Compares two based on their quality value (a.k.a their "q-value").
- /// Values with identical q-values are considered equal (i.e the result is 0) with the exception that sub-type wild-cards are
- /// considered less than specific media types and full wild-cards are considered less than sub-type wild-cards. This allows to
+ /// Values with identical q-values are considered equal (i.e the result is 0) with the exception that sub-type wild-cards are
+ /// considered less than specific media types and full wild-cards are considered less than sub-type wild-cards. This allows to
/// sort a sequence of following their q-values in the order of specific media types,
/// sub-type wildcards, and last any full wild-cards.
///
diff --git a/src/System.Net.Http.Formatting/Formatting/ParsedMediaTypeHeaderValue.cs b/src/System.Net.Http.Formatting/Formatting/ParsedMediaTypeHeaderValue.cs
index 057730391..fa1e4c259 100644
--- a/src/System.Net.Http.Formatting/Formatting/ParsedMediaTypeHeaderValue.cs
+++ b/src/System.Net.Http.Formatting/Formatting/ParsedMediaTypeHeaderValue.cs
@@ -40,14 +40,14 @@ public ParsedMediaTypeHeaderValue(MediaTypeHeaderValue mediaTypeHeaderValue)
}
}
- public bool IsAllMediaRange
- {
- get { return _isAllMediaRange; }
+ public bool IsAllMediaRange
+ {
+ get { return _isAllMediaRange; }
}
- public bool IsSubtypeMediaRange
- {
- get { return _isSubtypeMediaRange; }
+ public bool IsSubtypeMediaRange
+ {
+ get { return _isSubtypeMediaRange; }
}
public bool TypesEqual(ref ParsedMediaTypeHeaderValue other)
diff --git a/src/System.Net.Http.Formatting/Formatting/Parsers/FormUrlEncodedParser.cs b/src/System.Net.Http.Formatting/Formatting/Parsers/FormUrlEncodedParser.cs
index d7f248d16..90754c123 100644
--- a/src/System.Net.Http.Formatting/Formatting/Parsers/FormUrlEncodedParser.cs
+++ b/src/System.Net.Http.Formatting/Formatting/Parsers/FormUrlEncodedParser.cs
@@ -11,7 +11,7 @@
namespace System.Net.Http.Formatting.Parsers
{
///
- /// Buffer-oriented parsing of HTML form URL-ended, also known as application/x-www-form-urlencoded, data.
+ /// Buffer-oriented parsing of HTML form URL-ended, also known as application/x-www-form-urlencoded, data.
///
internal class FormUrlEncodedParser
{
@@ -54,7 +54,7 @@ private enum NameValueState
///
/// Parse a buffer of URL form-encoded name-value pairs and add them to the collection.
- /// Bytes are parsed in a consuming manner from the beginning of the buffer meaning that the same bytes can not be
+ /// Bytes are parsed in a consuming manner from the beginning of the buffer meaning that the same bytes can not be
/// present in the buffer.
///
/// Buffer from where data is read
@@ -243,7 +243,7 @@ private ParserState CopyCurrent(ParserState parseState)
}
///
- /// Maintains information about the current header field being parsed.
+ /// Maintains information about the current header field being parsed.
///
private class CurrentNameValuePair
{
@@ -275,9 +275,9 @@ public StringBuilder Value
/// The collection to copy into.
public void CopyTo(ICollection> nameValuePairs)
{
- string unescapedName = UriQueryUtility.UrlDecode(_name.ToString());
+ string unescapedName = WebUtility.UrlDecode(_name.ToString());
string escapedValue = _value.ToString();
- string value = UriQueryUtility.UrlDecode(escapedValue);
+ string value = WebUtility.UrlDecode(escapedValue);
nameValuePairs.Add(new KeyValuePair(unescapedName, value));
@@ -290,7 +290,7 @@ public void CopyTo(ICollection> nameValuePairs)
/// The collection to copy into.
public void CopyNameOnlyTo(ICollection> nameValuePairs)
{
- string unescapedName = UriQueryUtility.UrlDecode(_name.ToString());
+ string unescapedName = WebUtility.UrlDecode(_name.ToString());
string value = String.Empty;
nameValuePairs.Add(new KeyValuePair(unescapedName, value));
Clear();
diff --git a/src/System.Net.Http.Formatting/Formatting/Parsers/HttpRequestLineParser.cs b/src/System.Net.Http.Formatting/Formatting/Parsers/HttpRequestLineParser.cs
index 027270150..b89189f8a 100644
--- a/src/System.Net.Http.Formatting/Formatting/Parsers/HttpRequestLineParser.cs
+++ b/src/System.Net.Http.Formatting/Formatting/Parsers/HttpRequestLineParser.cs
@@ -56,8 +56,8 @@ private enum HttpRequestLineState
}
///
- /// Parse an HTTP request line.
- /// Bytes are parsed in a consuming manner from the beginning of the request buffer meaning that the same bytes can not be
+ /// Parse an HTTP request line.
+ /// Bytes are parsed in a consuming manner from the beginning of the request buffer meaning that the same bytes can not be
/// present in the request buffer.
///
/// Request buffer from where request is read
diff --git a/src/System.Net.Http.Formatting/Formatting/Parsers/HttpStatusLineParser.cs b/src/System.Net.Http.Formatting/Formatting/Parsers/HttpStatusLineParser.cs
index e64677e94..86f00f77d 100644
--- a/src/System.Net.Http.Formatting/Formatting/Parsers/HttpStatusLineParser.cs
+++ b/src/System.Net.Http.Formatting/Formatting/Parsers/HttpStatusLineParser.cs
@@ -58,8 +58,8 @@ private enum HttpStatusLineState
}
///
- /// Parse an HTTP status line.
- /// Bytes are parsed in a consuming manner from the beginning of the response buffer meaning that the same bytes can not be
+ /// Parse an HTTP status line.
+ /// Bytes are parsed in a consuming manner from the beginning of the response buffer meaning that the same bytes can not be
/// present in the response buffer.
///
/// Response buffer from where response is read
diff --git a/src/System.Net.Http.Formatting/Formatting/Parsers/InternetMessageFormatHeaderParser.cs b/src/System.Net.Http.Formatting/Formatting/Parsers/InternetMessageFormatHeaderParser.cs
index aebfa8c29..ebf22b9ba 100644
--- a/src/System.Net.Http.Formatting/Formatting/Parsers/InternetMessageFormatHeaderParser.cs
+++ b/src/System.Net.Http.Formatting/Formatting/Parsers/InternetMessageFormatHeaderParser.cs
@@ -10,8 +10,8 @@
namespace System.Net.Http.Formatting.Parsers
{
///
- /// Buffer-oriented RFC 5322 style Internet Message Format parser which can be used to pass header
- /// fields used in HTTP and MIME message entities.
+ /// Buffer-oriented RFC 5322 style Internet Message Format parser which can be used to pass header
+ /// fields used in HTTP and MIME message entities.
///
internal class InternetMessageFormatHeaderParser
{
@@ -76,7 +76,7 @@ private enum HeaderFieldState
///
/// Parse a buffer of RFC 5322 style header fields and add them to the collection.
- /// Bytes are parsed in a consuming manner from the beginning of the buffer meaning that the same bytes can not be
+ /// Bytes are parsed in a consuming manner from the beginning of the buffer meaning that the same bytes can not be
/// present in the buffer.
///
/// Request buffer from where request is read
@@ -283,7 +283,7 @@ private static ParserState ParseHeaderFields(
}
///
- /// Maintains information about the current header field being parsed.
+ /// Maintains information about the current header field being parsed.
///
private class CurrentHeaderFieldStore
{
@@ -320,6 +320,10 @@ public void CopyTo(HttpHeaders headers, bool ignoreHeaderValidation)
{
var name = _name.ToString();
var value = _value.ToString().Trim(CurrentHeaderFieldStore._linearWhiteSpace);
+ if (string.Equals("expires", name, StringComparison.OrdinalIgnoreCase))
+ {
+ ignoreHeaderValidation = true;
+ }
if (ignoreHeaderValidation)
{
diff --git a/src/System.Net.Http.Formatting/Formatting/Parsers/MimeMultipartBodyPartParser.cs b/src/System.Net.Http.Formatting/Formatting/Parsers/MimeMultipartBodyPartParser.cs
index 24981c209..4f135c6ed 100644
--- a/src/System.Net.Http.Formatting/Formatting/Parsers/MimeMultipartBodyPartParser.cs
+++ b/src/System.Net.Http.Formatting/Formatting/Parsers/MimeMultipartBodyPartParser.cs
@@ -11,7 +11,7 @@
namespace System.Net.Http.Formatting.Parsers
{
///
- /// Complete MIME multipart parser that combines for parsing the MIME message into individual body parts
+ /// Complete MIME multipart parser that combines for parsing the MIME message into individual body parts
/// and for parsing each body part into a MIME header and a MIME body. The caller of the parser is returned
/// the resulting MIME bodies which can then be written to some output.
///
@@ -104,7 +104,7 @@ public void Dispose()
}
///
- /// Parses the data provided and generates parsed MIME body part bodies in the form of which are ready to
+ /// Parses the data provided and generates parsed MIME body part bodies in the form of which are ready to
/// write to the output stream.
///
/// The data to parse
@@ -116,11 +116,11 @@ public IEnumerable ParseBuffer(byte[] data, int bytesRead)
bool isFinal = false;
// There's a special case here - if we've reached the end of the message and there's no optional
- // CRLF, then we're out of bytes to read, but we have finished the message.
+ // CRLF, then we're out of bytes to read, but we have finished the message.
//
- // If IsWaitingForEndOfMessage is true and we're at the end of the stream, then we're going to
- // call into the parser again with an empty array as the buffer to signal the end of the parse.
- // Then the final boundary segment will be marked as complete.
+ // If IsWaitingForEndOfMessage is true and we're at the end of the stream, then we're going to
+ // call into the parser again with an empty array as the buffer to signal the end of the parse.
+ // Then the final boundary segment will be marked as complete.
if (bytesRead == 0 && !_mimeParser.IsWaitingForEndOfMessage)
{
CleanupCurrentBodyPart();
@@ -195,7 +195,7 @@ public IEnumerable ParseBuffer(byte[] data, int bytesRead)
}
else
{
- // Otherwise return what we have
+ // Otherwise return what we have
yield return _currentBodyPart;
}
}
diff --git a/src/System.Net.Http.Formatting/Formatting/Parsers/MimeMultipartParser.cs b/src/System.Net.Http.Formatting/Formatting/Parsers/MimeMultipartParser.cs
index 734124566..40b83e617 100644
--- a/src/System.Net.Http.Formatting/Formatting/Parsers/MimeMultipartParser.cs
+++ b/src/System.Net.Http.Formatting/Formatting/Parsers/MimeMultipartParser.cs
@@ -122,7 +122,7 @@ public enum State
///
DataTooBig,
}
-
+
public bool CanParseMore(int bytesRead, int bytesConsumed)
{
if (bytesConsumed < bytesRead)
@@ -147,7 +147,7 @@ public bool CanParseMore(int bytesRead, int bytesConsumed)
///
/// Parse a MIME multipart message. Bytes are parsed in a consuming
- /// manner from the beginning of the request buffer meaning that the same bytes can not be
+ /// manner from the beginning of the request buffer meaning that the same bytes can not be
/// present in the request buffer.
///
/// Request buffer from where request is read
@@ -156,7 +156,7 @@ public bool CanParseMore(int bytesRead, int bytesConsumed)
/// Any body part that was considered as a potential MIME multipart boundary but which was in fact part of the body.
/// The bulk of the body part.
/// Indicates whether the final body part has been found.
- /// In order to get the complete body part, the caller is responsible for concatenating the contents of the
+ /// In order to get the complete body part, the caller is responsible for concatenating the contents of the
/// and out parameters.
/// State of the parser.
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Exception is translated to parse state.")]
@@ -375,7 +375,7 @@ private static State ParseBodyPart(
goto quit;
}
}
-
+
if (bytesConsumed > segmentStart)
{
if (!currentBodyPart.AppendBoundary(buffer, segmentStart, bytesConsumed - segmentStart))
@@ -391,7 +391,7 @@ private static State ParseBodyPart(
case BodyPartState.AfterBoundary:
// This state means that we just saw the end of a boundary. It might by a 'normal' boundary, in which
- // case it's followed by optional whitespace and a CRLF. Or it might be the 'final' boundary and will
+ // case it's followed by optional whitespace and a CRLF. Or it might be the 'final' boundary and will
// be followed by '--', optional whitespace and an optional CRLF.
if (buffer[bytesConsumed] == MimeMultipartParser.Dash && !currentBodyPart.IsFinal)
{
@@ -456,13 +456,13 @@ private static State ParseBodyPart(
{
currentBodyPart.AppendBoundary(MimeMultipartParser.Dash);
bytesConsumed++;
-
+
if (currentBodyPart.IsBoundaryComplete())
{
Debug.Assert(currentBodyPart.IsFinal);
- // If we get in here, it means we've see the trailing '--' of the last boundary - in order to consume all of the
- // remaining bytes, we don't mark the parse as complete again - wait until this method is called again with the
+ // If we get in here, it means we've see the trailing '--' of the last boundary - in order to consume all of the
+ // remaining bytes, we don't mark the parse as complete again - wait until this method is called again with the
// empty buffer to do that.
bodyPartState = BodyPartState.AfterBoundary;
parseStatus = State.NeedMoreData;
@@ -658,9 +658,9 @@ public void AppendBoundary(byte data)
/// The number of bytes to append.
public bool AppendBoundary(byte[] data, int offset, int count)
{
- // Check that potential boundary is not bigger than our reference boundary.
- // Allow for 2 extra characters to include the final boundary which ends with
- // an additional "--" sequence + plus up to 4 LWS characters (which are allowed).
+ // Check that potential boundary is not bigger than our reference boundary.
+ // Allow for 2 extra characters to include the final boundary which ends with
+ // an additional "--" sequence + plus up to 4 LWS characters (which are allowed).
if (_boundaryLength + count > _referenceBoundaryLength + 6)
{
return false;
@@ -753,7 +753,7 @@ public bool IsBoundaryComplete()
{
return false;
}
-
+
if (_boundaryLength < _referenceBoundaryLength)
{
return false;
@@ -797,9 +797,9 @@ private string DebuggerToString()
var boundary = Encoding.UTF8.GetString(_boundary, 0, _boundaryLength);
return String.Format(
- CultureInfo.InvariantCulture,
- "Expected: {0} *** Current: {1}",
- referenceBoundary,
+ CultureInfo.InvariantCulture,
+ "Expected: {0} *** Current: {1}",
+ referenceBoundary,
boundary);
}
}
diff --git a/src/System.Net.Http.Formatting/Formatting/RequestHeaderMapping.cs b/src/System.Net.Http.Formatting/Formatting/RequestHeaderMapping.cs
index 3deee8ca3..845d8903d 100644
--- a/src/System.Net.Http.Formatting/Formatting/RequestHeaderMapping.cs
+++ b/src/System.Net.Http.Formatting/Formatting/RequestHeaderMapping.cs
@@ -23,9 +23,9 @@ public class RequestHeaderMapping : MediaTypeMapping
/// Name of the header to match.
/// The header value to match.
/// The value comparison to use when matching .
- /// if set to true then is
+ /// if set to true then is
/// considered a match if it matches a substring of the actual header value.
- /// The media type to use if and
+ /// The media type to use if and
/// is considered a match.
public RequestHeaderMapping(string headerName, string headerValue, StringComparison valueComparison, bool isValueSubstring, string mediaType)
: base(mediaType)
@@ -39,9 +39,9 @@ public RequestHeaderMapping(string headerName, string headerValue, StringCompari
/// Name of the header to match.
/// The header value to match.
/// The to use when matching .
- /// if set to true then is
+ /// if set to true then is
/// considered a match if it matches a substring of the actual header value.
- /// The to use if and
+ /// The to use if and
/// is considered a match.
public RequestHeaderMapping(string headerName, string headerValue, StringComparison valueComparison, bool isValueSubstring, MediaTypeHeaderValue mediaType)
: base(mediaType)
@@ -65,7 +65,7 @@ public RequestHeaderMapping(string headerName, string headerValue, StringCompari
public StringComparison HeaderValueComparison { get; private set; }
///
- /// Gets a value indicating whether is
+ /// Gets a value indicating whether is
/// a matched as a substring of the actual header value.
/// this instance is value substring.
///
diff --git a/src/System.Net.Http.Formatting/Formatting/StringComparisonHelper.cs b/src/System.Net.Http.Formatting/Formatting/StringComparisonHelper.cs
index 8dade6d2d..8f45ee70c 100644
--- a/src/System.Net.Http.Formatting/Formatting/StringComparisonHelper.cs
+++ b/src/System.Net.Http.Formatting/Formatting/StringComparisonHelper.cs
@@ -23,7 +23,7 @@ public static bool IsDefined(StringComparison value)
{
return value == StringComparison.CurrentCulture ||
value == StringComparison.CurrentCultureIgnoreCase ||
-#if !NETFX_CORE
+#if !NETSTANDARD1_3
value == StringComparison.InvariantCulture ||
value == StringComparison.InvariantCultureIgnoreCase ||
#endif
diff --git a/src/System.Net.Http.Formatting/Formatting/StringWithQualityHeaderValueComparer.cs b/src/System.Net.Http.Formatting/Formatting/StringWithQualityHeaderValueComparer.cs
index c10caf277..6ded7c717 100644
--- a/src/System.Net.Http.Formatting/Formatting/StringWithQualityHeaderValueComparer.cs
+++ b/src/System.Net.Http.Formatting/Formatting/StringWithQualityHeaderValueComparer.cs
@@ -9,9 +9,9 @@ namespace System.Net.Http.Formatting
{
///
/// Implementation of that can compare content negotiation header fields
- /// based on their quality values (a.k.a q-values). This applies to values used in accept-charset,
- /// accept-encoding, accept-language and related header fields with similar syntax rules. See
- /// for a comparer for media type
+ /// based on their quality values (a.k.a q-values). This applies to values used in accept-charset,
+ /// accept-encoding, accept-language and related header fields with similar syntax rules. See
+ /// for a comparer for media type
/// q-values.
///
internal class StringWithQualityHeaderValueComparer : IComparer
diff --git a/src/System.Net.Http.Formatting/Formatting/XmlMediaTypeFormatter.cs b/src/System.Net.Http.Formatting/Formatting/XmlMediaTypeFormatter.cs
index bec831de8..76ee18f3d 100644
--- a/src/System.Net.Http.Formatting/Formatting/XmlMediaTypeFormatter.cs
+++ b/src/System.Net.Http.Formatting/Formatting/XmlMediaTypeFormatter.cs
@@ -1,9 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-#if !NETFX_CORE // In portable library we have our own implementation of Concurrent Dictionary which is in the internal namespace
using System.Collections.Concurrent;
-#endif
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
@@ -57,9 +55,7 @@ protected XmlMediaTypeFormatter(XmlMediaTypeFormatter formatter)
{
UseXmlSerializer = formatter.UseXmlSerializer;
WriterSettings = formatter.WriterSettings;
-#if !NETFX_CORE // MaxDepth is not supported in portable libraries
MaxDepth = formatter.MaxDepth;
-#endif
}
///
@@ -67,8 +63,8 @@ protected XmlMediaTypeFormatter(XmlMediaTypeFormatter formatter)
///
///
///
- /// The default media type does not have any charset parameter as
- /// the can be configured on a per
+ /// The default media type does not have any charset parameter as
+ /// the can be configured on a per
/// instance basis.
///
/// Because is mutable, the value
@@ -89,7 +85,7 @@ public static MediaTypeHeaderValue DefaultMediaType
public bool UseXmlSerializer { get; set; }
///
- /// Gets or sets a value indicating whether to indent elements when writing data.
+ /// Gets or sets a value indicating whether to indent elements when writing data.
///
public bool Indent
{
@@ -108,7 +104,6 @@ public bool Indent
///
public XmlWriterSettings WriterSettings { get; private set; }
-#if !NETFX_CORE // MaxDepth is not supported in portable libraries
///
/// Gets or sets the maximum depth allowed by this formatter.
///
@@ -128,7 +123,6 @@ public int MaxDepth
_readerQuotas.MaxDepth = value;
}
}
-#endif
///
/// Registers the to use to read or write
@@ -343,12 +337,14 @@ protected internal virtual XmlReader CreateXmlReader(Stream readStream, HttpCont
{
// Get the character encoding for the content
Encoding effectiveEncoding = SelectCharacterEncoding(content == null ? null : content.Headers);
-#if NETFX_CORE
- // Force a preamble into the stream, since CreateTextReader in WinRT only supports auto-detecting encoding.
- return XmlDictionaryReader.CreateTextReader(new ReadOnlyStreamWithEncodingPreamble(readStream, effectiveEncoding), _readerQuotas);
-#else
- return XmlDictionaryReader.CreateTextReader(new NonClosingDelegatingStream(readStream), effectiveEncoding, _readerQuotas, null);
-#endif
+
+ // DCS encodings are limited to UTF8, UTF16BE, and UTF16LE. Convert to UTF8 as we read.
+ Stream innerStream = string.Equals(effectiveEncoding.WebName, Utf8Encoding.WebName, StringComparison.OrdinalIgnoreCase) ?
+ new NonClosingDelegatingStream(readStream) :
+ new TranscodingStream(readStream, effectiveEncoding, Utf8Encoding, leaveOpen: true);
+
+ // XmlDictionaryReader will always dispose of innerStream when caller disposes of the reader.
+ return XmlDictionaryReader.CreateTextReader(innerStream, Utf8Encoding, _readerQuotas, onClose: null);
}
///
@@ -439,9 +435,20 @@ protected internal virtual object GetSerializer(Type type, object value, HttpCon
protected internal virtual XmlWriter CreateXmlWriter(Stream writeStream, HttpContent content)
{
Encoding effectiveEncoding = SelectCharacterEncoding(content != null ? content.Headers : null);
+ WritePreamble(writeStream, effectiveEncoding);
+
+ // DCS encodings are limited to UTF8, UTF16BE, and UTF16LE. Convert to UTF8 as we read.
+ Stream innerStream = string.Equals(effectiveEncoding.WebName, Utf8Encoding.WebName, StringComparison.OrdinalIgnoreCase) ?
+ writeStream :
+ new TranscodingStream(writeStream, effectiveEncoding, Utf8Encoding, leaveOpen: true);
+
XmlWriterSettings writerSettings = WriterSettings.Clone();
- writerSettings.Encoding = effectiveEncoding;
- return XmlWriter.Create(writeStream, writerSettings);
+ writerSettings.Encoding = Utf8Encoding;
+
+ // Have XmlWriter dispose of innerStream when caller disposes of the writer if using a TranscodingStream.
+ writerSettings.CloseOutput = writeStream != innerStream;
+
+ return XmlWriter.Create(innerStream, writerSettings);
}
///
@@ -504,6 +511,23 @@ public object InvokeGetSerializer(Type type, object value, HttpContent content)
private object CreateDefaultSerializer(Type type, bool throwOnError)
{
Contract.Assert(type != null, "type cannot be null.");
+
+#if NETSTANDARD1_3 // XsdDataContractExporter is not supported in netstandard1.3
+ if (!UseXmlSerializer)
+ {
+ if (throwOnError)
+ {
+ throw new PlatformNotSupportedException(Error.Format(
+ Properties.Resources.XmlMediaTypeFormatter_DCS_NotSupported,
+ nameof(UseXmlSerializer)));
+ }
+ else
+ {
+ return null;
+ }
+ }
+#endif
+
Exception exception = null;
object serializer = null;
@@ -515,12 +539,12 @@ private object CreateDefaultSerializer(Type type, bool throwOnError)
}
else
{
-#if !NETFX_CORE
- // REVIEW: Is there something comparable in WinRT?
+#if !NETSTANDARD1_3 // Unreachable when targeting netstandard1.3.
// Verify that type is a valid data contract by forcing the serializer to try to create a data contract
FormattingUtilities.XsdDataContractExporter.GetRootElementName(type);
-#endif
+
serializer = CreateDataContractSerializer(type);
+#endif
}
}
catch (Exception caught)
diff --git a/src/System.Net.Http.Formatting/FormattingUtilities.cs b/src/System.Net.Http.Formatting/FormattingUtilities.cs
index dd61bcf39..2d296a18c 100644
--- a/src/System.Net.Http.Formatting/FormattingUtilities.cs
+++ b/src/System.Net.Http.Formatting/FormattingUtilities.cs
@@ -18,7 +18,7 @@ namespace System.Net.Http
internal static class FormattingUtilities
{
// Supported date formats for input.
- private static readonly string[] dateFormats = new string[]
+ private static readonly string[] dateFormats = new string[]
{
// "r", // RFC 1123, required output format but too strict for input
"ddd, d MMM yyyy H:m:s 'GMT'", // RFC 1123 (r, except it allows both 1 and 01 for date and time)
@@ -30,8 +30,9 @@ internal static class FormattingUtilities
"d MMM yy H:m:s 'GMT'", // RFC 1123, no day-of-week, short year
"d MMM yy H:m:s", // RFC 1123, no day-of-week, short year, no zone
- "dddd, d'-'MMM'-'yy H:m:s 'GMT'", // RFC 850
+ "dddd, d'-'MMM'-'yy H:m:s 'GMT'", // RFC 850, short year
"dddd, d'-'MMM'-'yy H:m:s", // RFC 850 no zone
+ "ddd, d'-'MMM'-'yyyy H:m:s 'GMT'", // RFC 850, long year
"ddd MMM d H:m:s yyyy", // ANSI C's asctime() format
"ddd, d MMM yyyy H:m:s zzz", // RFC 5322
@@ -113,7 +114,7 @@ internal static class FormattingUtilities
///
public static readonly Type QueryableInterfaceGenericType = typeof(IQueryable<>);
-#if !NETFX_CORE // XsdDataContractExporter is not supported in portable libraries
+#if !NETSTANDARD1_3 // XsdDataContractExporter is not supported in netstandard1.3
///
/// An instance of .
///
@@ -133,7 +134,7 @@ public static bool IsJTokenType(Type type)
}
///
- /// Creates an empty instance. The only way is to get it from a dummy
+ /// Creates an empty instance. The only way is to get it from a dummy
/// instance.
///
/// The created instance.
@@ -165,9 +166,6 @@ public static HttpContentHeaders CreateEmptyContentHeaders()
///
public static XmlDictionaryReaderQuotas CreateDefaultReaderQuotas()
{
-#if NETFX_CORE // MaxDepth is a DOS mitigation. We don't support MaxDepth in portable libraries because it is strictly client side.
- return XmlDictionaryReaderQuotas.Max;
-#else
return new XmlDictionaryReaderQuotas()
{
MaxArrayLength = Int32.MaxValue,
@@ -176,7 +174,6 @@ public static XmlDictionaryReaderQuotas CreateDefaultReaderQuotas()
MaxNameTableCharCount = Int32.MaxValue,
MaxStringContentLength = Int32.MaxValue
};
-#endif
}
///
diff --git a/src/System.Net.Http.Formatting/GlobalSuppressions.cs b/src/System.Net.Http.Formatting/GlobalSuppressions.cs
index deefc5652..d815e56e6 100644
--- a/src/System.Net.Http.Formatting/GlobalSuppressions.cs
+++ b/src/System.Net.Http.Formatting/GlobalSuppressions.cs
@@ -6,3 +6,5 @@
[assembly: SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")]
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Net.Http.Headers", Justification = "We follow the layout of System.Net.Http.")]
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Net.Http.Handlers", Justification = "Handlers provide an extensibility hook which we want to keep in a separate namespace.")]
+// Some resources are specific to the netstandard1.3 assembly
+[assembly: SuppressMessage("Microsoft.Web.FxCop", "MW1000:UnusedResourceUsageRule", Justification = "There are a few unused resources due to missing netstandard1.3 features.")]
diff --git a/src/System.Net.Http.Formatting/Handlers/ProgressStream.cs b/src/System.Net.Http.Formatting/Handlers/ProgressStream.cs
index fe545f9a2..eff766608 100644
--- a/src/System.Net.Http.Formatting/Handlers/ProgressStream.cs
+++ b/src/System.Net.Http.Formatting/Handlers/ProgressStream.cs
@@ -10,7 +10,7 @@
namespace System.Net.Http.Handlers
{
///
- /// This implementation of registers how much data has been
+ /// This implementation of registers how much data has been
/// read (received) versus written (sent) for a particular HTTP operation. The implementation
/// is client side in that the total bytes to send is taken from the request and the total
/// bytes to read is taken from the response. In a server side scenario, it would be the
@@ -67,7 +67,8 @@ public override async Task ReadAsync(byte[] buffer, int offset, int count,
ReportBytesReceived(readCount, userState: null);
return readCount;
}
-#if !NETFX_CORE // BeginX and EndX are not supported on streams in portable libraries
+
+#if !NETSTANDARD1_3 // BeginX and EndX are not supported on Streams in netstandard1.3
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return InnerStream.BeginRead(buffer, offset, count, callback, state);
@@ -99,7 +100,7 @@ public override async Task WriteAsync(byte[] buffer, int offset, int count, Canc
ReportBytesSent(count, userState: null);
}
-#if !NETFX_CORE // BeginX and EndX are not supported on streams in portable libraries
+#if !NETSTANDARD1_3 // BeginX and EndX are not supported on Streams in netstandard1.3
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return new ProgressWriteAsyncResult(InnerStream, this, buffer, offset, count, callback, state);
diff --git a/src/System.Net.Http.Formatting/HttpContentFormDataExtensions.cs b/src/System.Net.Http.Formatting/HttpContentFormDataExtensions.cs
index 3ef7afc6a..72ebb40c7 100644
--- a/src/System.Net.Http.Formatting/HttpContentFormDataExtensions.cs
+++ b/src/System.Net.Http.Formatting/HttpContentFormDataExtensions.cs
@@ -12,7 +12,7 @@
namespace System.Net.Http
{
///
- /// Extension methods to allow HTML form URL-encoded data, also known as application/x-www-form-urlencoded,
+ /// Extension methods to allow HTML form URL-encoded data, also known as application/x-www-form-urlencoded,
/// to be read from instances.
///
[EditorBrowsable(EditorBrowsableState.Never)]
diff --git a/src/System.Net.Http.Formatting/HttpContentMessageExtensions.cs b/src/System.Net.Http.Formatting/HttpContentMessageExtensions.cs
index dd801b604..fdc518c54 100644
--- a/src/System.Net.Http.Formatting/HttpContentMessageExtensions.cs
+++ b/src/System.Net.Http.Formatting/HttpContentMessageExtensions.cs
@@ -126,7 +126,7 @@ public static Task ReadAsHttpRequestMessageAsync(this HttpCo
/// Read the as an .
///
/// The content to read.
- /// The URI scheme to use for the request URI (the
+ /// The URI scheme to use for the request URI (the
/// URI scheme is not actually part of the HTTP Request URI and so must be provided externally).
/// Size of the buffer.
/// A task object representing reading the content as an .
@@ -140,7 +140,7 @@ public static Task ReadAsHttpRequestMessageAsync(this HttpCo
/// Read the as an .
///
/// The content to read.
- /// The URI scheme to use for the request URI (the
+ /// The URI scheme to use for the request URI (the
/// URI scheme is not actually part of the HTTP Request URI and so must be provided externally).
/// Size of the buffer.
/// The token to monitor for cancellation requests.
@@ -157,7 +157,7 @@ public static Task ReadAsHttpRequestMessageAsync(this HttpCo
/// Read the as an .
///
/// The content to read.
- /// The URI scheme to use for the request URI (the
+ /// The URI scheme to use for the request URI (the
/// URI scheme is not actually part of the HTTP Request URI and so must be provided externally).
/// Size of the buffer.
/// The max length of the HTTP header.
@@ -174,7 +174,7 @@ public static Task ReadAsHttpRequestMessageAsync(this HttpCo
/// Read the as an .
///
/// The content to read.
- /// The URI scheme to use for the request URI (the
+ /// The URI scheme to use for the request URI (the
/// URI scheme is not actually part of the HTTP Request URI and so must be provided externally).
/// Size of the buffer.
/// The max length of the HTTP header.
@@ -223,7 +223,7 @@ private static async Task ReadAsHttpRequestMessageAsyncCore(
HttpUnsortedRequest httpRequest = new HttpUnsortedRequest();
HttpRequestHeaderParser parser = new HttpRequestHeaderParser(httpRequest,
- HttpRequestHeaderParser.DefaultMaxRequestLineSize, maxHeaderSize);
+ Math.Max(HttpRequestHeaderParser.DefaultMaxRequestLineSize, maxHeaderSize), maxHeaderSize);
ParserState parseStatus;
byte[] buffer = new byte[bufferSize];
@@ -451,7 +451,7 @@ private static HttpContent CreateHeaderFields(HttpHeaders source, HttpHeaders de
Contract.Assert(destination != null, "destination headers cannot be null");
Contract.Assert(contentStream != null, "contentStream must be non null");
HttpContentHeaders contentHeaders = null;
- HttpContent content = null;
+ HttpContent content;
// Set the header fields
foreach (KeyValuePair> header in source)
@@ -467,7 +467,8 @@ private static HttpContent CreateHeaderFields(HttpHeaders source, HttpHeaders de
}
}
- // If we have content headers then create an HttpContent for this Response
+ // If we have content headers then create an HttpContent for this request or response. Otherwise,
+ // provide a HttpContent instance to overwrite the null or EmptyContent value.
if (contentHeaders != null)
{
// Need to rewind the input stream to be at the position right after the HTTP header
@@ -481,6 +482,10 @@ private static HttpContent CreateHeaderFields(HttpHeaders source, HttpHeaders de
content = new StreamContent(contentStream);
contentHeaders.CopyTo(content.Headers);
}
+ else
+ {
+ content = new StreamContent(Stream.Null);
+ }
return content;
}
diff --git a/src/System.Net.Http.Formatting/HttpContentMultipartExtensions.cs b/src/System.Net.Http.Formatting/HttpContentMultipartExtensions.cs
index dce8ce8fa..e9671d5b2 100644
--- a/src/System.Net.Http.Formatting/HttpContentMultipartExtensions.cs
+++ b/src/System.Net.Http.Formatting/HttpContentMultipartExtensions.cs
@@ -41,9 +41,9 @@ public static bool IsMimeMultipartContent(this HttpContent content)
}
///
- /// Determines whether the specified content is MIME multipart content with the
+ /// Determines whether the specified content is MIME multipart content with the
/// specified subtype. For example, the subtype mixed would match content
- /// with a content type of multipart/mixed.
+ /// with a content type of multipart/mixed.
///
/// The content.
/// The MIME multipart subtype to match.
@@ -91,7 +91,7 @@ public static Task ReadAsMultipartAsync(this Http
///
/// Reads all body parts within a MIME multipart message using the provided instance
- /// to determine where the contents of each body part is written.
+ /// to determine where the contents of each body part is written.
///
/// The with which to process the data.
/// An existing instance to use for the object's content.
@@ -104,7 +104,7 @@ public static Task ReadAsMultipartAsync(this HttpContent content, T stream
///
/// Reads all body parts within a MIME multipart message using the provided instance
- /// to determine where the contents of each body part is written.
+ /// to determine where the contents of each body part is written.
///
/// The with which to process the data.
/// An existing instance to use for the object's content.
diff --git a/src/System.Net.Http.Formatting/HttpMessageContent.cs b/src/System.Net.Http.Formatting/HttpMessageContent.cs
index 1d90b16d8..c182d40c8 100644
--- a/src/System.Net.Http.Formatting/HttpMessageContent.cs
+++ b/src/System.Net.Http.Formatting/HttpMessageContent.cs
@@ -205,6 +205,7 @@ protected override async Task SerializeToStreamAsync(Stream stream, TransportCon
protected override bool TryComputeLength(out long length)
{
// We have four states we could be in:
+ // 0. We have content and it knows its ContentLength.
// 1. We have content, but the task is still running or finished without success
// 2. We have content, the task has finished successfully, and the stream came back as a null or non-seekable
// 3. We have content, the task has finished successfully, and the stream is seekable, so we know its length
@@ -214,11 +215,13 @@ protected override bool TryComputeLength(out long length)
// For #3, we return true & the size of our headers + the content length
// For #4, we return true & the size of our headers
- bool hasContent = _streamTask.Value != null;
length = 0;
- // Cases #1, #2, #3
- if (hasContent)
+ if (Content?.Headers.ContentLength is not null)
+ {
+ length = (long)Content.Headers.ContentLength; // Case #0
+ }
+ else if (_streamTask.Value is not null)
{
Stream readStream;
if (!_streamTask.Value.TryGetResult(out readStream) // Case #1
@@ -356,12 +359,21 @@ private byte[] SerializeHeader()
private void ValidateStreamForReading(Stream stream)
{
+ // Stream is null case should be an extreme, incredibly unlikely corner case. Every HttpContent from
+ // the framework (see dotnet/runtime or .NET Framework reference source) provides a non-null Stream
+ // in the ReadAsStreamAsync task's return value. Likely need a poorly-designed derived HttpContent
+ // to hit this. Mostly ignoring the fact this message doesn't make much sense for the case.
+ if (stream is null || !stream.CanRead)
+ {
+ throw Error.NotSupported(Properties.Resources.NotSupported_UnreadableStream);
+ }
+
// If the content needs to be written to a target stream a 2nd time, then the stream must support
- // seeking (e.g. a FileStream), otherwise the stream can't be copied a second time to a target
+ // seeking (e.g. a FileStream), otherwise the stream can't be copied a second time to a target
// stream (e.g. a NetworkStream).
if (_contentConsumed)
{
- if (stream != null && stream.CanRead)
+ if (stream.CanSeek)
{
stream.Position = 0;
}
diff --git a/src/System.Net.Http.Formatting/HttpRequestMessageExtensions.cs b/src/System.Net.Http.Formatting/HttpRequestMessageExtensions.cs
index a503f148b..b2e568eaa 100644
--- a/src/System.Net.Http.Formatting/HttpRequestMessageExtensions.cs
+++ b/src/System.Net.Http.Formatting/HttpRequestMessageExtensions.cs
@@ -3,6 +3,7 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
+using System.IO;
using System.Web.Http;
namespace System.Net.Http
@@ -29,6 +30,7 @@ public static HttpResponseMessage CreateResponse(this HttpRequestMessage request
return new HttpResponseMessage
{
+ Content = new StreamContent(Stream.Null),
StatusCode = statusCode,
RequestMessage = request
};
@@ -49,6 +51,7 @@ public static HttpResponseMessage CreateResponse(this HttpRequestMessage request
return new HttpResponseMessage
{
+ Content = new StreamContent(Stream.Null),
RequestMessage = request
};
}
diff --git a/src/System.Net.Http.Formatting/Internal/ByteRangeStream.cs b/src/System.Net.Http.Formatting/Internal/ByteRangeStream.cs
index b519144bc..a4fce9a3f 100644
--- a/src/System.Net.Http.Formatting/Internal/ByteRangeStream.cs
+++ b/src/System.Net.Http.Formatting/Internal/ByteRangeStream.cs
@@ -3,12 +3,14 @@
using System.IO;
using System.Net.Http.Headers;
+using System.Threading;
+using System.Threading.Tasks;
using System.Web.Http;
namespace System.Net.Http.Internal
{
///
- /// Stream which only exposes a read-only only range view of an
+ /// Stream which only exposes a read-only only range view of an
/// inner stream.
///
internal class ByteRangeStream : DelegatingStream
@@ -16,7 +18,7 @@ internal class ByteRangeStream : DelegatingStream
// The offset stream position at which the range starts.
private readonly long _lowerbounds;
- // The total number of bytes within the range.
+ // The total number of bytes within the range.
private readonly long _totalCount;
// The current number of bytes read into the range
@@ -92,16 +94,40 @@ public override bool CanWrite
get { return false; }
}
+ public override long Position
+ {
+ get
+ {
+ return _currentCount;
+ }
+ set
+ {
+ if (value < 0)
+ {
+ throw Error.ArgumentMustBeGreaterThanOrEqualTo("value", value, 0L);
+ }
+
+ _currentCount = value;
+ }
+ }
+
+#if !NETSTANDARD1_3 // BeginX and EndX are not supported on Streams in netstandard1.3
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return base.BeginRead(buffer, offset, PrepareStreamForRangeRead(count), callback, state);
}
+#endif
public override int Read(byte[] buffer, int offset, int count)
{
return base.Read(buffer, offset, PrepareStreamForRangeRead(count));
}
+ public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
+ {
+ return base.ReadAsync(buffer, offset, PrepareStreamForRangeRead(count), cancellationToken);
+ }
+
public override int ReadByte()
{
int effectiveCount = PrepareStreamForRangeRead(1);
@@ -109,9 +135,35 @@ public override int ReadByte()
{
return -1;
}
+
return base.ReadByte();
}
+ public override long Seek(long offset, SeekOrigin origin)
+ {
+ switch (origin)
+ {
+ case SeekOrigin.Begin:
+ _currentCount = offset;
+ break;
+ case SeekOrigin.Current:
+ _currentCount = _currentCount + offset;
+ break;
+ case SeekOrigin.End:
+ _currentCount = _totalCount + offset;
+ break;
+ default:
+ throw Error.InvalidEnumArgument("origin", (int)origin, typeof(SeekOrigin));
+ }
+
+ if (_currentCount < 0L)
+ {
+ throw new IOException(Properties.Resources.ByteRangeStreamInvalidOffset);
+ }
+
+ return _currentCount;
+ }
+
public override void SetLength(long value)
{
throw Error.NotSupported(Properties.Resources.ByteRangeStreamReadOnly);
@@ -122,6 +174,7 @@ public override void Write(byte[] buffer, int offset, int count)
throw Error.NotSupported(Properties.Resources.ByteRangeStreamReadOnly);
}
+#if !NETSTANDARD1_3 // BeginX and EndX are not supported on Streams in netstandard1.3
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
throw Error.NotSupported(Properties.Resources.ByteRangeStreamReadOnly);
@@ -131,6 +184,12 @@ public override void EndWrite(IAsyncResult asyncResult)
{
throw Error.NotSupported(Properties.Resources.ByteRangeStreamReadOnly);
}
+#endif
+
+ public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
+ {
+ throw Error.NotSupported(Properties.Resources.ByteRangeStreamReadOnly);
+ }
public override void WriteByte(byte value)
{
@@ -138,27 +197,38 @@ public override void WriteByte(byte value)
}
///
- /// Gets the
+ /// Gets the correct count for the next read operation.
///
/// The count requested to be read by the caller.
/// The remaining bytes to read within the range defined for this stream.
private int PrepareStreamForRangeRead(int count)
{
- long effectiveCount = Math.Min(count, _totalCount - _currentCount);
- if (effectiveCount > 0)
+ // A negative count causes base.Raad* methods to throw an ArgumentOutOfRangeException.
+ if (count <= 0)
{
- // Check if we should update the stream position
- long position = InnerStream.Position;
- if (_lowerbounds + _currentCount != position)
- {
- InnerStream.Position = _lowerbounds + _currentCount;
- }
+ return count;
+ }
- // Update current number of bytes read
- _currentCount += effectiveCount;
+ // Reading past the end simply does nothing.
+ if (_currentCount >= _totalCount)
+ {
+ return 0;
}
- // Effective count can never be bigger than int
+ long effectiveCount = Math.Min(count, _totalCount - _currentCount);
+
+ // Check if we should update the inner stream's position.
+ var newPosition = _lowerbounds + _currentCount;
+ var position = InnerStream.Position;
+ if (newPosition != position)
+ {
+ InnerStream.Position = newPosition;
+ }
+
+ // Update current number of bytes read.
+ _currentCount += effectiveCount;
+
+ // Effective count can never be bigger than int.
return (int)effectiveCount;
}
}
diff --git a/src/System.Net.Http.Formatting/Internal/DelegatingStream.cs b/src/System.Net.Http.Formatting/Internal/DelegatingStream.cs
index 9547b6704..0e713fdfd 100644
--- a/src/System.Net.Http.Formatting/Internal/DelegatingStream.cs
+++ b/src/System.Net.Http.Formatting/Internal/DelegatingStream.cs
@@ -9,12 +9,12 @@
namespace System.Net.Http.Internal
{
///
- /// Stream that delegates to inner stream.
+ /// Stream that delegates to inner stream.
/// This is taken from System.Net.Http
///
internal abstract class DelegatingStream : Stream
{
- private Stream _innerStream;
+ private readonly Stream _innerStream;
protected DelegatingStream(Stream innerStream)
{
@@ -97,7 +97,7 @@ public override Task ReadAsync(byte[] buffer, int offset, int count, Cancel
return _innerStream.ReadAsync(buffer, offset, count, cancellationToken);
}
-#if !NETFX_CORE // BeginX and EndX not supported on Streams in portable libraries
+#if !NETSTANDARD1_3 // BeginX and EndX not supported on Streams in netstandard1.3
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return _innerStream.BeginRead(buffer, offset, count, callback, state);
@@ -119,11 +119,6 @@ public override void Flush()
_innerStream.Flush();
}
- public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
- {
- return _innerStream.CopyToAsync(destination, bufferSize, cancellationToken);
- }
-
public override Task FlushAsync(CancellationToken cancellationToken)
{
return _innerStream.FlushAsync(cancellationToken);
@@ -144,7 +139,7 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
return _innerStream.WriteAsync(buffer, offset, count, cancellationToken);
}
-#if !NETFX_CORE // BeginX and EndX not supported on Streams in portable libraries
+#if !NETSTANDARD1_3 // BeginX and EndX not supported on Streams in netstandard1.3
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
return _innerStream.BeginWrite(buffer, offset, count, callback, state);
diff --git a/src/System.Net.Http.Formatting/Internal/HttpValueCollection.cs b/src/System.Net.Http.Formatting/Internal/HttpValueCollection.cs
index 1af77650e..082b33319 100644
--- a/src/System.Net.Http.Formatting/Internal/HttpValueCollection.cs
+++ b/src/System.Net.Http.Formatting/Internal/HttpValueCollection.cs
@@ -1,14 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-#if NETFX_CORE
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics.Contracts;
-using System.Linq;
-using System.Text;
-using System.Web.Http;
-#else
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics.Contracts;
@@ -17,45 +9,29 @@
using System.Runtime.Serialization;
using System.Text;
using System.Web.Http;
-#endif
-#if NETFX_CORE
-namespace System.Net.Http.Formatting
-#else
namespace System.Net.Http.Formatting.Internal
-#endif
{
///
/// NameValueCollection to represent form data and to generate form data output.
///
-#if NETFX_CORE
- public class HttpValueCollection : IEnumerable>
-#else
+#if !NETSTANDARD1_3 // NameValueCollection is not serializable in netstandard1.3.
[Serializable]
- internal class HttpValueCollection : NameValueCollection
#endif
+ internal class HttpValueCollection : NameValueCollection
{
-#if NETFX_CORE
- internal readonly HashSet Names = new HashSet(StringComparer.OrdinalIgnoreCase);
- internal readonly List> List = new List>();
-
- ///
- /// Creates a new instance
- ///
- public HttpValueCollection()
- {
- }
-#else
+#if !NETSTANDARD1_3 // NameValueCollection is not serializable in netstandard1.3.
protected HttpValueCollection(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
+#endif
private HttpValueCollection()
: base(StringComparer.OrdinalIgnoreCase) // case-insensitive keys
{
}
-#endif
+
// Use a builder function instead of a ctor to avoid virtual calls from the ctor.
// The above condition is only important in the Full .NET fx implementation.
internal static HttpValueCollection Create()
@@ -75,9 +51,8 @@ internal static HttpValueCollection Create(IEnumerable
/// The name to be added as a case insensitive string.
/// The value to be added.
- public
-#if !NETFX_CORE
- override
-#endif
- void Add(string name, string value)
+ public override void Add(string name, string value)
{
ThrowIfMaxHttpCollectionKeysExceeded(Count);
name = name ?? String.Empty;
value = value ?? String.Empty;
-#if NETFX_CORE
- Names.Add(name);
- List.Add(new KeyValuePair(name, value));
-#else
base.Add(name, value);
-#endif
}
///
@@ -131,11 +97,7 @@ private string ToString(bool urlEncode)
StringBuilder builder = new StringBuilder();
bool first = true;
-#if NETFX_CORE
- foreach (string name in Names)
-#else
foreach (string name in this)
-#endif
{
string[] values = GetValues(name);
if (values == null || values.Length == 0)
@@ -157,10 +119,10 @@ private string ToString(bool urlEncode)
private static bool AppendNameValuePair(StringBuilder builder, bool first, bool urlEncode, string name, string value)
{
string effectiveName = name ?? String.Empty;
- string encodedName = urlEncode ? UriQueryUtility.UrlEncode(effectiveName) : effectiveName;
+ string encodedName = urlEncode ? WebUtility.UrlEncode(effectiveName) : effectiveName;
string effectiveValue = value ?? String.Empty;
- string encodedValue = urlEncode ? UriQueryUtility.UrlEncode(effectiveValue) : effectiveValue;
+ string encodedValue = urlEncode ? WebUtility.UrlEncode(effectiveValue) : effectiveValue;
if (first)
{
@@ -179,104 +141,5 @@ private static bool AppendNameValuePair(StringBuilder builder, bool first, bool
}
return first;
}
-
-#if NETFX_CORE
- ///
- /// Gets the values associated with the specified name
- /// combined into one comma-separated list.
- ///
- /// The name of the entry that contains the values to get. The name can be null.
- /// A that contains a comma-separated list of url encoded values associated
- /// with the specified name if found; otherwise, null. The values are Url encoded.
- public string this[string name]
- {
- get
- {
- return Get(name);
- }
- }
-
- ///
- /// Gets the number of names in the collection.
- ///
- public int Count
- {
- get
- {
- return Names.Count;
- }
- }
-
- ///
- /// Gets the values associated with the specified name
- /// combined into one comma-separated list.
- ///
- /// The name of the entry that contains the values to get. The name can be null.
- ///
- /// A that contains a comma-separated list of url encoded values associated
- /// with the specified name if found; otherwise, null. The values are Url encoded.
- ///
- public string Get(string name)
- {
- name = name ?? String.Empty;
-
- if (!Names.Contains(name))
- {
- return null;
- }
-
- List values = GetValuesInternal(name);
- Contract.Assert(values != null && values.Count > 0);
-
- return String.Join(",", values);
- }
-
- ///
- /// Gets the values associated with the specified name.
- ///
- /// The
- /// A that contains url encoded values associated with the name, or null if the name does not exist.
- public string[] GetValues(string name)
- {
- name = name ?? String.Empty;
-
- if (!Names.Contains(name))
- {
- return null;
- }
-
- return GetValuesInternal(name).ToArray();
- }
-
- // call this when only when there are values available.
- private List GetValuesInternal(string name)
- {
- List values = new List();
-
- for (int i = 0; i < List.Count; i++)
- {
- KeyValuePair kvp = List[i];
-
- if (String.Equals(kvp.Key, name, StringComparison.OrdinalIgnoreCase))
- {
- values.Add(kvp.Value);
- }
- }
-
- return values;
- }
-
- ///
- public IEnumerator> GetEnumerator()
- {
- return List.GetEnumerator();
- }
-
- ///
- IEnumerator IEnumerable.GetEnumerator()
- {
- return List.GetEnumerator();
- }
-#endif
}
}
diff --git a/src/System.Net.Http.Formatting/Internal/NonClosingDelegatingStream.cs b/src/System.Net.Http.Formatting/Internal/NonClosingDelegatingStream.cs
index 5af2385b0..1d7599654 100644
--- a/src/System.Net.Http.Formatting/Internal/NonClosingDelegatingStream.cs
+++ b/src/System.Net.Http.Formatting/Internal/NonClosingDelegatingStream.cs
@@ -8,8 +8,8 @@ namespace System.Net.Http.Internal
///
/// Stream that doesn't close the inner stream when closed. This is to work around a limitation
/// in the insisting of closing the inner stream.
- /// The regular does allow for not closing the inner stream but that
- /// doesn't have the quota that we need for security reasons. Implementations of
+ /// The regular does allow for not closing the inner stream but that
+ /// doesn't have the quota that we need for security reasons. Implementations of
///
/// should not close the input stream when reading or writing so hence this workaround.
///
@@ -20,8 +20,14 @@ public NonClosingDelegatingStream(Stream innerStream)
{
}
+#if NETSTANDARD1_3
+ protected override void Dispose(bool disposing)
+ {
+ }
+#else
public override void Close()
{
}
+#endif
}
}
diff --git a/src/System.Net.Http.Formatting/Internal/NullableAttributes.cs b/src/System.Net.Http.Formatting/Internal/NullableAttributes.cs
new file mode 100644
index 000000000..2344a2994
--- /dev/null
+++ b/src/System.Net.Http.Formatting/Internal/NullableAttributes.cs
@@ -0,0 +1,198 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+// From https://github.com/dotnet/runtime/blob/88868b7a781f4e5b9037b8721f30440207a7aa42/src/tools/illink/src/ILLink.RoslynAnalyzer/NullableAttributes.cs
+
+namespace System.Diagnostics.CodeAnalysis
+{
+#if !NETSTANDARD2_1
+ /// Specifies that null is allowed as an input even if the corresponding type disallows it.
+ [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class AllowNullAttribute : Attribute { }
+
+ /// Specifies that null is disallowed as an input even if the corresponding type allows it.
+ [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class DisallowNullAttribute : Attribute { }
+
+ /// Specifies that an output may be null even if the corresponding type disallows it.
+ [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class MaybeNullAttribute : Attribute { }
+
+ /// Specifies that an output will not be null even if the corresponding type allows it. Specifies that an input argument was not null when the call returns.
+ [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)]
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class NotNullAttribute : Attribute { }
+
+ /// Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it.
+ [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class MaybeNullWhenAttribute : Attribute
+ {
+ /// Initializes the attribute with the specified return value condition.
+ ///
+ /// The return value condition. If the method returns this value, the associated parameter may be null.
+ ///
+ public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
+
+ /// Gets the return value condition.
+ public bool ReturnValue { get; }
+ }
+
+ /// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it.
+ [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class NotNullWhenAttribute : Attribute
+ {
+ /// Initializes the attribute with the specified return value condition.
+ ///
+ /// The return value condition. If the method returns this value, the associated parameter will not be null.
+ ///
+ public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue;
+
+ /// Gets the return value condition.
+ public bool ReturnValue { get; }
+ }
+
+ /// Specifies that the output will be non-null if the named parameter is non-null.
+ [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class NotNullIfNotNullAttribute : Attribute
+ {
+ /// Initializes the attribute with the associated parameter name.
+ ///
+ /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null.
+ ///
+ public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName;
+
+ /// Gets the associated parameter name.
+ public string ParameterName { get; }
+ }
+
+ /// Applied to a method that will never return under any circumstance.
+ [AttributeUsage(AttributeTargets.Method, Inherited = false)]
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class DoesNotReturnAttribute : Attribute { }
+
+ /// Specifies that the method will not return if the associated Boolean parameter is passed the specified value.
+ [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class DoesNotReturnIfAttribute : Attribute
+ {
+ /// Initializes the attribute with the specified parameter value.
+ ///
+ /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to
+ /// the associated parameter matches this value.
+ ///
+ public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue;
+
+ /// Gets the condition parameter value.
+ public bool ParameterValue { get; }
+ }
+#endif
+
+ /// Specifies that the method or property will ensure that the listed field and property members have not-null values.
+ [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class MemberNotNullAttribute : Attribute
+ {
+ /// Initializes the attribute with a field or property member.
+ ///
+ /// The field or property member that is promised to be not-null.
+ ///
+ public MemberNotNullAttribute(string member) => Members = new[] { member };
+
+ /// Initializes the attribute with the list of field and property members.
+ ///
+ /// The list of field and property members that are promised to be not-null.
+ ///
+ public MemberNotNullAttribute(params string[] members) => Members = members;
+
+ /// Gets field or property member names.
+ public string[] Members { get; }
+ }
+
+ /// Specifies that the method or property will ensure that the listed field and property members have not-null values when returning with the specified return value condition.
+ [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class MemberNotNullWhenAttribute : Attribute
+ {
+ /// Initializes the attribute with the specified return value condition and a field or property member.
+ ///
+ /// The return value condition. If the method returns this value, the associated parameter will not be null.
+ ///
+ ///
+ /// The field or property member that is promised to be not-null.
+ ///
+ public MemberNotNullWhenAttribute(bool returnValue, string member)
+ {
+ ReturnValue = returnValue;
+ Members = new[] { member };
+ }
+
+ /// Initializes the attribute with the specified return value condition and list of field and property members.
+ ///
+ /// The return value condition. If the method returns this value, the associated parameter will not be null.
+ ///
+ ///
+ /// The list of field and property members that are promised to be not-null.
+ ///
+ public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
+ {
+ ReturnValue = returnValue;
+ Members = members;
+ }
+
+ /// Gets the return value condition.
+ public bool ReturnValue { get; }
+
+ /// Gets field or property member names.
+ public string[] Members { get; }
+ }
+}
diff --git a/src/System.Net.Http.Formatting/Internal/ReadOnlyStreamWithEncodingPreamble.cs b/src/System.Net.Http.Formatting/Internal/ReadOnlyStreamWithEncodingPreamble.cs
deleted file mode 100644
index 923e4bd37..000000000
--- a/src/System.Net.Http.Formatting/Internal/ReadOnlyStreamWithEncodingPreamble.cs
+++ /dev/null
@@ -1,175 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.Diagnostics.Contracts;
-using System.IO;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.Net.Http.Internal
-{
- ///
- /// This implements a read-only, forward-only stream around another readable stream, to ensure
- /// that there is an appropriate encoding preamble in the stream.
- ///
- internal class ReadOnlyStreamWithEncodingPreamble : Stream
- {
- private static Task _cancelledTask = GetCancelledTask();
- private Stream _innerStream;
- private ArraySegment _remainingBytes;
-
- public ReadOnlyStreamWithEncodingPreamble(Stream innerStream, Encoding encoding)
- {
- Contract.Assert(innerStream != null);
- Contract.Assert(innerStream.CanRead);
- Contract.Assert(encoding != null);
-
- _innerStream = innerStream;
-
- // Determine whether we even have a preamble to be concerned about
- byte[] preamble = encoding.GetPreamble();
- int preambleLength = preamble.Length;
- if (preambleLength <= 0)
- {
- return;
- }
-
- // Create a double sized buffer, and read enough bytes from the stream to know
- // whether we have a preamble present already or not.
- int finalBufferLength = preambleLength * 2;
- byte[] finalBuffer = new byte[finalBufferLength];
- int finalCount = preambleLength;
- preamble.CopyTo(finalBuffer, 0);
-
- // Read the first bytes of the stream and see if they already contain a preamble
- for (; finalCount < finalBufferLength; finalCount++)
- {
- int b = innerStream.ReadByte();
- if (b == -1)
- {
- break;
- }
- finalBuffer[finalCount] = (byte)b;
- }
-
- // Did we read enough bytes to do the comparison?
- if (finalCount == finalBufferLength)
- {
- bool foundPreamble = true;
- for (int idx = 0; idx < preambleLength; idx++)
- {
- if (finalBuffer[idx] != finalBuffer[idx + preambleLength])
- {
- foundPreamble = false;
- break;
- }
- }
-
- // If we found the preamble, then just exclude it from the data that we return
- if (foundPreamble)
- {
- finalCount = preambleLength;
- }
- }
-
- _remainingBytes = new ArraySegment(finalBuffer, 0, finalCount);
- }
-
- public override bool CanRead
- {
- get { return true; }
- }
-
- public override bool CanSeek
- {
- get { return false; }
- }
-
- public override bool CanWrite
- {
- get { return false; }
- }
-
- public override long Length
- {
- get { throw new NotImplementedException(); }
- }
-
- public override long Position
- {
- get { throw new NotImplementedException(); }
- set { throw new NotImplementedException(); }
- }
-
- public override void Flush()
- {
- throw new NotImplementedException();
- }
-
- private static Task GetCancelledTask()
- {
- var tcs = new TaskCompletionSource();
- tcs.SetCanceled();
- return tcs.Task;
- }
-
- public override int Read(byte[] buffer, int offset, int count)
- {
- byte[] remainingArray = _remainingBytes.Array;
- if (remainingArray == null)
- {
- return _innerStream.Read(buffer, offset, count);
- }
-
- int remainingCount = _remainingBytes.Count;
- int remainingOffset = _remainingBytes.Offset;
- int result = Math.Min(count, remainingCount);
-
- for (int idx = 0; idx < result; ++idx)
- {
- buffer[offset + idx] = remainingArray[remainingOffset + idx];
- }
-
- if (result == remainingCount)
- {
- _remainingBytes = default(ArraySegment);
- }
- else
- {
- _remainingBytes = new ArraySegment(remainingArray, remainingOffset + result, remainingCount - result);
- }
-
- return result;
- }
-
- public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- if (_remainingBytes.Array == null)
- {
- return _innerStream.ReadAsync(buffer, offset, count, cancellationToken);
- }
- if (cancellationToken.IsCancellationRequested)
- {
- return _cancelledTask;
- }
-
- return Task.FromResult(Read(buffer, offset, count));
- }
-
- public override long Seek(long offset, SeekOrigin origin)
- {
- throw new NotImplementedException();
- }
-
- public override void SetLength(long value)
- {
- throw new NotImplementedException();
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- throw new NotImplementedException();
- }
- }
-}
diff --git a/src/System.Net.Http.Formatting/Internal/TranscodingStream.cs b/src/System.Net.Http.Formatting/Internal/TranscodingStream.cs
new file mode 100644
index 000000000..f279b73ad
--- /dev/null
+++ b/src/System.Net.Http.Formatting/Internal/TranscodingStream.cs
@@ -0,0 +1,828 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+// From https://github.com/dotnet/runtime/blob/88868b7a781f4e5b9037b8721f30440207a7aa42/src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs
+
+using System.Buffers;
+using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
+using System.IO;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Web.Http;
+using Properties = System.Net.Http.Properties;
+
+#nullable enable
+
+namespace System.Text
+{
+ internal sealed class TranscodingStream : Stream
+ {
+ private const int DefaultReadByteBufferSize = 4 * 1024; // lifted from StreamReader.cs (FileStream)
+
+ // We optimistically assume 1 byte ~ 1 char during transcoding. This is a good rule of thumb
+ // but isn't always appropriate: transcoding between single-byte and multi-byte encodings
+ // will violate this, as will any invalid data fixups performed by the transcoder itself.
+ // To account for these unknowns we have a minimum scratch buffer size we use during the
+ // transcoding process. This should be generous enough to account for even the largest
+ // fallback mechanism we're likely to see in the real world.
+
+ private const int MinWriteRentedArraySize = 4 * 1024;
+ private const int MaxWriteRentedArraySize = 1024 * 1024;
+
+ private static readonly byte[] EmptyByteBuffer = new byte[0];
+ private static readonly char[] EmptyCharBuffer = new char[0];
+
+ private readonly Encoding _innerEncoding;
+ private readonly Encoding _thisEncoding;
+ private Stream _innerStream; // null if the wrapper has been disposed
+ private readonly bool _leaveOpen;
+ private readonly byte[] _singleByteBuffer = new byte[1];
+
+ /*
+ * Fields used for writing bytes [this] -> chars -> bytes [inner]
+ * Lazily initialized the first time we need to write
+ */
+
+ private Encoder? _innerEncoder;
+ private Decoder? _thisDecoder;
+
+ /*
+ * Fields used for reading bytes [inner] -> chars -> bytes [this]
+ * Lazily initialized the first time we need to read
+ */
+
+ private Encoder? _thisEncoder;
+ private Decoder? _innerDecoder;
+ private int _readCharBufferMaxSize; // the maximum number of characters _innerDecoder.ReadChars can return
+ private byte[]? _readBuffer; // contains the data that Read() should return
+ private int _readBufferOffset;
+ private int _readBufferCount;
+
+ internal TranscodingStream(Stream innerStream, Encoding innerEncoding, Encoding thisEncoding, bool leaveOpen = false)
+ {
+ _innerStream = innerStream ?? throw Error.ArgumentNull(nameof(innerStream));
+ _leaveOpen = leaveOpen;
+
+ _innerEncoding = innerEncoding ?? throw Error.ArgumentNull(nameof(innerEncoding));
+ _thisEncoding = thisEncoding ?? throw Error.ArgumentNull(nameof(thisEncoding));
+ }
+
+ /*
+ * Most CanXyz methods delegate to the inner stream, returning false
+ * if this instance has been disposed. CanSeek is always false.
+ */
+
+ public override bool CanRead => _innerStream?.CanRead ?? false;
+
+ public override bool CanSeek => false;
+
+ public override bool CanWrite => _innerStream?.CanWrite ?? false;
+
+ public override long Length => throw Error.NotSupported(Properties.Resources.NotSupported_UnseekableStream);
+
+ public override long Position
+ {
+ get => throw Error.NotSupported(Properties.Resources.NotSupported_UnseekableStream);
+ set => throw Error.NotSupported(Properties.Resources.NotSupported_UnseekableStream);
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ Debug.Assert(disposing, "This type isn't finalizable.");
+ base.Dispose(disposing);
+
+ if (_innerStream is null)
+ {
+ return; // dispose called multiple times, ignore
+ }
+
+ // First, flush any pending data to the inner stream.
+
+ ArraySegment pendingData = FinalFlushWriteBuffers();
+ if (pendingData.Count != 0)
+ {
+ _innerStream.Write(pendingData.Array, pendingData.Offset, pendingData.Count);
+ }
+
+ // Mark our object as disposed
+
+ Stream innerStream = _innerStream;
+ _innerStream = null!;
+
+ // And dispose the inner stream if needed
+
+ if (!_leaveOpen)
+ {
+ innerStream.Dispose();
+ }
+ }
+
+#if NETCOREAPP3_1_OR_GREATER || NETSTANDARD2_1
+ public override ValueTask DisposeAsync()
+ {
+ if (_innerStream is null)
+ {
+ return default; // dispose called multiple times, ignore
+ }
+
+ // First, get any pending data destined for the inner stream.
+
+ ArraySegment pendingData = FinalFlushWriteBuffers();
+
+ if (pendingData.Count == 0)
+ {
+ // Fast path: just dispose of the object graph.
+ // No need to write anything to the stream first.
+
+ Stream innerStream = _innerStream;
+ _innerStream = null!;
+
+ return (_leaveOpen)
+ ? default /* no work to do */
+ : innerStream.DisposeAsync();
+ }
+
+ // Slower path; need to perform an async write followed by an async dispose.
+
+ return DisposeAsyncCore(pendingData);
+ async ValueTask DisposeAsyncCore(ArraySegment pendingData)
+ {
+ Debug.Assert(pendingData.Count != 0);
+
+ Stream innerStream = _innerStream;
+ _innerStream = null!;
+
+ await innerStream.WriteAsync(pendingData.AsMemory()).ConfigureAwait(false);
+
+ if (!_leaveOpen)
+ {
+ await innerStream.DisposeAsync().ConfigureAwait(false);
+ }
+ }
+ }
+#endif
+
+#pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant
+#pragma warning disable CS8774 // Member must have a non-null value when exiting.
+
+ // Sets up the data structures that are necessary before any read operation takes place,
+ // throwing if the object is in a state where reads are not possible.
+ [MemberNotNull(nameof(_innerDecoder), nameof(_thisEncoder), nameof(_readBuffer))]
+ private void EnsurePreReadConditions()
+ {
+ ThrowIfDisposed();
+ if (_innerDecoder is null)
+ {
+ InitializeReadDataStructures();
+ }
+
+ void InitializeReadDataStructures()
+ {
+ if (!CanRead)
+ {
+ throw Error.NotSupported(Properties.Resources.NotSupported_UnreadableStream);
+ }
+
+ _innerDecoder = _innerEncoding.GetDecoder();
+ _thisEncoder = _thisEncoding.GetEncoder();
+ _readCharBufferMaxSize = _innerEncoding.GetMaxCharCount(DefaultReadByteBufferSize);
+
+ // Can't use ArrayPool for the below array since it's an instance field of this object.
+ // But since we never expose the raw array contents to our callers we can get away
+ // with skipping the array zero-init during allocation. The segment points to the
+ // data which we haven't yet read; however, we own the entire backing array and can
+ // re-create the segment as needed once the array is repopulated.
+
+#if NET5_0_OR_GREATER
+ _readBuffer = GC.AllocateUninitializedArray(_thisEncoding.GetMaxByteCount(_readCharBufferMaxSize));
+#else
+ _readBuffer = new byte[_thisEncoding.GetMaxByteCount(_readCharBufferMaxSize)];
+#endif
+ }
+ }
+
+ // Sets up the data structures that are necessary before any write operation takes place,
+ // throwing if the object is in a state where writes are not possible.
+ [MemberNotNull(nameof(_thisDecoder), nameof(_innerEncoder))]
+ private void EnsurePreWriteConditions()
+ {
+ ThrowIfDisposed();
+ if (_innerEncoder is null)
+ {
+ InitializeReadDataStructures();
+ }
+
+ void InitializeReadDataStructures()
+ {
+ if (!CanWrite)
+ {
+ throw Error.NotSupported(Properties.Resources.NotSupported_UnwritableStream);
+ }
+
+ _innerEncoder = _innerEncoding.GetEncoder();
+ _thisDecoder = _thisEncoding.GetDecoder();
+ }
+ }
+
+#pragma warning restore CS8774 // Member must have a non-null value when exiting.
+#pragma warning restore CS3016 // Arrays as attribute arguments is not CLS-compliant
+
+ // returns any pending data that needs to be flushed to the inner stream before disposal
+ private ArraySegment FinalFlushWriteBuffers()
+ {
+ // If this stream was never used for writing, no-op.
+
+ if (_thisDecoder is null || _innerEncoder is null)
+ {
+ return default;
+ }
+
+ // convert bytes [this] -> chars
+ // Having leftover data in our buffers should be very rare since it should only
+ // occur if the end of the stream contains an incomplete multi-byte sequence.
+ // Let's not bother complicating this logic with array pool rentals or allocation-
+ // avoiding loops.
+
+ char[] chars = EmptyCharBuffer;
+ int charCount = _thisDecoder.GetCharCount(EmptyByteBuffer, 0, 0, flush: true);
+ if (charCount > 0)
+ {
+ chars = new char[charCount];
+ charCount = _thisDecoder.GetChars(EmptyByteBuffer, 0, 0, chars, 0, flush: true);
+ }
+
+ // convert chars -> bytes [inner]
+ // It's possible that _innerEncoder might need to perform some end-of-text fixup
+ // (due to flush: true), even if _thisDecoder didn't need to do so.
+
+ byte[] bytes = EmptyByteBuffer;
+ int byteCount = _innerEncoder.GetByteCount(chars, 0, charCount, flush: true);
+ if (byteCount > 0)
+ {
+ bytes = new byte[byteCount];
+ byteCount = _innerEncoder.GetBytes(chars, 0, charCount, bytes, 0, flush: true);
+ }
+
+ return new ArraySegment(bytes, 0, byteCount);
+ }
+
+ public override void Flush()
+ {
+ // Don't pass flush: true to our inner decoder + encoder here, since it could cause data
+ // corruption if a flush occurs mid-stream. Wait until the stream is being closed.
+
+ ThrowIfDisposed();
+ _innerStream.Flush();
+ }
+
+ public override Task FlushAsync(CancellationToken cancellationToken)
+ {
+ // Don't pass flush: true to our inner decoder + encoder here, since it could cause data
+ // corruption if a flush occurs mid-stream. Wait until the stream is being closed.
+
+ ThrowIfDisposed();
+ return _innerStream.FlushAsync(cancellationToken);
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ ValidateBufferArguments(buffer, offset, count);
+
+ return Read(new Span(buffer, offset, count));
+ }
+
+#if NETCOREAPP || NETSTANDARD2_1
+ public override
+#else
+ private
+#endif
+ int Read(Span buffer)
+ {
+ EnsurePreReadConditions();
+
+ // If there's no data in our pending read buffer, we'll need to populate it from
+ // the inner stream. We read the inner stream's bytes, decode that to chars using
+ // the 'inner' encoding, then re-encode those chars under the 'this' encoding.
+ // We've already calculated the worst-case expansions for the intermediate buffers,
+ // so we use GetChars / GetBytes instead of Convert to simplify the below code
+ // and to ensure an exception is thrown if the Encoding reported an incorrect
+ // worst-case expansion.
+
+ if (_readBufferCount == 0)
+ {
+ byte[] rentedBytes = ArrayPool.Shared.Rent(DefaultReadByteBufferSize);
+ char[] rentedChars = ArrayPool.Shared.Rent(_readCharBufferMaxSize);
+
+ try
+ {
+ int pendingReadDataPopulatedJustNow;
+ bool isEofReached;
+
+ do
+ {
+ // Beware: Use our constant value instead of 'rentedBytes.Length' for the count
+ // parameter below. The reason for this is that the array pool could've returned
+ // a larger-than-expected array, but our worst-case expansion calculations
+ // performed earlier didn't take that into account.
+
+ int innerBytesReadJustNow = _innerStream.Read(rentedBytes, 0, DefaultReadByteBufferSize);
+ isEofReached = (innerBytesReadJustNow == 0);
+
+ // Convert bytes [inner] -> chars, then convert chars -> bytes [this].
+ // We can't return 0 to our caller until inner stream EOF has been reached. But if the
+ // inner stream returns a non-empty but incomplete buffer, GetBytes may return 0 anyway
+ // since it can't yet make forward progress on the input data. If this happens, we'll
+ // loop so that we don't return 0 to our caller until we truly see inner stream EOF.
+
+ int charsDecodedJustNow = _innerDecoder.GetChars(rentedBytes, 0, innerBytesReadJustNow, rentedChars, 0, flush: isEofReached);
+ pendingReadDataPopulatedJustNow = _thisEncoder.GetBytes(rentedChars, 0, charsDecodedJustNow, _readBuffer, 0, flush: isEofReached);
+ } while (!isEofReached && pendingReadDataPopulatedJustNow == 0);
+
+ _readBufferOffset = 0;
+ _readBufferCount = pendingReadDataPopulatedJustNow;
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(rentedBytes);
+ ArrayPool.Shared.Return(rentedChars);
+ }
+ }
+
+ // At this point: (a) we've populated our pending read buffer and there's
+ // useful data to return to our caller; or (b) the pending read buffer is
+ // empty because the inner stream has reached EOF and all pending read data
+ // has already been flushed, and we should return 0.
+
+ int bytesToReturn = Math.Min(_readBufferCount, buffer.Length);
+ _readBuffer.AsSpan(_readBufferOffset, bytesToReturn).CopyTo(buffer);
+ _readBufferOffset += bytesToReturn;
+ _readBufferCount -= bytesToReturn;
+ return bytesToReturn;
+ }
+
+ public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
+ {
+ ValidateBufferArguments(buffer, offset, count);
+
+ return ReadAsync(new Memory(buffer, offset, count), cancellationToken).AsTask();
+ }
+
+#if NETCOREAPP || NETSTANDARD2_1
+ public override
+#else
+ private
+#endif
+ ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default)
+ {
+ EnsurePreReadConditions();
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+#if NETCOREAPP || NETSTANDARD
+ return new ValueTask(Task.FromCanceled(cancellationToken));
+#else
+ // Lose track of the CancellationToken in this case.
+ return new ValueTask(TaskHelpers.Canceled());
+#endif
+ }
+
+ return ReadAsyncCore(buffer, cancellationToken);
+ async ValueTask ReadAsyncCore(Memory buffer, CancellationToken cancellationToken)
+ {
+ // If there's no data in our pending read buffer, we'll need to populate it from
+ // the inner stream. We read the inner stream's bytes, decode that to chars using
+ // the 'inner' encoding, then re-encode those chars under the 'this' encoding.
+ // We've already calculated the worst-case expansions for the intermediate buffers,
+ // so we use GetChars / GetBytes instead of Convert to simplify the below code
+ // and to ensure an exception is thrown if the Encoding reported an incorrect
+ // worst-case expansion.
+
+ if (_readBufferCount == 0)
+ {
+ byte[] rentedBytes = ArrayPool.Shared.Rent(DefaultReadByteBufferSize);
+ char[] rentedChars = ArrayPool.Shared.Rent(_readCharBufferMaxSize);
+
+ try
+ {
+ int pendingReadDataPopulatedJustNow;
+ bool isEofReached;
+
+ do
+ {
+ // Beware: Use our constant value instead of 'rentedBytes.Length' when creating
+ // the Mem struct. The reason for this is that the array pool could've returned
+ // a larger-than-expected array, but our worst-case expansion calculations
+ // performed earlier didn't take that into account.
+
+ int innerBytesReadJustNow = await _innerStream.ReadAsync(rentedBytes, 0, DefaultReadByteBufferSize, cancellationToken).ConfigureAwait(false);
+ isEofReached = (innerBytesReadJustNow == 0);
+
+ // Convert bytes [inner] -> chars, then convert chars -> bytes [this].
+ // We can't return 0 to our caller until inner stream EOF has been reached. But if the
+ // inner stream returns a non-empty but incomplete buffer, GetBytes may return 0 anyway
+ // since it can't yet make forward progress on the input data. If this happens, we'll
+ // loop so that we don't return 0 to our caller until we truly see inner stream EOF.
+
+ int charsDecodedJustNow = _innerDecoder.GetChars(rentedBytes, 0, innerBytesReadJustNow, rentedChars, 0, flush: isEofReached);
+ pendingReadDataPopulatedJustNow = _thisEncoder.GetBytes(rentedChars, 0, charsDecodedJustNow, _readBuffer, 0, flush: isEofReached);
+ } while (!isEofReached && pendingReadDataPopulatedJustNow == 0);
+
+ _readBufferOffset = 0;
+ _readBufferCount = pendingReadDataPopulatedJustNow;
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(rentedBytes);
+ ArrayPool.Shared.Return(rentedChars);
+ }
+ }
+
+ // At this point: (a) we've populated our pending read buffer and there's
+ // useful data to return to our caller; or (b) the pending read buffer is
+ // empty because the inner stream has reached EOF and all pending read data
+ // has already been flushed, and we should return 0.
+
+ int bytesToReturn = Math.Min(_readBufferCount, buffer.Length);
+ _readBuffer.AsSpan(_readBufferOffset, bytesToReturn).CopyTo(buffer.Span);
+ _readBufferOffset += bytesToReturn;
+ _readBufferCount -= bytesToReturn;
+ return bytesToReturn;
+ }
+ }
+
+ public override int ReadByte()
+ {
+ return Read(_singleByteBuffer, offset: 0, count: 1) != 0 ? _singleByteBuffer[0] : -1;
+ }
+
+ public override long Seek(long offset, SeekOrigin origin)
+ => throw Error.NotSupported(Properties.Resources.NotSupported_UnseekableStream);
+
+ public override void SetLength(long value)
+ => throw Error.NotSupported(Properties.Resources.NotSupported_UnseekableStream);
+
+#if NET6_0_OR_GREATER
+ [StackTraceHidden]
+#endif
+ private void ThrowIfDisposed()
+ {
+ if (_innerStream is null)
+ {
+ ThrowObjectDisposedException();
+ }
+ }
+
+ [DoesNotReturn]
+#if NET6_0_OR_GREATER
+ [StackTraceHidden]
+#endif
+ private void ThrowObjectDisposedException()
+ {
+ throw new ObjectDisposedException(GetType().Name, Properties.Resources.ObjectDisposed_StreamClosed);
+ }
+
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ ValidateBufferArguments(buffer, offset, count);
+
+#if NETCOREAPP || NETSTANDARD2_1
+ Write(new ReadOnlySpan(buffer, offset, count));
+#else
+ WriteCore(buffer, offset, count);
+#endif
+ }
+
+#if NETCOREAPP || NETSTANDARD2_1
+ public override void Write(ReadOnlySpan buffer)
+ {
+ EnsurePreWriteConditions();
+
+ if (buffer.IsEmpty)
+ {
+ return;
+ }
+
+ int rentalLength = buffer.Length < MinWriteRentedArraySize ? MinWriteRentedArraySize :
+ buffer.Length > MaxWriteRentedArraySize ? MaxWriteRentedArraySize :
+ buffer.Length;
+
+ char[] scratchChars = ArrayPool.Shared.Rent(rentalLength);
+ byte[] scratchBytes = ArrayPool.Shared.Rent(rentalLength);
+
+ try
+ {
+ bool decoderFinished, encoderFinished;
+ do
+ {
+ // convert bytes [this] -> chars
+
+ _thisDecoder.Convert(
+ bytes: buffer,
+ chars: scratchChars,
+ flush: false,
+ out int bytesConsumed,
+ out int charsWritten,
+ out decoderFinished);
+
+ buffer = buffer.Slice(bytesConsumed);
+
+ // convert chars -> bytes [inner]
+
+ Span decodedChars = scratchChars.AsSpan(0, charsWritten);
+
+ do
+ {
+ _innerEncoder.Convert(
+ chars: decodedChars,
+ bytes: scratchBytes,
+ flush: false,
+ out int charsConsumed,
+ out int bytesWritten,
+ out encoderFinished);
+
+ decodedChars = decodedChars.Slice(charsConsumed);
+
+ // It's more likely that the inner stream provides an optimized implementation of
+ // Write(byte[], ...) over Write(ROS), so we'll prefer the byte[]-based overloads.
+
+ _innerStream.Write(scratchBytes, 0, bytesWritten);
+ } while (!encoderFinished);
+ } while (!decoderFinished);
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(scratchChars);
+ ArrayPool.Shared.Return(scratchBytes);
+ }
+ }
+#else
+ private void WriteCore(byte[] buffer, int offset, int count)
+ {
+ EnsurePreWriteConditions();
+
+ if (count == 0)
+ {
+ return;
+ }
+
+ int rentalLength = buffer.Length < MinWriteRentedArraySize ? MinWriteRentedArraySize :
+ buffer.Length > MaxWriteRentedArraySize ? MaxWriteRentedArraySize :
+ buffer.Length;
+
+ char[] scratchChars = ArrayPool.Shared.Rent(rentalLength);
+ byte[] scratchBytes = ArrayPool.Shared.Rent(rentalLength);
+
+ try
+ {
+ bool decoderFinished, encoderFinished;
+ do
+ {
+ // convert bytes [this] -> chars
+
+ _thisDecoder.Convert(
+ bytes: buffer,
+ byteIndex: offset,
+ byteCount: count,
+ chars: scratchChars,
+ charIndex: 0,
+ charCount: rentalLength,
+ flush: false,
+ out int bytesConsumed,
+ out int charsWritten,
+ out decoderFinished);
+
+ offset += bytesConsumed;
+ count -= bytesConsumed;
+
+ // convert chars -> bytes [inner]
+
+ int scratchOffset = 0;
+ do
+ {
+ _innerEncoder.Convert(
+ chars: scratchChars,
+ charIndex: scratchOffset,
+ charCount: charsWritten,
+ bytes: scratchBytes,
+ byteIndex: 0,
+ byteCount: rentalLength,
+ flush: false,
+ out int charsConsumed,
+ out int bytesWritten,
+ out encoderFinished);
+
+ scratchOffset += charsConsumed;
+ charsWritten -= charsConsumed;
+
+ // It's more likely that the inner stream provides an optimized implementation of
+ // Write(byte[], ...) over Write(ROS), so we'll prefer the byte[]-based overloads.
+
+ _innerStream.Write(scratchBytes, 0, bytesWritten);
+ } while (!encoderFinished);
+ } while (!decoderFinished);
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(scratchChars);
+ ArrayPool.Shared.Return(scratchBytes);
+ }
+ }
+#endif
+
+ public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
+ {
+ ValidateBufferArguments(buffer, offset, count);
+
+#if NETCOREAPP || NETSTANDARD2_1
+ return WriteAsync(new ReadOnlyMemory(buffer, offset, count), cancellationToken).AsTask();
+#else
+ return WriteAsyncCore(buffer, offset, count, cancellationToken).AsTask();
+#endif
+ }
+
+#if NETCOREAPP || NETSTANDARD2_1
+ public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default)
+ {
+ EnsurePreWriteConditions();
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ return new ValueTask(Task.FromCanceled(cancellationToken));
+ }
+
+ if (buffer.IsEmpty)
+ {
+ // ValueTask.CompletedTask
+ return default;
+ }
+
+ return WriteAsyncCore(buffer, cancellationToken);
+ async ValueTask WriteAsyncCore(ReadOnlyMemory remainingOuterEncodedBytes, CancellationToken cancellationToken)
+ {
+ int rentalLength = remainingOuterEncodedBytes.Length < MinWriteRentedArraySize ? MinWriteRentedArraySize :
+ remainingOuterEncodedBytes.Length > MaxWriteRentedArraySize ? MaxWriteRentedArraySize:
+ remainingOuterEncodedBytes.Length;
+
+ char[] scratchChars = ArrayPool.Shared.Rent(rentalLength);
+ byte[] scratchBytes = ArrayPool.Shared.Rent(rentalLength);
+
+ try
+ {
+ bool decoderFinished, encoderFinished;
+ do
+ {
+ // convert bytes [this] -> chars
+
+ _thisDecoder.Convert(
+ bytes: buffer,
+ chars: scratchChars,
+ flush: false,
+ out int bytesConsumed,
+ out int charsWritten,
+ out decoderFinished);
+
+ buffer = buffer.Slice(bytesConsumed);
+
+ // convert chars -> bytes [inner]
+
+ Span decodedChars = scratchChars.AsSpan(0, charsWritten);
+
+ do
+ {
+ _innerEncoder.Convert(
+ chars: decodedChars,
+ bytes: scratchBytes,
+ flush: false,
+ out int charsConsumed,
+ out int bytesWritten,
+ out encoderFinished);
+
+ decodedChars = decodedChars.Slice(charsConsumed);
+
+ await _innerStream.WriteAsync(scratchBytes, 0, bytesWritten, cancellationToken).ConfigureAwait(false);
+ } while (!encoderFinished);
+ } while (!decoderFinished);
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(scratchChars);
+ ArrayPool.Shared.Return(scratchBytes);
+ }
+ }
+ }
+#else
+ private ValueTask WriteAsyncCore(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
+ {
+ EnsurePreWriteConditions();
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+#if NETSTANDARD
+ return new ValueTask(Task.FromCanceled(cancellationToken));
+#else
+ // Lose track of the CancellationToken in this case.
+ return new ValueTask(TaskHelpers.Canceled());
+#endif
+ }
+
+ if (count == 0)
+ {
+ // ValueTask.CompletedTask
+ return default;
+ }
+
+ return WriteAsyncCore(buffer, cancellationToken);
+ async ValueTask WriteAsyncCore(ReadOnlyMemory remainingOuterEncodedBytes, CancellationToken cancellationToken)
+ {
+ int rentalLength = remainingOuterEncodedBytes.Length < MinWriteRentedArraySize ? MinWriteRentedArraySize :
+ remainingOuterEncodedBytes.Length > MaxWriteRentedArraySize ? MaxWriteRentedArraySize :
+ remainingOuterEncodedBytes.Length;
+
+ char[] scratchChars = ArrayPool.Shared.Rent(rentalLength);
+ byte[] scratchBytes = ArrayPool.Shared.Rent(rentalLength);
+
+ try
+ {
+ bool decoderFinished, encoderFinished;
+ do
+ {
+ // convert bytes [this] -> chars
+
+ _thisDecoder.Convert(
+ bytes: buffer,
+ byteIndex: offset,
+ byteCount: count,
+ chars: scratchChars,
+ charIndex: 0,
+ charCount: rentalLength,
+ flush: false,
+ out int bytesConsumed,
+ out int charsWritten,
+ out decoderFinished);
+
+ offset += bytesConsumed;
+ count -= bytesConsumed;
+
+ // convert chars -> bytes [inner]
+
+ int scratchOffset = 0;
+ do
+ {
+ _innerEncoder.Convert(
+ chars: scratchChars,
+ charIndex: scratchOffset,
+ charCount: charsWritten,
+ bytes: scratchBytes,
+ byteIndex: 0,
+ byteCount: rentalLength,
+ flush: false,
+ out int charsConsumed,
+ out int bytesWritten,
+ out encoderFinished);
+
+ scratchOffset += charsConsumed;
+ charsWritten -= charsConsumed;
+
+ await _innerStream.WriteAsync(scratchBytes, 0, bytesWritten, cancellationToken).ConfigureAwait(false);
+ } while (!encoderFinished);
+ } while (!decoderFinished);
+ }
+ finally
+ {
+ ArrayPool.Shared.Return(scratchChars);
+ ArrayPool.Shared.Return(scratchBytes);
+ }
+ }
+ }
+#endif
+
+ public override void WriteByte(byte value)
+ {
+ _singleByteBuffer[0] = value;
+ Write(_singleByteBuffer, offset: 0, count: 1);
+ }
+
+ // From https://github.com/dotnet/runtime/blob/88868b7a781f4e5b9037b8721f30440207a7aa42/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static void ValidateBufferArguments(byte[] buffer, int offset, int count)
+ {
+ if (buffer is null)
+ {
+ throw Error.ArgumentNull(nameof(buffer));
+ }
+
+ if (offset < 0)
+ {
+ throw Error.ArgumentMustBeGreaterThanOrEqualTo(nameof(offset), offset, minValue: 0);
+ }
+
+ if ((uint)count > buffer.Length - offset)
+ {
+ throw Error.ArgumentOutOfRange(nameof(count), count, Properties.Resources.Argument_InvalidOffLen);
+ }
+ }
+ }
+}
diff --git a/src/System.Net.Http.Formatting/Internal/TypeExtensions.cs b/src/System.Net.Http.Formatting/Internal/TypeExtensions.cs
index 0f22bfcea..aab7ca05c 100644
--- a/src/System.Net.Http.Formatting/Internal/TypeExtensions.cs
+++ b/src/System.Net.Http.Formatting/Internal/TypeExtensions.cs
@@ -8,7 +8,7 @@ namespace System.Net.Http
{
internal static class TypeExtensions
{
-#if NETFX_CORE
+#if NETSTANDARD1_3
private static bool EqualTo(this Type[] t1, Type[] t2)
{
if (t1.Length != t2.Length)
@@ -42,7 +42,7 @@ public static Type ExtractGenericInterface(this Type queryType, Type interfaceTy
return (matchesInterface(queryType)) ? queryType : queryType.GetInterfaces().FirstOrDefault(matchesInterface);
}
-#if NETFX_CORE
+#if NETSTANDARD1_3
public static Type[] GetGenericArguments(this Type type)
{
return type.GetTypeInfo().GenericTypeArguments;
@@ -54,7 +54,7 @@ public static Type[] GetInterfaces(this Type type)
}
#endif
-#if NETFX_CORE
+#if NETSTANDARD1_3
public static bool IsAssignableFrom(this Type type, Type c)
{
return type.GetTypeInfo().IsAssignableFrom(c.GetTypeInfo());
@@ -63,7 +63,7 @@ public static bool IsAssignableFrom(this Type type, Type c)
public static bool IsGenericType(this Type type)
{
-#if NETFX_CORE
+#if NETSTANDARD1_3
return type.GetTypeInfo().IsGenericType;
#else
return type.IsGenericType;
@@ -72,7 +72,7 @@ public static bool IsGenericType(this Type type)
public static bool IsInterface(this Type type)
{
-#if NETFX_CORE
+#if NETSTANDARD1_3
return type.GetTypeInfo().IsInterface;
#else
return type.IsInterface;
@@ -81,7 +81,7 @@ public static bool IsInterface(this Type type)
public static bool IsValueType(this Type type)
{
-#if NETFX_CORE
+#if NETSTANDARD1_3
return type.GetTypeInfo().IsValueType;
#else
return type.IsValueType;
diff --git a/src/System.Net.Http.Formatting/InvalidByteRangeException.cs b/src/System.Net.Http.Formatting/InvalidByteRangeException.cs
index 230564dbd..ef6175208 100644
--- a/src/System.Net.Http.Formatting/InvalidByteRangeException.cs
+++ b/src/System.Net.Http.Formatting/InvalidByteRangeException.cs
@@ -9,7 +9,7 @@
namespace System.Net.Http
{
///
- /// An exception thrown by in case none of the requested ranges
+ /// An exception thrown by in case none of the requested ranges
/// overlap with the current extend of the selected resource. The current extend of the resource
/// is indicated in the ContentRange property.
///
@@ -35,11 +35,13 @@ public InvalidByteRangeException(ContentRangeHeaderValue contentRange, string me
Initialize(contentRange);
}
+#if !NETSTANDARD1_3 // Exception is not serializable in netstandard1.3.
public InvalidByteRangeException(ContentRangeHeaderValue contentRange, SerializationInfo info, StreamingContext context)
: base(info, context)
{
Initialize(contentRange);
}
+#endif
///
/// The current extend of the resource indicated in terms of a ContentRange header field.
diff --git a/src/System.Net.Http.Formatting/MimeBodyPart.cs b/src/System.Net.Http.Formatting/MimeBodyPart.cs
index aa14f5dc6..cd07e8bba 100644
--- a/src/System.Net.Http.Formatting/MimeBodyPart.cs
+++ b/src/System.Net.Http.Formatting/MimeBodyPart.cs
@@ -39,8 +39,8 @@ public MimeBodyPart(MultipartStreamProvider streamProvider, int maxBodyPartHeade
Segments = new List>(2);
_headers = FormattingUtilities.CreateEmptyContentHeaders();
HeaderParser = new InternetMessageFormatHeaderParser(
- _headers,
- maxBodyPartHeaderSize,
+ _headers,
+ maxBodyPartHeaderSize,
ignoreHeaderValidation: true);
}
@@ -190,7 +190,7 @@ private void CleanupOutputStream()
}
else
{
-#if NETFX_CORE
+#if NETSTANDARD1_3
_outputStream.Dispose();
#else
_outputStream.Close();
diff --git a/src/System.Net.Http.Formatting/MultipartFormDataStreamProvider.cs b/src/System.Net.Http.Formatting/MultipartFormDataStreamProvider.cs
index f2c997e92..1e012106b 100644
--- a/src/System.Net.Http.Formatting/MultipartFormDataStreamProvider.cs
+++ b/src/System.Net.Http.Formatting/MultipartFormDataStreamProvider.cs
@@ -11,12 +11,12 @@
namespace System.Net.Http
{
///
- /// A implementation suited for use with HTML file uploads for writing file
- /// content to a . The stream provider looks at the Content-Disposition header
+ /// A implementation suited for use with HTML file uploads for writing file
+ /// content to a . The stream provider looks at the Content-Disposition header
/// field and determines an output based on the presence of a filename parameter.
- /// If a filename parameter is present in the Content-Disposition header field then the body
+ /// If a filename parameter is present in the Content-Disposition header field then the body
/// part is written to a , otherwise it is written to a .
- /// This makes it convenient to process MIME Multipart HTML Form data which is a combination of form
+ /// This makes it convenient to process MIME Multipart HTML Form data which is a combination of form
/// data and file content.
///
public class MultipartFormDataStreamProvider : MultipartFileStreamProvider
@@ -52,7 +52,7 @@ public MultipartFormDataStreamProvider(string rootPath, int bufferSize)
///
/// This body part stream provider examines the headers provided by the MIME multipart parser
- /// and decides whether it should return a file stream or a memory stream for the body part to be
+ /// and decides whether it should return a file stream or a memory stream for the body part to be
/// written to.
///
/// The parent MIME multipart HttpContent instance.
diff --git a/src/System.Net.Http.Formatting/MultipartRelatedStreamProvider.cs b/src/System.Net.Http.Formatting/MultipartRelatedStreamProvider.cs
index 464f891e7..68b5a6034 100644
--- a/src/System.Net.Http.Formatting/MultipartRelatedStreamProvider.cs
+++ b/src/System.Net.Http.Formatting/MultipartRelatedStreamProvider.cs
@@ -24,7 +24,7 @@ public class MultipartRelatedStreamProvider : MultipartStreamProvider
private HttpContent _parent;
///
- /// Gets the instance that has been marked as the root content in the
+ /// Gets the instance that has been marked as the root content in the
/// MIME multipart related message using the start parameter. If no start parameter is
/// present then pick the first of the children.
///
@@ -71,7 +71,7 @@ private static HttpContent FindRootContent(HttpContent parent, IEnumerable
/// A strongly-typed resource class, for looking up localized strings, etc.
///
@@ -19,19 +20,19 @@ namespace System.Net.Http.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
-
+
private static global::System.Resources.ResourceManager resourceMan;
-
+
private static global::System.Globalization.CultureInfo resourceCulture;
-
+
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
-
+
///
/// Returns the cached ResourceManager instance used by this class.
///
@@ -39,7 +40,7 @@ internal Resources() {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
-#if NETFX_CORE
+#if NETSTANDARD1_3
var assembly = typeof(Resources).GetTypeInfo().Assembly;
#else
var assembly = typeof(Resources).Assembly;
@@ -50,7 +51,7 @@ internal Resources() {
return resourceMan;
}
}
-
+
///
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
@@ -64,7 +65,16 @@ internal Resources() {
resourceCulture = value;
}
}
-
+
+ ///
+ /// Looks up a localized string similar to Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection..
+ ///
+ internal static string Argument_InvalidOffLen {
+ get {
+ return ResourceManager.GetString("Argument_InvalidOffLen", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Async Callback threw an exception..
///
@@ -73,7 +83,7 @@ internal static string AsyncResult_CallbackThrewException {
return ResourceManager.GetString("AsyncResult_CallbackThrewException", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The IAsyncResult implementation '{0}' tried to complete a single operation multiple times. This could be caused by an incorrect application IAsyncResult implementation or other extensibility code, such as an IAsyncResult that returns incorrect CompletedSynchronously values or invokes the AsyncCallback multiple times..
///
@@ -82,7 +92,7 @@ internal static string AsyncResult_MultipleCompletes {
return ResourceManager.GetString("AsyncResult_MultipleCompletes", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to End cannot be called twice on an AsyncResult..
///
@@ -91,7 +101,7 @@ internal static string AsyncResult_MultipleEnds {
return ResourceManager.GetString("AsyncResult_MultipleEnds", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to An incorrect IAsyncResult was provided to an 'End' method. The IAsyncResult object passed to 'End' must be the one returned from the matching 'Begin' or passed to the callback provided to 'Begin'..
///
@@ -100,7 +110,7 @@ internal static string AsyncResult_ResultMismatch {
return ResourceManager.GetString("AsyncResult_ResultMismatch", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Found zero byte ranges. There must be at least one byte range provided..
///
@@ -109,7 +119,7 @@ internal static string ByteRangeStreamContentNoRanges {
return ResourceManager.GetString("ByteRangeStreamContentNoRanges", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The range unit '{0}' is not valid. The range must have a unit of '{1}'..
///
@@ -118,7 +128,7 @@ internal static string ByteRangeStreamContentNotBytesRange {
return ResourceManager.GetString("ByteRangeStreamContentNotBytesRange", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The stream over which '{0}' provides a range view must have a length greater than or equal to 1..
///
@@ -127,7 +137,7 @@ internal static string ByteRangeStreamEmpty {
return ResourceManager.GetString("ByteRangeStreamEmpty", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The 'From' value of the range must be less than or equal to {0}..
///
@@ -136,7 +146,16 @@ internal static string ByteRangeStreamInvalidFrom {
return ResourceManager.GetString("ByteRangeStreamInvalidFrom", resourceCulture);
}
}
-
+
+ ///
+ /// Looks up a localized string similar to An attempt was made to move the position before the beginning of the stream..
+ ///
+ internal static string ByteRangeStreamInvalidOffset {
+ get {
+ return ResourceManager.GetString("ByteRangeStreamInvalidOffset", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to None of the requested ranges ({0}) overlap with the current extent of the selected resource..
///
@@ -145,7 +164,7 @@ internal static string ByteRangeStreamNoneOverlap {
return ResourceManager.GetString("ByteRangeStreamNoneOverlap", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The requested range ({0}) does not overlap with the current extent of the selected resource..
///
@@ -154,7 +173,7 @@ internal static string ByteRangeStreamNoOverlap {
return ResourceManager.GetString("ByteRangeStreamNoOverlap", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The stream over which '{0}' provides a range view must be seekable..
///
@@ -163,7 +182,7 @@ internal static string ByteRangeStreamNotSeekable {
return ResourceManager.GetString("ByteRangeStreamNotSeekable", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to This is a read-only stream..
///
@@ -172,7 +191,7 @@ internal static string ByteRangeStreamReadOnly {
return ResourceManager.GetString("ByteRangeStreamReadOnly", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to A null '{0}' is not valid..
///
@@ -181,7 +200,7 @@ internal static string CannotHaveNullInList {
return ResourceManager.GetString("CannotHaveNullInList", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The '{0}' of '{1}' cannot be used as a supported media type because it is a media range..
///
@@ -190,7 +209,7 @@ internal static string CannotUseMediaRangeForSupportedMediaType {
return ResourceManager.GetString("CannotUseMediaRangeForSupportedMediaType", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The '{0}' type cannot accept a null value for the value type '{1}'..
///
@@ -199,7 +218,7 @@ internal static string CannotUseNullValueType {
return ResourceManager.GetString("CannotUseNullValueType", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The specified value is not a valid cookie name..
///
@@ -208,7 +227,7 @@ internal static string CookieInvalidName {
return ResourceManager.GetString("CookieInvalidName", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Cookie cannot be null..
///
@@ -217,7 +236,7 @@ internal static string CookieNull {
return ResourceManager.GetString("CookieNull", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The '{0}' list is invalid because it contains one or more null items..
///
@@ -226,7 +245,7 @@ internal static string DelegatingHandlerArrayContainsNullItem {
return ResourceManager.GetString("DelegatingHandlerArrayContainsNullItem", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The '{0}' list is invalid because the property '{1}' of '{2}' is not null..
///
@@ -235,7 +254,7 @@ internal static string DelegatingHandlerArrayHasNonNullInnerHandler {
return ResourceManager.GetString("DelegatingHandlerArrayHasNonNullInnerHandler", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Error reading HTML form URL-encoded data stream..
///
@@ -244,7 +263,7 @@ internal static string ErrorReadingFormUrlEncodedStream {
return ResourceManager.GetString("ErrorReadingFormUrlEncodedStream", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Mismatched types at node '{0}'..
///
@@ -253,7 +272,7 @@ internal static string FormUrlEncodedMismatchingTypes {
return ResourceManager.GetString("FormUrlEncodedMismatchingTypes", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Error parsing HTML form URL-encoded data, byte {0}..
///
@@ -262,7 +281,7 @@ internal static string FormUrlEncodedParseError {
return ResourceManager.GetString("FormUrlEncodedParseError", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Invalid HTTP status code: '{0}'. The status code must be between {1} and {2}..
///
@@ -271,7 +290,7 @@ internal static string HttpInvalidStatusCode {
return ResourceManager.GetString("HttpInvalidStatusCode", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Invalid HTTP version: '{0}'. The version must start with the characters '{1}'..
///
@@ -280,7 +299,7 @@ internal static string HttpInvalidVersion {
return ResourceManager.GetString("HttpInvalidVersion", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The '{0}' of the '{1}' has already been read..
///
@@ -289,7 +308,7 @@ internal static string HttpMessageContentAlreadyRead {
return ResourceManager.GetString("HttpMessageContentAlreadyRead", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The '{0}' must be seekable in order to create an '{1}' instance containing an entity body. .
///
@@ -298,7 +317,7 @@ internal static string HttpMessageContentStreamMustBeSeekable {
return ResourceManager.GetString("HttpMessageContentStreamMustBeSeekable", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Error reading HTTP message..
///
@@ -307,7 +326,7 @@ internal static string HttpMessageErrorReading {
return ResourceManager.GetString("HttpMessageErrorReading", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Invalid '{0}' instance provided. It does not have a content type header with a value of '{1}'..
///
@@ -316,7 +335,7 @@ internal static string HttpMessageInvalidMediaType {
return ResourceManager.GetString("HttpMessageInvalidMediaType", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to HTTP Request URI cannot be an empty string..
///
@@ -325,7 +344,7 @@ internal static string HttpMessageParserEmptyUri {
return ResourceManager.GetString("HttpMessageParserEmptyUri", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Error parsing HTTP message header byte {0} of message {1}..
///
@@ -334,7 +353,7 @@ internal static string HttpMessageParserError {
return ResourceManager.GetString("HttpMessageParserError", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to An invalid number of '{0}' header fields were present in the HTTP Request. It must contain exactly one '{0}' header field but found {1}..
///
@@ -343,7 +362,7 @@ internal static string HttpMessageParserInvalidHostCount {
return ResourceManager.GetString("HttpMessageParserInvalidHostCount", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Invalid URI scheme: '{0}'. The URI scheme must be a valid '{1}' scheme..
///
@@ -352,7 +371,7 @@ internal static string HttpMessageParserInvalidUriScheme {
return ResourceManager.GetString("HttpMessageParserInvalidUriScheme", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Invalid array at node '{0}'..
///
@@ -361,7 +380,7 @@ internal static string InvalidArrayInsert {
return ResourceManager.GetString("InvalidArrayInsert", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Traditional style array without '[]' is not supported with nested object at location {0}..
///
@@ -370,7 +389,16 @@ internal static string JQuery13CompatModeNotSupportNestedJson {
return ResourceManager.GetString("JQuery13CompatModeNotSupportNestedJson", resourceCulture);
}
}
-
+
+ ///
+ /// Looks up a localized string similar to Unable to validate types on this platform when {0} is 'true'. Please reset {0} or move to a supported platform, one where the 'netstandard2.0' assembly is usable..
+ ///
+ internal static string JsonMediaTypeFormatter_DCS_NotSupported {
+ get {
+ return ResourceManager.GetString("JsonMediaTypeFormatter_DCS_NotSupported", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to The '{0}' method returned null. It must return a JSON serializer instance..
///
@@ -379,7 +407,7 @@ internal static string JsonSerializerFactoryReturnedNull {
return ResourceManager.GetString("JsonSerializerFactoryReturnedNull", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The '{0}' method threw an exception when attempting to create a JSON serializer..
///
@@ -388,7 +416,7 @@ internal static string JsonSerializerFactoryThrew {
return ResourceManager.GetString("JsonSerializerFactoryThrew", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The maximum read depth ({0}) has been exceeded because the form url-encoded data being read has more levels of nesting than is allowed..
///
@@ -397,7 +425,7 @@ internal static string MaxDepthExceeded {
return ResourceManager.GetString("MaxDepthExceeded", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The number of keys in a NameValueCollection has exceeded the limit of '{0}'. You can adjust it by modifying the MaxHttpCollectionKeys property on the '{1}' class..
///
@@ -406,7 +434,7 @@ internal static string MaxHttpCollectionKeyLimitReached {
return ResourceManager.GetString("MaxHttpCollectionKeyLimitReached", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Error parsing BSON data; unable to read content as a {0}..
///
@@ -415,7 +443,7 @@ internal static string MediaTypeFormatter_BsonParseError_MissingData {
return ResourceManager.GetString("MediaTypeFormatter_BsonParseError_MissingData", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Error parsing BSON data; unexpected dictionary content: {0} entries, first key '{1}'..
///
@@ -424,7 +452,7 @@ internal static string MediaTypeFormatter_BsonParseError_UnexpectedData {
return ResourceManager.GetString("MediaTypeFormatter_BsonParseError_UnexpectedData", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The '{0}' method returned null. It must return a JSON reader instance..
///
@@ -433,7 +461,7 @@ internal static string MediaTypeFormatter_JsonReaderFactoryReturnedNull {
return ResourceManager.GetString("MediaTypeFormatter_JsonReaderFactoryReturnedNull", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The '{0}' method returned null. It must return a JSON writer instance..
///
@@ -442,7 +470,7 @@ internal static string MediaTypeFormatter_JsonWriterFactoryReturnedNull {
return ResourceManager.GetString("MediaTypeFormatter_JsonWriterFactoryReturnedNull", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The media type formatter of type '{0}' does not support reading because it does not implement the ReadFromStreamAsync method..
///
@@ -451,7 +479,7 @@ internal static string MediaTypeFormatterCannotRead {
return ResourceManager.GetString("MediaTypeFormatterCannotRead", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The media type formatter of type '{0}' does not support reading because it does not implement the ReadFromStream method..
///
@@ -460,7 +488,7 @@ internal static string MediaTypeFormatterCannotReadSync {
return ResourceManager.GetString("MediaTypeFormatterCannotReadSync", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The media type formatter of type '{0}' does not support writing because it does not implement the WriteToStreamAsync method..
///
@@ -469,7 +497,7 @@ internal static string MediaTypeFormatterCannotWrite {
return ResourceManager.GetString("MediaTypeFormatterCannotWrite", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The media type formatter of type '{0}' does not support writing because it does not implement the WriteToStream method..
///
@@ -478,7 +506,7 @@ internal static string MediaTypeFormatterCannotWriteSync {
return ResourceManager.GetString("MediaTypeFormatterCannotWriteSync", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to No encoding found for media type formatter '{0}'. There must be at least one supported encoding registered in order for the media type formatter to read or write content..
///
@@ -487,7 +515,7 @@ internal static string MediaTypeFormatterNoEncoding {
return ResourceManager.GetString("MediaTypeFormatterNoEncoding", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to MIME multipart boundary cannot end with an empty space..
///
@@ -496,7 +524,7 @@ internal static string MimeMultipartParserBadBoundary {
return ResourceManager.GetString("MimeMultipartParserBadBoundary", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Did not find required '{0}' header field in MIME multipart body part..
///
@@ -505,7 +533,7 @@ internal static string MultipartFormDataStreamProviderNoContentDisposition {
return ResourceManager.GetString("MultipartFormDataStreamProviderNoContentDisposition", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Could not determine a valid local file name for the multipart body part..
///
@@ -514,7 +542,7 @@ internal static string MultipartStreamProviderInvalidLocalFileName {
return ResourceManager.GetString("MultipartStreamProviderInvalidLocalFileName", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Nested bracket is not valid for '{0}' data at position {1}..
///
@@ -523,7 +551,7 @@ internal static string NestedBracketNotValid {
return ResourceManager.GetString("NestedBracketNotValid", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to A non-null request URI must be provided to determine if a '{0}' matches a given request or response message..
///
@@ -532,7 +560,7 @@ internal static string NonNullUriRequiredForMediaTypeMapping {
return ResourceManager.GetString("NonNullUriRequiredForMediaTypeMapping", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to No MediaTypeFormatter is available to read an object of type '{0}' from content with media type '{1}'..
///
@@ -541,7 +569,34 @@ internal static string NoReadSerializerAvailable {
return ResourceManager.GetString("NoReadSerializerAvailable", resourceCulture);
}
}
-
+
+ ///
+ /// Looks up a localized string similar to Stream does not support reading..
+ ///
+ internal static string NotSupported_UnreadableStream {
+ get {
+ return ResourceManager.GetString("NotSupported_UnreadableStream", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Stream does not support seeking..
+ ///
+ internal static string NotSupported_UnseekableStream {
+ get {
+ return ResourceManager.GetString("NotSupported_UnseekableStream", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Stream does not support writing..
+ ///
+ internal static string NotSupported_UnwritableStream {
+ get {
+ return ResourceManager.GetString("NotSupported_UnwritableStream", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to An object of type '{0}' cannot be used with a type parameter of '{1}'..
///
@@ -550,7 +605,7 @@ internal static string ObjectAndTypeDisagree {
return ResourceManager.GetString("ObjectAndTypeDisagree", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The configured formatter '{0}' cannot write an object of type '{1}'..
///
@@ -559,7 +614,16 @@ internal static string ObjectContent_FormatterCannotWriteType {
return ResourceManager.GetString("ObjectContent_FormatterCannotWriteType", resourceCulture);
}
}
-
+
+ ///
+ /// Looks up a localized string similar to Cannot access a closed stream..
+ ///
+ internal static string ObjectDisposed_StreamClosed {
+ get {
+ return ResourceManager.GetString("ObjectDisposed_StreamClosed", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Query string name cannot be null..
///
@@ -568,7 +632,7 @@ internal static string QueryStringNameShouldNotNull {
return ResourceManager.GetString("QueryStringNameShouldNotNull", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Unexpected end of HTTP message stream. HTTP message is not complete..
///
@@ -577,7 +641,7 @@ internal static string ReadAsHttpMessageUnexpectedTermination {
return ResourceManager.GetString("ReadAsHttpMessageUnexpectedTermination", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Invalid '{0}' instance provided. It does not have a '{1}' content-type header with a '{2}' parameter..
///
@@ -586,7 +650,7 @@ internal static string ReadAsMimeMultipartArgumentNoBoundary {
return ResourceManager.GetString("ReadAsMimeMultipartArgumentNoBoundary", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Invalid '{0}' instance provided. It does not have a content-type header value. '{0}' instances must have a content-type header starting with '{1}'..
///
@@ -595,7 +659,7 @@ internal static string ReadAsMimeMultipartArgumentNoContentType {
return ResourceManager.GetString("ReadAsMimeMultipartArgumentNoContentType", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Invalid '{0}' instance provided. It does not have a content type header starting with '{1}'..
///
@@ -604,7 +668,7 @@ internal static string ReadAsMimeMultipartArgumentNoMultipart {
return ResourceManager.GetString("ReadAsMimeMultipartArgumentNoMultipart", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Error reading MIME multipart body part..
///
@@ -613,7 +677,7 @@ internal static string ReadAsMimeMultipartErrorReading {
return ResourceManager.GetString("ReadAsMimeMultipartErrorReading", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Error writing MIME multipart body part to output stream..
///
@@ -622,7 +686,7 @@ internal static string ReadAsMimeMultipartErrorWriting {
return ResourceManager.GetString("ReadAsMimeMultipartErrorWriting", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Error parsing MIME multipart body part header byte {0} of data segment {1}..
///
@@ -631,7 +695,7 @@ internal static string ReadAsMimeMultipartHeaderParseError {
return ResourceManager.GetString("ReadAsMimeMultipartHeaderParseError", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Error parsing MIME multipart message byte {0} of data segment {1}..
///
@@ -640,7 +704,7 @@ internal static string ReadAsMimeMultipartParseError {
return ResourceManager.GetString("ReadAsMimeMultipartParseError", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The stream provider of type '{0}' threw an exception..
///
@@ -649,7 +713,7 @@ internal static string ReadAsMimeMultipartStreamProviderException {
return ResourceManager.GetString("ReadAsMimeMultipartStreamProviderException", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The stream provider of type '{0}' returned null. It must return a writable '{1}' instance..
///
@@ -658,7 +722,7 @@ internal static string ReadAsMimeMultipartStreamProviderNull {
return ResourceManager.GetString("ReadAsMimeMultipartStreamProviderNull", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The stream provider of type '{0}' returned a read-only stream. It must return a writable '{1}' instance..
///
@@ -667,7 +731,7 @@ internal static string ReadAsMimeMultipartStreamProviderReadOnly {
return ResourceManager.GetString("ReadAsMimeMultipartStreamProviderReadOnly", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Unexpected end of MIME multipart stream. MIME multipart message is not complete..
///
@@ -676,7 +740,7 @@ internal static string ReadAsMimeMultipartUnexpectedTermination {
return ResourceManager.GetString("ReadAsMimeMultipartUnexpectedTermination", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The '{0}' method in '{1}' returned null. It must return a RemoteStreamResult instance containing a writable stream and a valid URL..
///
@@ -685,7 +749,7 @@ internal static string RemoteStreamInfoCannotBeNull {
return ResourceManager.GetString("RemoteStreamInfoCannotBeNull", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The '{0}' serializer cannot serialize the type '{1}'..
///
@@ -694,7 +758,7 @@ internal static string SerializerCannotSerializeType {
return ResourceManager.GetString("SerializerCannotSerializeType", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to There is an unmatched opened bracket for the '{0}' at position {1}..
///
@@ -703,7 +767,7 @@ internal static string UnMatchedBracketNotValid {
return ResourceManager.GetString("UnMatchedBracketNotValid", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to Indentation is not supported by '{0}'..
///
@@ -712,7 +776,16 @@ internal static string UnsupportedIndent {
return ResourceManager.GetString("UnsupportedIndent", resourceCulture);
}
}
-
+
+ ///
+ /// Looks up a localized string similar to Unable to validate types on this platform when {0} is 'false'. Please set {0} or move to a supported platform, one where the 'netstandard2.0' assembly is usable..
+ ///
+ internal static string XmlMediaTypeFormatter_DCS_NotSupported {
+ get {
+ return ResourceManager.GetString("XmlMediaTypeFormatter_DCS_NotSupported", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to The object of type '{0}' returned by {1} must be an instance of either XmlObjectSerializer or XmlSerializer..
///
@@ -721,7 +794,7 @@ internal static string XmlMediaTypeFormatter_InvalidSerializerType {
return ResourceManager.GetString("XmlMediaTypeFormatter_InvalidSerializerType", resourceCulture);
}
}
-
+
///
/// Looks up a localized string similar to The object returned by {0} must not be a null value..
///
diff --git a/src/System.Net.Http.Formatting/Properties/Resources.resx b/src/System.Net.Http.Formatting/Properties/Resources.resx
index 77b63a96a..82d90e68c 100644
--- a/src/System.Net.Http.Formatting/Properties/Resources.resx
+++ b/src/System.Net.Http.Formatting/Properties/Resources.resx
@@ -1,17 +1,17 @@
-
@@ -339,4 +339,28 @@
The '{0}' method in '{1}' returned null. It must return a RemoteStreamResult instance containing a writable stream and a valid URL.
+
+ An attempt was made to move the position before the beginning of the stream.
+
+
+ Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
+
+
+ Stream does not support reading.
+
+
+ Stream does not support seeking.
+
+
+ Stream does not support writing.
+
+
+ Cannot access a closed stream.
+
+
+ Unable to validate types on this platform when {0} is 'true'. Please reset {0} or move to a supported platform, one where the .NET Standard 2.0 assembly is usable.
+
+
+ Unable to validate types on this platform when {0} is 'false'. Please set {0} or move to a supported platform, one where the .NET Standard 2.0 assembly is usable.
+
\ No newline at end of file
diff --git a/src/System.Net.Http.Formatting/PushStreamContent.cs b/src/System.Net.Http.Formatting/PushStreamContent.cs
index a8df4f262..8b4a72b3c 100644
--- a/src/System.Net.Http.Formatting/PushStreamContent.cs
+++ b/src/System.Net.Http.Formatting/PushStreamContent.cs
@@ -14,7 +14,7 @@ namespace System.Net.Http
{
///
/// Provides an implementation that exposes an output
- /// which can be written to directly. The ability to push data to the output stream differs from the
+ /// which can be written to directly. The ability to push data to the output stream differs from the
/// where data is pulled and not pushed.
///
public class PushStreamContent : HttpContent
@@ -24,8 +24,8 @@ public class PushStreamContent : HttpContent
///
/// Initializes a new instance of the class. The
/// action is called when an output stream
- /// has become available allowing the action to write to it directly. When the
- /// stream is closed, it will signal to the content that is has completed and the
+ /// has become available allowing the action to write to it directly. When the
+ /// stream is closed, it will signal to the content that it has completed and the
/// HTTP request or response will be completed.
///
/// The action to call when an output stream is available.
@@ -35,10 +35,11 @@ public PushStreamContent(Action onStreamA
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
- /// The action to call when an output stream is available. The stream is automatically
- /// closed when the return task is completed.
+ /// The action to call when an output stream is available. When the
+ /// output stream is closed or disposed, it will signal to the content that it has completed and the
+ /// HTTP request or response will be completed.
public PushStreamContent(Func onStreamAvailable)
: this(onStreamAvailable, (MediaTypeHeaderValue)null)
{
@@ -47,6 +48,8 @@ public PushStreamContent(Func onStr
///
/// Initializes a new instance of the class with the given media type.
///
+ /// The action to call when an output stream is available.
+ /// The value of the Content-Type content header on an HTTP response.
public PushStreamContent(Action onStreamAvailable, string mediaType)
: this(Taskify(onStreamAvailable), new MediaTypeHeaderValue(mediaType))
{
@@ -55,6 +58,10 @@ public PushStreamContent(Action onStreamA
///
/// Initializes a new instance of the class with the given media type.
///
+ /// The action to call when an output stream is available. When the
+ /// output stream is closed or disposed, it will signal to the content that it has completed and the
+ /// HTTP request or response will be completed.
+ /// The value of the Content-Type content header on an HTTP response.
public PushStreamContent(Func onStreamAvailable, string mediaType)
: this(onStreamAvailable, new MediaTypeHeaderValue(mediaType))
{
@@ -63,6 +70,8 @@ public PushStreamContent(Func onStr
///
/// Initializes a new instance of the class with the given .
///
+ /// The action to call when an output stream is available.
+ /// The value of the Content-Type content header on an HTTP response.
public PushStreamContent(Action onStreamAvailable, MediaTypeHeaderValue mediaType)
: this(Taskify(onStreamAvailable), mediaType)
{
@@ -71,6 +80,10 @@ public PushStreamContent(Action onStreamA
///
/// Initializes a new instance of the class with the given .
///
+ /// The action to call when an output stream is available. When the
+ /// output stream is closed or disposed, it will signal to the content that it has completed and the
+ /// HTTP request or response will be completed.
+ /// The value of the Content-Type content header on an HTTP response.
public PushStreamContent(Func onStreamAvailable, MediaTypeHeaderValue mediaType)
{
if (onStreamAvailable == null)
@@ -98,8 +111,8 @@ private static Func Taskify(
}
///
- /// When this method is called, it calls the action provided in the constructor with the output
- /// stream to write to. Once the action has completed its work it closes the stream which will
+ /// When this method is called, it calls the action provided in the constructor with the output
+ /// stream to write to. Once the action has completed its work it closes the stream which will
/// close this content instance and complete the HTTP request or response.
///
/// The to which to write.
@@ -140,10 +153,10 @@ public CompleteTaskOnCloseStream(Stream innerStream, TaskCompletionSource
_serializeToStreamTask = serializeToStreamTask;
}
-#if NETFX_CORE
+#if NETSTANDARD1_3
[SuppressMessage(
- "Microsoft.Usage",
- "CA2215:Dispose methods should call base class dispose",
+ "Microsoft.Usage",
+ "CA2215:Dispose methods should call base class dispose",
Justification = "See comments, this is intentional.")]
protected override void Dispose(bool disposing)
{
diff --git a/src/System.Net.Http.Formatting/Settings.StyleCop b/src/System.Net.Http.Formatting/Settings.StyleCop
deleted file mode 100644
index 5b387864d..000000000
--- a/src/System.Net.Http.Formatting/Settings.StyleCop
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
- UriQueryUtility.cs
-
-
- False
-
-
-
-
\ No newline at end of file
diff --git a/src/System.Net.Http.Formatting/System.Net.Http.Formatting.csproj b/src/System.Net.Http.Formatting/System.Net.Http.Formatting.csproj
index 42c7a509f..bf2cf46b1 100644
--- a/src/System.Net.Http.Formatting/System.Net.Http.Formatting.csproj
+++ b/src/System.Net.Http.Formatting/System.Net.Http.Formatting.csproj
@@ -10,171 +10,88 @@
$(OutputPath)$(AssemblyName).xml$(CodeAnalysis)..\Strict.ruleset
- $(DefineConstants);ASPNETMVC
+ $(DefineConstants);ASPNETHTTPFORMATTINGClient1591
+
-
+
+
+ ..\..\packages\System.Buffers.4.5.1\lib\netstandard2.0\System.Buffers.dllFalse
- ..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll
+ False
-
+
+ ..\..\packages\System.Memory.4.5.5\lib\netstandard2.0\System.Memory.dll
+ False
+ False
+
+
+ ..\..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll
+ False
+ False
+
-
-
-
- Properties\CommonAssemblyInfo.cs
-
-
- Common\CollectionExtensions.cs
-
-
- Common\Error.cs
-
-
- Common\ListWrapperCollection.cs
-
-
- Common\TaskHelpers.cs
-
-
- Common\TaskHelpersExtensions.cs
-
-
- Common\UriQueryUtility.cs
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- True
- True
- Resources.resx
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ ..\..\packages\NETStandard.Library.2.0.3\lib\netstandard2.0\netstandard.dll
+ False
+ False
+
+
+ ..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
+ False
+ False
+
+
+ ..\..\packages\Newtonsoft.Json.Bson.1.0.2\lib\net45\Newtonsoft.Json.Bson.dll
+ False
+ False
+
+
+
+
+
+
+
+
+
+
+
- Properties\CommonWebApiResources.Designer.cs
True
- TrueCommonWebApiResources.resx
+ True
+ Properties\CommonWebApiResources.Designer.cs
-
-
- Properties\CommonWebApiResources.resx
ResXFileCodeGeneratorCommonWebApiResources.Designer.cs
+ Properties\CommonWebApiResources.resx
-
-
+
+
+ True
+ Resources.resx
+ True
+ ResXFileCodeGeneratorResources.Designer.csDesigner
-
-
-
- CodeAnalysisDictionary.xml
-
-
-
+
+
+
+
-
\ No newline at end of file
+
diff --git a/src/System.Net.Http.Formatting/UriExtensions.cs b/src/System.Net.Http.Formatting/UriExtensions.cs
index ab83ec938..cf531431a 100644
--- a/src/System.Net.Http.Formatting/UriExtensions.cs
+++ b/src/System.Net.Http.Formatting/UriExtensions.cs
@@ -18,21 +18,12 @@ namespace System.Net.Http
[EditorBrowsable(EditorBrowsableState.Never)]
public static class UriExtensions
{
-#if NETFX_CORE
- ///
- /// Parses the query portion of the specified .
- ///
- /// The instance from which to read.
- /// A containing the parsed result.
- public static HttpValueCollection ParseQueryString(this Uri address)
-#else
///
/// Parses the query portion of the specified .
///
/// The instance from which to read.
/// A containing the parsed result.
public static NameValueCollection ParseQueryString(this Uri address)
-#endif
{
if (address == null)
{
diff --git a/src/System.Net.Http.Formatting/packages.config b/src/System.Net.Http.Formatting/packages.config
index 992a6e6d0..1ff2795f6 100644
--- a/src/System.Net.Http.Formatting/packages.config
+++ b/src/System.Net.Http.Formatting/packages.config
@@ -1,4 +1,9 @@
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/System.Web.Http.Cors/CorsHttpConfigurationExtensions.cs b/src/System.Web.Http.Cors/CorsHttpConfigurationExtensions.cs
index 3bf6631b5..42190f97b 100644
--- a/src/System.Web.Http.Cors/CorsHttpConfigurationExtensions.cs
+++ b/src/System.Web.Http.Cors/CorsHttpConfigurationExtensions.cs
@@ -26,7 +26,17 @@ public static class CorsHttpConfigurationExtensions
/// The .
public static void EnableCors(this HttpConfiguration httpConfiguration)
{
- EnableCors(httpConfiguration, null);
+ EnableCors(httpConfiguration, null, false);
+ }
+
+ ///
+ /// Enables the support for CORS.
+ ///
+ /// The .
+ /// Indicates whether upstream exceptions should be rethrown
+ public static void EnableCors(this HttpConfiguration httpConfiguration, bool rethrowExceptions)
+ {
+ EnableCors(httpConfiguration, null, rethrowExceptions);
}
///
@@ -34,8 +44,20 @@ public static void EnableCors(this HttpConfiguration httpConfiguration)
///
/// The .
/// The default .
- /// httpConfiguration
public static void EnableCors(this HttpConfiguration httpConfiguration, ICorsPolicyProvider defaultPolicyProvider)
+ {
+ EnableCors(httpConfiguration, defaultPolicyProvider, false);
+ }
+
+ ///
+ /// Enables the support for CORS.
+ ///
+ /// The .
+ /// The default .
+ /// Indicates whether upstream exceptions should be rethrown
+ /// httpConfiguration
+ public static void EnableCors(this HttpConfiguration httpConfiguration, ICorsPolicyProvider defaultPolicyProvider,
+ bool rethrowExceptions)
{
if (httpConfiguration == null)
{
@@ -49,11 +71,11 @@ public static void EnableCors(this HttpConfiguration httpConfiguration, ICorsPol
httpConfiguration.SetCorsPolicyProviderFactory(policyProviderFactory);
}
- AddCorsMessageHandler(httpConfiguration);
+ AddCorsMessageHandler(httpConfiguration, rethrowExceptions);
}
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Caller owns the disposable object")]
- private static void AddCorsMessageHandler(this HttpConfiguration httpConfiguration)
+ private static void AddCorsMessageHandler(this HttpConfiguration httpConfiguration, bool rethrowExceptions)
{
object corsEnabled;
if (!httpConfiguration.Properties.TryGetValue(CorsEnabledKey, out corsEnabled))
@@ -64,7 +86,7 @@ private static void AddCorsMessageHandler(this HttpConfiguration httpConfigurati
if (!config.Properties.TryGetValue(CorsEnabledKey, out corsEnabled))
{
// Execute this in the Initializer to ensure that the CorsMessageHandler is added last.
- config.MessageHandlers.Add(new CorsMessageHandler(config));
+ config.MessageHandlers.Add(new CorsMessageHandler(config, rethrowExceptions));
ITraceWriter traceWriter = config.Services.GetTraceWriter();
diff --git a/src/System.Web.Http.Cors/CorsMessageHandler.cs b/src/System.Web.Http.Cors/CorsMessageHandler.cs
index 5d683ca26..5308ee340 100644
--- a/src/System.Web.Http.Cors/CorsMessageHandler.cs
+++ b/src/System.Web.Http.Cors/CorsMessageHandler.cs
@@ -18,13 +18,24 @@ namespace System.Web.Http.Cors
public class CorsMessageHandler : DelegatingHandler
{
private HttpConfiguration _httpConfiguration;
+ private bool _rethrowExceptions;
///
/// Initializes a new instance of the class.
///
/// The .
/// httpConfiguration
- public CorsMessageHandler(HttpConfiguration httpConfiguration)
+ public CorsMessageHandler(HttpConfiguration httpConfiguration) : this(httpConfiguration, false)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The .
+ /// Indicates whether upstream exceptions should be rethrown
+ /// httpConfiguration
+ public CorsMessageHandler(HttpConfiguration httpConfiguration, bool rethrowExceptions)
{
if (httpConfiguration == null)
{
@@ -32,6 +43,7 @@ public CorsMessageHandler(HttpConfiguration httpConfiguration)
}
_httpConfiguration = httpConfiguration;
+ _rethrowExceptions = rethrowExceptions;
}
///
@@ -60,6 +72,11 @@ protected async override Task SendAsync(HttpRequestMessage
}
catch (Exception exception)
{
+ if (_rethrowExceptions)
+ {
+ throw;
+ }
+
return HandleException(request, exception);
}
}
diff --git a/src/System.Web.Http.Owin/HttpMessageHandlerAdapter.cs b/src/System.Web.Http.Owin/HttpMessageHandlerAdapter.cs
index b8c6fc648..ac118a754 100644
--- a/src/System.Web.Http.Owin/HttpMessageHandlerAdapter.cs
+++ b/src/System.Web.Http.Owin/HttpMessageHandlerAdapter.cs
@@ -275,7 +275,7 @@ private static async Task CreateBufferedRequestContentAsync(IOwinRe
}
else
{
- buffer = new MemoryStream(contentLength.Value);
+ buffer = new MemoryStream(Math.Min(4 * 1024, contentLength.Value));
}
cancellationToken.ThrowIfCancellationRequested();
diff --git a/src/System.Web.Http.Owin/OwinHttpRequestContext.cs b/src/System.Web.Http.Owin/OwinHttpRequestContext.cs
index a2321a2ec..d76c8a19c 100644
--- a/src/System.Web.Http.Owin/OwinHttpRequestContext.cs
+++ b/src/System.Web.Http.Owin/OwinHttpRequestContext.cs
@@ -182,7 +182,7 @@ public override string VirtualPathRoot
{
// Set the virtual path root for link resolution and link generation to work
// OWIN spec requires request path base to be either the empty string or start with "/"
- string requestPathBase = _context.Request.PathBase.ToString();
+ string requestPathBase = _context.Request.PathBase.Value;
_virtualPathRoot = String.IsNullOrEmpty(requestPathBase) ? "/" : requestPathBase;
_virtualPathRootSet = true;
}
diff --git a/src/System.Web.Http.Owin/PassiveAuthenticationMessageHandler.cs b/src/System.Web.Http.Owin/PassiveAuthenticationMessageHandler.cs
index c1587e537..daf526bd4 100644
--- a/src/System.Web.Http.Owin/PassiveAuthenticationMessageHandler.cs
+++ b/src/System.Web.Http.Owin/PassiveAuthenticationMessageHandler.cs
@@ -9,9 +9,7 @@
using System.Threading.Tasks;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
-using System.Web.Http.Hosting;
using System.Web.Http.Owin.Properties;
-using Microsoft.Owin;
using Microsoft.Owin.Security;
namespace System.Web.Http.Owin
@@ -37,27 +35,36 @@ protected override async Task SendAsync(HttpRequestMessage
throw new ArgumentNullException("request");
}
- SetCurrentPrincipalToAnonymous(request);
-
- HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
+ HttpResponseMessage response;
+ var previousPrincipal = SetCurrentPrincipal(request, _anonymousPrincipal.Value);
+ try
+ {
+ response = await base.SendAsync(request, cancellationToken);
+ }
+ finally
+ {
+ SetCurrentPrincipal(request, previousPrincipal);
+ }
SuppressDefaultAuthenticationChallenges(request);
return response;
}
- private static void SetCurrentPrincipalToAnonymous(HttpRequestMessage request)
+ private static IPrincipal SetCurrentPrincipal(HttpRequestMessage request, IPrincipal principal)
{
Contract.Assert(request != null);
HttpRequestContext requestContext = request.GetRequestContext();
-
if (requestContext == null)
{
throw new ArgumentException(OwinResources.Request_RequestContextMustNotBeNull, "request");
}
- requestContext.Principal = _anonymousPrincipal.Value;
+ var previousPrincipal = requestContext.Principal;
+ requestContext.Principal = principal;
+
+ return previousPrincipal;
}
private static void SuppressDefaultAuthenticationChallenges(HttpRequestMessage request)
diff --git a/src/System.Web.Http.Owin/System.Web.Http.Owin.csproj b/src/System.Web.Http.Owin/System.Web.Http.Owin.csproj
index 40565650e..ae8d5176d 100644
--- a/src/System.Web.Http.Owin/System.Web.Http.Owin.csproj
+++ b/src/System.Web.Http.Owin/System.Web.Http.Owin.csproj
@@ -14,7 +14,7 @@
- ..\..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll
+ ..\..\packages\Microsoft.Owin.4.2.2\lib\net45\Microsoft.Owin.dll..\..\packages\Owin.1.0\lib\net40\Owin.dll
diff --git a/src/System.Web.Http.Owin/packages.config b/src/System.Web.Http.Owin/packages.config
index 57b34eaa5..a288e84ae 100644
--- a/src/System.Web.Http.Owin/packages.config
+++ b/src/System.Web.Http.Owin/packages.config
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/src/System.Web.Http.SignalR/System.Web.Http.SignalR.csproj b/src/System.Web.Http.SignalR/System.Web.Http.SignalR.csproj
index 8a1146a62..e8aeaff50 100644
--- a/src/System.Web.Http.SignalR/System.Web.Http.SignalR.csproj
+++ b/src/System.Web.Http.SignalR/System.Web.Http.SignalR.csproj
@@ -16,9 +16,10 @@
..\..\packages\Microsoft.AspNet.SignalR.Core.1.0.0\lib\net40\Microsoft.AspNet.SignalR.Core.dll
-
+
+ ..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dllFalse
- ..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll
+ False
diff --git a/src/System.Web.Http.SignalR/packages.config b/src/System.Web.Http.SignalR/packages.config
index 6342f7fc0..253454ad2 100644
--- a/src/System.Web.Http.SignalR/packages.config
+++ b/src/System.Web.Http.SignalR/packages.config
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/src/System.Web.Http.Tracing/System.Web.Http.Tracing.csproj b/src/System.Web.Http.Tracing/System.Web.Http.Tracing.csproj
index 7dcda357c..139282520 100644
--- a/src/System.Web.Http.Tracing/System.Web.Http.Tracing.csproj
+++ b/src/System.Web.Http.Tracing/System.Web.Http.Tracing.csproj
@@ -13,9 +13,10 @@
$(DefineConstants);ASPNETMVC
-
+
+ ..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dllFalse
- ..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll
+ False
diff --git a/src/System.Web.Http.Tracing/packages.config b/src/System.Web.Http.Tracing/packages.config
index 992a6e6d0..093dcd239 100644
--- a/src/System.Web.Http.Tracing/packages.config
+++ b/src/System.Web.Http.Tracing/packages.config
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/src/System.Web.Http.WebHost/HttpControllerHandler.cs b/src/System.Web.Http.WebHost/HttpControllerHandler.cs
index 9a78f57f3..213f0e982 100644
--- a/src/System.Web.Http.WebHost/HttpControllerHandler.cs
+++ b/src/System.Web.Http.WebHost/HttpControllerHandler.cs
@@ -717,14 +717,17 @@ public Task WriteToStreamAsync(Stream stream, TransportContext context)
return SerializeToStreamAsync(stream, context);
}
- public bool TryCalculateLength(out long length)
+ public Task GetContentReadStreamAsync()
{
- return TryComputeLength(out length);
+ return CreateContentReadStreamAsync();
}
- public Task GetContentReadStreamAsync()
+ protected override bool TryComputeLength(out long length)
{
- return CreateContentReadStreamAsync();
+ // Do not attempt to calculate length because SeekableBufferedRequestStream (for example)
+ // may report 0 until the underlying Stream has been read to end.
+ length = 0L;
+ return false;
}
}
@@ -762,7 +765,10 @@ protected override Task CreateContentReadStreamAsync()
protected override bool TryComputeLength(out long length)
{
- return StreamContent.TryCalculateLength(out length);
+ // Do not attempt to calculate length because SeekableBufferedRequestStream (for example)
+ // may report 0 until the underlying Stream has been read to end.
+ length = 0L;
+ return false;
}
}
}
diff --git a/src/System.Web.Http/Batch/DefaultHttpBatchHandler.cs b/src/System.Web.Http/Batch/DefaultHttpBatchHandler.cs
index ca5412816..62171a318 100644
--- a/src/System.Web.Http/Batch/DefaultHttpBatchHandler.cs
+++ b/src/System.Web.Http/Batch/DefaultHttpBatchHandler.cs
@@ -187,7 +187,7 @@ public virtual async Task> ParseBatchRequestsAsync(Htt
foreach (HttpContent httpContent in streamProvider.Contents)
{
cancellationToken.ThrowIfCancellationRequested();
- HttpRequestMessage innerRequest = await httpContent.ReadAsHttpRequestMessageAsync();
+ HttpRequestMessage innerRequest = request.RequestUri == null ? await httpContent.ReadAsHttpRequestMessageAsync() : await httpContent.ReadAsHttpRequestMessageAsync(request.RequestUri.Scheme);
innerRequest.CopyBatchRequestProperties(request);
requests.Add(innerRequest);
}
diff --git a/src/System.Web.Http/Controllers/ReflectedHttpActionDescriptor.cs b/src/System.Web.Http/Controllers/ReflectedHttpActionDescriptor.cs
index d663000b6..f1714ff77 100644
--- a/src/System.Web.Http/Controllers/ReflectedHttpActionDescriptor.cs
+++ b/src/System.Web.Http/Controllers/ReflectedHttpActionDescriptor.cs
@@ -400,7 +400,7 @@ private static Func