Skip to content

Commit d15c3a5

Browse files
committed
Feedback
1 parent 65dd796 commit d15c3a5

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/Servers/Kestrel/Core/src/Internal/Http/Http1Connection.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,15 @@ private void OnOriginFormTarget(HttpMethod method, HttpVersion version, Span<byt
290290
{
291291
// Read raw target before mutating memory.
292292
var previousValue = _parsedRawTarget;
293-
if (previousValue == null || previousValue.Length != target.Length ||
293+
if (DisableStringReuse || previousValue == null || previousValue.Length != target.Length ||
294294
!StringUtilities.BytesOrdinalEqualsStringAndAscii(previousValue, target))
295295
{
296296
// The previous string does not match what the bytes would convert to,
297297
// so we will need to generate a new string.
298298
RawTarget = _parsedRawTarget = target.GetAsciiStringNonNullCharacters();
299299

300300
previousValue = _parsedQueryString;
301-
if (previousValue == null || previousValue.Length != query.Length ||
301+
if (DisableStringReuse || previousValue == null || previousValue.Length != query.Length ||
302302
!StringUtilities.BytesOrdinalEqualsStringAndAscii(previousValue, query))
303303
{
304304
// The previous string does not match what the bytes would convert to,
@@ -363,7 +363,7 @@ private void OnAuthorityFormTarget(HttpMethod method, Span<byte> target)
363363
// Allowed characters in the 'host + port' section of authority.
364364
// See https://tools.ietf.org/html/rfc3986#section-3.2
365365
var previousValue = _parsedRawTarget;
366-
if (previousValue == null || previousValue.Length != target.Length ||
366+
if (DisableStringReuse || previousValue == null || previousValue.Length != target.Length ||
367367
!StringUtilities.BytesOrdinalEqualsStringAndAscii(previousValue, target))
368368
{
369369
// The previous string does not match what the bytes would convert to,
@@ -416,7 +416,7 @@ private void OnAbsoluteFormTarget(Span<byte> target, Span<byte> query)
416416
// HTTP/1.1 clients will only send them in requests to proxies.
417417

418418
var previousValue = _parsedRawTarget;
419-
if (previousValue == null || previousValue.Length != target.Length ||
419+
if (DisableStringReuse || previousValue == null || previousValue.Length != target.Length ||
420420
!StringUtilities.BytesOrdinalEqualsStringAndAscii(previousValue, target))
421421
{
422422
// The previous string does not match what the bytes would convert to,
@@ -436,13 +436,17 @@ private void OnAbsoluteFormTarget(Span<byte> target, Span<byte> query)
436436
Path = _parsedPath = uri.LocalPath;
437437
// don't use uri.Query because we need the unescaped version
438438
previousValue = _parsedQueryString;
439-
if (previousValue == null || previousValue.Length != query.Length ||
439+
if (DisableStringReuse || previousValue == null || previousValue.Length != query.Length ||
440440
!StringUtilities.BytesOrdinalEqualsStringAndAscii(previousValue, query))
441441
{
442442
// The previous string does not match what the bytes would convert to,
443443
// so we will need to generate a new string.
444444
QueryString = _parsedQueryString = query.GetAsciiStringNonNullCharacters();
445445
}
446+
else
447+
{
448+
QueryString = _parsedQueryString;
449+
}
446450
}
447451
else
448452
{

src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
2525
{
2626
internal abstract partial class HttpProtocol : IDefaultHttpContextContainer, IHttpResponseControl
2727
{
28-
private const string DisableHeaderReuseSwitch = "Switch.Microsoft.AspNetCore.Kestrel.DisableHeaderReuse";
29-
private static readonly bool DisableHeaderReuse = GetDisableHeaderReuseSwitch();
28+
private const string DisableHeaderStringSwitch = "Switch.Microsoft.AspNetCore.Kestrel.DisableStringReuse";
29+
protected static readonly bool DisableStringReuse = GetDisableHeaderStringSwitch();
3030

3131
private static readonly byte[] _bytesConnectionClose = Encoding.ASCII.GetBytes("\r\nConnection: close");
3232
private static readonly byte[] _bytesConnectionKeepAlive = Encoding.ASCII.GetBytes("\r\nConnection: keep-alive");
@@ -77,7 +77,7 @@ public HttpProtocol(HttpConnectionContext context)
7777
_context = context;
7878

7979
ServerOptions = ServiceContext.ServerOptions;
80-
HttpRequestHeaders = new HttpRequestHeaders(reuseHeaderValues: !DisableHeaderReuse);
80+
HttpRequestHeaders = new HttpRequestHeaders(reuseHeaderValues: !DisableStringReuse);
8181
HttpResponseControl = this;
8282
}
8383

@@ -1505,9 +1505,9 @@ public async ValueTask<FlushResult> WriteAsyncAwaited(Task initializeTask, ReadO
15051505
}
15061506
}
15071507

1508-
private static bool GetDisableHeaderReuseSwitch()
1508+
private static bool GetDisableHeaderStringSwitch()
15091509
{
1510-
if (AppContext.TryGetSwitch(DisableHeaderReuseSwitch, out var disableHeaderReuse))
1510+
if (AppContext.TryGetSwitch(DisableHeaderStringSwitch, out var disableHeaderReuse))
15111511
{
15121512
return disableHeaderReuse;
15131513
}

0 commit comments

Comments
 (0)