Remove Logging dependency from the http parser (#1780)
* Remove Logging dependency from the http parser
This commit is contained in:
parent
c2f15fcac3
commit
0755495ce5
|
|
@ -5,18 +5,21 @@ using System.Runtime.CompilerServices;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Internal.System;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||
{
|
||||
public class HttpParser<TRequestHandler> : IHttpParser<TRequestHandler> where TRequestHandler : IHttpHeadersHandler, IHttpRequestLineHandler
|
||||
{
|
||||
public HttpParser(IKestrelTrace log)
|
||||
private bool _showErrorDetails;
|
||||
|
||||
public HttpParser() : this(showErrorDetails: true)
|
||||
{
|
||||
Log = log;
|
||||
}
|
||||
|
||||
private IKestrelTrace Log { get; }
|
||||
public HttpParser(bool showErrorDetails)
|
||||
{
|
||||
_showErrorDetails = showErrorDetails;
|
||||
}
|
||||
|
||||
// byte types don't have a data type annotation so we pre-cast them; to avoid in-place casts
|
||||
private const byte ByteCR = (byte)'\r';
|
||||
|
|
@ -488,7 +491,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
|||
private unsafe BadHttpRequestException GetInvalidRequestException(RequestRejectionReason reason, byte* detail, int length)
|
||||
=> BadHttpRequestException.GetException(
|
||||
reason,
|
||||
Log.IsEnabled(LogLevel.Information)
|
||||
_showErrorDetails
|
||||
? new Span<byte>(detail, length).GetAsciiStringEscaped(Constants.MaxExceptionDetailSize)
|
||||
: string.Empty);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
|
|||
return new ServiceContext
|
||||
{
|
||||
Log = trace,
|
||||
HttpParserFactory = frameParser => new HttpParser<FrameAdapter>(frameParser.Frame.ServiceContext.Log),
|
||||
HttpParserFactory = frameParser => new HttpParser<FrameAdapter>(frameParser.Frame.ServiceContext.Log.IsEnabled(LogLevel.Information)),
|
||||
ThreadPool = threadPool,
|
||||
SystemClock = systemClock,
|
||||
DateHeaderValueManager = dateHeaderValueManager,
|
||||
|
|
@ -207,4 +207,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -417,7 +417,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
|||
Assert.Equal(buffer.End, examined);
|
||||
}
|
||||
|
||||
private IHttpParser<RequestHandler> CreateParser(IKestrelTrace log) => new HttpParser<RequestHandler>(log);
|
||||
private IHttpParser<RequestHandler> CreateParser(IKestrelTrace log) => new HttpParser<RequestHandler>(log.IsEnabled(LogLevel.Information));
|
||||
|
||||
public static IEnumerable<string[]> RequestLineValidData => HttpParsingData.RequestLineValidData;
|
||||
|
||||
|
|
@ -463,4 +463,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
|||
DateHeaderValueManager = new DateHeaderValueManager(),
|
||||
ServerOptions = new KestrelServerOptions(),
|
||||
Log = new MockTrace(),
|
||||
HttpParserFactory = f => new HttpParser<FrameAdapter>(log: null)
|
||||
HttpParserFactory = f => new HttpParser<FrameAdapter>()
|
||||
};
|
||||
var frameContext = new FrameContext
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
|||
|
||||
public class KestrelHttpParserBenchmark : IHttpRequestLineHandler, IHttpHeadersHandler
|
||||
{
|
||||
private readonly HttpParser<Adapter> _parser = new HttpParser<Adapter>(log: null);
|
||||
private readonly HttpParser<Adapter> _parser = new HttpParser<Adapter>();
|
||||
|
||||
private ReadableBuffer _buffer;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
|||
{
|
||||
var serviceContext = new ServiceContext
|
||||
{
|
||||
HttpParserFactory = f => new HttpParser<FrameAdapter>(f.Frame.ServiceContext.Log),
|
||||
HttpParserFactory = f => new HttpParser<FrameAdapter>(),
|
||||
ServerOptions = new KestrelServerOptions()
|
||||
};
|
||||
var frameContext = new FrameContext
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
|||
{
|
||||
var serviceContext = new ServiceContext
|
||||
{
|
||||
HttpParserFactory = f => new HttpParser<FrameAdapter>(f.Frame.ServiceContext.Log),
|
||||
HttpParserFactory = f => new HttpParser<FrameAdapter>(),
|
||||
ServerOptions = new KestrelServerOptions()
|
||||
};
|
||||
var frameContext = new FrameContext
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
|||
DateHeaderValueManager = new DateHeaderValueManager(),
|
||||
ServerOptions = new KestrelServerOptions(),
|
||||
Log = new MockTrace(),
|
||||
HttpParserFactory = f => new HttpParser<FrameAdapter>(log: null)
|
||||
HttpParserFactory = f => new HttpParser<FrameAdapter>()
|
||||
};
|
||||
|
||||
var frameContext = new FrameContext
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNetCore.Testing
|
||||
{
|
||||
|
|
@ -20,7 +21,7 @@ namespace Microsoft.AspNetCore.Testing
|
|||
DateHeaderValueManager = new DateHeaderValueManager(SystemClock);
|
||||
ConnectionManager = new FrameConnectionManager(Log);
|
||||
DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String;
|
||||
HttpParserFactory = frameAdapter => new HttpParser<FrameAdapter>(frameAdapter.Frame.ServiceContext.Log);
|
||||
HttpParserFactory = frameAdapter => new HttpParser<FrameAdapter>(frameAdapter.Frame.ServiceContext.Log.IsEnabled(LogLevel.Information));
|
||||
ServerOptions = new KestrelServerOptions
|
||||
{
|
||||
AddServerHeader = false
|
||||
|
|
|
|||
Loading…
Reference in New Issue