Skip to content

Configure max request line size limits to be the same as maxHeaderSize #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bet you're missing out var 😀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that and it does not work in C# 5. This is like getting -ve 💯 points.

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