Skip to content

Commit

Permalink
Merge tag 'v3.2.8' into 'main' (aspnet#319)
Browse files Browse the repository at this point in the history
- see https://github.com/aspnet/AspNetWebStack/releases/tag/v3.2.8 for prominent issues resolved as well as a more detailed list of changes

Co-authored-by: Pranav Krishnamoorthy <prkrishn@microsoft.com>
Co-authored-by: Pranav K <prkrishn@hotmail.com>
Co-authored-by: dotnet-bot <dotnet-bot@microsoft.com>
  • Loading branch information
4 people authored Apr 15, 2022
1 parent f7321b3 commit 646f452
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace System.Net.Http.Formatting.Parsers
{
/// <summary>
/// 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.
/// </summary>
internal class InternetMessageFormatHeaderParser
{
Expand Down Expand Up @@ -76,7 +76,7 @@ private enum HeaderFieldState

/// <summary>
/// Parse a buffer of RFC 5322 style header fields and add them to the <see cref="HttpHeaders"/> 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.
/// </summary>
/// <param name="buffer">Request buffer from where request is read</param>
Expand Down Expand Up @@ -283,7 +283,7 @@ private static ParserState ParseHeaderFields(
}

/// <summary>
/// Maintains information about the current header field being parsed.
/// Maintains information about the current header field being parsed.
/// </summary>
private class CurrentHeaderFieldStore
{
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private static async Task<HttpRequestMessage> 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];
Expand Down
33 changes: 23 additions & 10 deletions src/System.Net.Http.Formatting/PushStreamContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace System.Net.Http
{
/// <summary>
/// Provides an <see cref="HttpContent"/> implementation that exposes an output <see cref="Stream"/>
/// 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
/// <see cref="StreamContent"/> where data is pulled and not pushed.
/// </summary>
public class PushStreamContent : HttpContent
Expand All @@ -24,8 +24,8 @@ public class PushStreamContent : HttpContent
/// <summary>
/// Initializes a new instance of the <see cref="PushStreamContent"/> class. The
/// <paramref name="onStreamAvailable"/> 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.
/// </summary>
/// <param name="onStreamAvailable">The action to call when an output stream is available.</param>
Expand All @@ -35,10 +35,11 @@ public PushStreamContent(Action<Stream, HttpContent, TransportContext> onStreamA
}

/// <summary>
/// Initializes a new instance of the <see cref="PushStreamContent"/> class.
/// Initializes a new instance of the <see cref="PushStreamContent"/> class.
/// </summary>
/// <param name="onStreamAvailable">The action to call when an output stream is available. The stream is automatically
/// closed when the return task is completed.</param>
/// <param name="onStreamAvailable">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.</param>
public PushStreamContent(Func<Stream, HttpContent, TransportContext, Task> onStreamAvailable)
: this(onStreamAvailable, (MediaTypeHeaderValue)null)
{
Expand All @@ -47,6 +48,8 @@ public PushStreamContent(Func<Stream, HttpContent, TransportContext, Task> onStr
/// <summary>
/// Initializes a new instance of the <see cref="PushStreamContent"/> class with the given media type.
/// </summary>
/// <param name="onStreamAvailable">The action to call when an output stream is available.</param>
/// <param name="mediaType">The value of the Content-Type content header on an HTTP response.</param>
public PushStreamContent(Action<Stream, HttpContent, TransportContext> onStreamAvailable, string mediaType)
: this(Taskify(onStreamAvailable), new MediaTypeHeaderValue(mediaType))
{
Expand All @@ -55,6 +58,10 @@ public PushStreamContent(Action<Stream, HttpContent, TransportContext> onStreamA
/// <summary>
/// Initializes a new instance of the <see cref="PushStreamContent"/> class with the given media type.
/// </summary>
/// <param name="onStreamAvailable">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.</param>
/// <param name="mediaType">The value of the Content-Type content header on an HTTP response.</param>
public PushStreamContent(Func<Stream, HttpContent, TransportContext, Task> onStreamAvailable, string mediaType)
: this(onStreamAvailable, new MediaTypeHeaderValue(mediaType))
{
Expand All @@ -63,6 +70,8 @@ public PushStreamContent(Func<Stream, HttpContent, TransportContext, Task> onStr
/// <summary>
/// Initializes a new instance of the <see cref="PushStreamContent"/> class with the given <see cref="MediaTypeHeaderValue"/>.
/// </summary>
/// <param name="onStreamAvailable">The action to call when an output stream is available.</param>
/// <param name="mediaType">The value of the Content-Type content header on an HTTP response.</param>
public PushStreamContent(Action<Stream, HttpContent, TransportContext> onStreamAvailable, MediaTypeHeaderValue mediaType)
: this(Taskify(onStreamAvailable), mediaType)
{
Expand All @@ -71,6 +80,10 @@ public PushStreamContent(Action<Stream, HttpContent, TransportContext> onStreamA
/// <summary>
/// Initializes a new instance of the <see cref="PushStreamContent"/> class with the given <see cref="MediaTypeHeaderValue"/>.
/// </summary>
/// <param name="onStreamAvailable">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.</param>
/// <param name="mediaType">The value of the Content-Type content header on an HTTP response.</param>
public PushStreamContent(Func<Stream, HttpContent, TransportContext, Task> onStreamAvailable, MediaTypeHeaderValue mediaType)
{
if (onStreamAvailable == null)
Expand Down Expand Up @@ -98,8 +111,8 @@ private static Func<Stream, HttpContent, TransportContext, Task> Taskify(
}

/// <summary>
/// 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.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to which to write.</param>
Expand Down Expand Up @@ -142,8 +155,8 @@ public CompleteTaskOnCloseStream(Stream innerStream, TaskCompletionSource<bool>

#if NETFX_CORE
[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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/System.Web.Http.Owin/HttpMessageHandlerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private static async Task<HttpContent> CreateBufferedRequestContentAsync(IOwinRe
}
else
{
buffer = new MemoryStream(contentLength.Value);
buffer = new MemoryStream(Math.Min(4 * 1024, contentLength.Value));
}

cancellationToken.ThrowIfCancellationRequested();
Expand Down
2 changes: 0 additions & 2 deletions src/WebApiHelpPage/VB/WebApiHelpPage.VB.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<owners>Microsoft</owners>
<projectUrl>http://www.asp.net/web-api</projectUrl>
<repository type="git" url="https://github.com/aspnet/AspNetWebStack"/>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<licenseUrl>http://www.microsoft.com/web/webpi/eula/mvc4extensions_prerelease_eula.htm</licenseUrl>
<description>The ASP.NET Web API Help Page automatically generates help page content for the web APIs on your site. Visitors to your help page can use this content to learn how to call your web APIs. Everything generated by the help page is fully customizable using ASP.NET MVC and Razor. ASP.NET Web API Help Page is a great addition to any ASP.NET Web API project.</description>
<summary>The ASP.NET Web API Help Page automatically generates help page content for the web APIs on your site.</summary>
<dependencies>
Expand Down
4 changes: 1 addition & 3 deletions src/WebApiHelpPage/WebApiHelpPage.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<owners>Microsoft</owners>
<projectUrl>http://www.asp.net/web-api</projectUrl>
<repository type="git" url="https://github.com/aspnet/AspNetWebStack"/>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<licenseUrl>http://www.microsoft.com/web/webpi/eula/mvc4extensions_prerelease_eula.htm</licenseUrl>
<description>The ASP.NET Web API Help Page automatically generates help page content for the web APIs on your site. Visitors to your help page can use this content to learn how to call your web APIs. Everything generated by the help page is fully customizable using ASP.NET MVC and Razor. ASP.NET Web API Help Page is a great addition to any ASP.NET Web API project.</description>
<summary>The ASP.NET Web API Help Page automatically generates help page content for the web APIs on your site.</summary>
<dependencies>
Expand All @@ -22,7 +20,7 @@
<frameworkAssembly assemblyName="System.ComponentModel.DataAnnotations" />
</frameworkAssemblies>
<language>en-US</language>
<tags>Microsoft AspNet WebApi AspNetWebApi HelpPage</tags>
<tags>Microsoft AspNet WebApi AspNetWebApi HelpPage</tags>
</metadata>
<files>
<file src="Areas\HelpPage\App_Start\HelpPageConfig.cs.pp" target="content\Areas\HelpPage\App_Start\HelpPageConfig.cs.pp" />
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.TestCommon/PlatformInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static Platform GetPlatform()
{
if (Type.GetType(_netCore20TypeName, throwOnError: false) != null)
{
// Treat .NET Core 2.0 as a .NET 4.5 superset though internal types are different.
// Treat .NET Core 2.1 as a .NET 4.5 superset though internal types are different.
return Platform.Net45;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),Runtime.sln))\tools\WebStack.settings.targets" />
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
<RootNamespace>System.Net.Http</RootNamespace>
<AssemblyName>System.Net.Http.Formatting.NetStandard.Test</AssemblyName>
<OutputPath>..\..\bin\$(Configuration)\Test\</OutputPath>
Expand Down
4 changes: 2 additions & 2 deletions test/System.Net.Http.Formatting.Test/DataSets/HttpTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@ public static TheoryDataSet<string, string, bool> ReadAndWriteCorrectCharacterEn
{ "This is a test 激光這兩個字是甚麼意思 string written using utf-8", "utf-8", true },
{ "This is a test 激光這兩個字是甚麼意思 string written using utf-16", "utf-16", true },
{ "This is a test 激光這兩個字是甚麼意思 string written using utf-32", "utf-32", false },
#if !NETCOREAPP2_0 // shift_jis and iso-2022-kr are not supported when running on .NET Core 2.0.
#if !NETCOREAPP // shift_jis and iso-2022-kr are not supported when running on .NET Core 2.1.
{ "This is a test 激光這兩個字是甚麼意思 string written using shift_jis", "shift_jis", false },
#endif
{ "This is a test æøå string written using iso-8859-1", "iso-8859-1", false },
#if !NETCOREAPP2_0
#if !NETCOREAPP
{ "This is a test 레이저 단어 뜻 string written using iso-2022-kr", "iso-2022-kr", false },
#endif
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_DBNullAsNull(
Assert.Null(readObj);
}

#if !NETCOREAPP2_0 // DBNull not serializable on .NET Core 2.0 except at top level (using BsonMediaTypeformatter special case).
#if !NETCOREAPP // DBNull not serializable on .NET Core 2.1 except at top level (using BsonMediaTypeformatter special case).
[Theory]
[TestDataSet(typeof(JsonMediaTypeFormatterTests), "DBNullAsObjectTestDataCollection", TestDataVariations.AsDictionary)]
public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_DBNullAsNull_Dictionary(Type variationType, object testData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_KnownTypes(Ty
}
}

#if !NETCOREAPP2_0 // DBNull not serializable on .NET Core 2.0.
#if !NETCOREAPP // DBNull not serializable on .NET Core 2.1.
// Test alternate null value
[Fact]
public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_DBNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync(Type variatio
}
}

#if !NETCOREAPP2_0 // DBNull not serializable on .NET Core 2.0.
#if !NETCOREAPP // DBNull not serializable on .NET Core 2.1.
// Test alternate null value; always serialized as "null"
[Theory]
[TestDataSet(typeof(JsonMediaTypeFormatterTests), "DBNullAsObjectTestDataCollection", TestDataVariations.AllSingleInstances)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public Task DeserializingDeepArraysThrows()
// low surrogate not preceded by high surrogate
[InlineData("ABC \\udc00\\ud800 DEF", "ABC \ufffd\ufffd DEF")]
// make sure unencoded invalid surrogate characters don't make it through
#if NETCOREAPP2_0 // Json.NET uses its regular invalid Unicode character on .NET Core 2.0; '?' elsewhere.
#if NETCOREAPP // Json.NET uses its regular invalid Unicode character on .NET Core 2.1; '?' elsewhere.
[InlineData("\udc00\ud800\ud800", "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd")]
#else
[InlineData("\udc00\ud800\ud800", "??????")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class XmlMediaTypeFormatterTests : MediaTypeFormatterTestBase<XmlMediaTyp
Int32.MaxValue,
Int64.MinValue,
Int64.MaxValue,
#if !NETCOREAPP2_0 // DBNull not serializable on .NET Core 2.0.
#if !NETCOREAPP // DBNull not serializable on .NET Core 2.1.
DBNull.Value,
#endif
});
Expand Down Expand Up @@ -484,7 +484,7 @@ public async Task ReadFromStream_AsyncRoundTripsWriteToStreamUsingDataContractSe
}
}

#if !NETCOREAPP2_0 // DBNull not serializable on .NET Core 2.0.
#if !NETCOREAPP // DBNull not serializable on .NET Core 2.1.
[Fact]
public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsyncUsingDataContractSerializer_DBNull()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,50 @@ public Task ReadAsHttpResponseMessageAsync_LargeHeaderSize()
}

[Fact]
public Task ReadAsHttpRequestMessageAsync_LargeHeaderSize()
public async Task ReadAsHttpRequestMessageAsync_LargeHeaderSize()
{
string cookieValue = string.Format("{0}={1}", new String('a', 16 * 1024), new String('b', 16 * 1024));
string[] request = new[] {
@"GET / HTTP/1.1",
@"Host: msdn.microsoft.com",
String.Format("Cookie: {0}={1}", new String('a', 16 * 1024), new String('b', 16 * 1024))
string.Format("Cookie: {0}", cookieValue),
};

HttpContent content = CreateContent(true, request, "sample body");
var httpRequestMessage = await content.ReadAsHttpRequestMessageAsync(Uri.UriSchemeHttp, 64 * 1024, 64 * 1024);

Assert.Equal(HttpMethod.Get, httpRequestMessage.Method);
Assert.Equal("/", httpRequestMessage.RequestUri.PathAndQuery);
Assert.Equal("msdn.microsoft.com", httpRequestMessage.Headers.Host);
IEnumerable<string> actualCookieValue;
Assert.True(httpRequestMessage.Headers.TryGetValues("Cookie", out actualCookieValue));
Assert.Equal(cookieValue, Assert.Single(actualCookieValue));
}

[Fact]
public async Task ReadAsHttpRequestMessageAsync_LargeHttpRequestLine()
{
string requestPath = string.Format("/myurl?{0}={1}", new string('a', 4 * 1024), new string('b', 4 * 1024));
string cookieValue = string.Format("{0}={1}", new String('a', 4 * 1024), new String('b', 4 * 1024));
string[] request = new[]
{
string.Format("GET {0} HTTP/1.1", requestPath),
@"Host: msdn.microsoft.com",
string.Format("Cookie: {0}", cookieValue),
};

HttpContent content = CreateContent(true, request, "sample body");
return content.ReadAsHttpRequestMessageAsync(Uri.UriSchemeHttp, 64 * 1024, 64 * 1024);
var httpRequestMessage = await content.ReadAsHttpRequestMessageAsync(
Uri.UriSchemeHttp,
bufferSize: 64 * 1024,
maxHeaderSize: 64 * 1024);

Assert.Equal(HttpMethod.Get, httpRequestMessage.Method);
Assert.Equal(requestPath, httpRequestMessage.RequestUri.PathAndQuery);
Assert.Equal("msdn.microsoft.com", httpRequestMessage.Headers.Host);
IEnumerable<string> actualCookieValue;
Assert.True(httpRequestMessage.Headers.TryGetValues("Cookie", out actualCookieValue));
Assert.Equal(cookieValue, Assert.Single(actualCookieValue));
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace System.Net.Http.Internal
{
public class HttpValueCollectionTest
{
#if !NETCOREAPP2_0 // Unused on .NET Core 2.0.
#if !NETCOREAPP // Unused on .NET Core 2.1.
private static readonly int _maxCollectionKeys = 1000;
#endif

Expand Down Expand Up @@ -148,7 +148,7 @@ public void Create_CreatesEmptyCollection()
Assert.Empty(nvc);
}

#if !NETCOREAPP2_0 // DBNull not serializable on .NET Core 2.0.
#if !NETCOREAPP // DBNull not serializable on .NET Core 2.1.
// This set of tests requires running on a separate appdomain so we don't
// touch the static property MediaTypeFormatter.MaxHttpCollectionKeys.
[Fact]
Expand Down
Loading

0 comments on commit 646f452

Please sign in to comment.