Seal some internal derived classes (#9880)

This commit is contained in:
Ben Adams 2019-05-01 18:29:05 +01:00 committed by Chris Ross
parent 22affb4cf8
commit 86728ecc17
32 changed files with 36 additions and 47 deletions

View File

@ -6,14 +6,14 @@ using Microsoft.Extensions.Primitives;
namespace Microsoft.Net.Http.Headers namespace Microsoft.Net.Http.Headers
{ {
internal class CookieHeaderParser : HttpHeaderParser<CookieHeaderValue> internal sealed class CookieHeaderParser : HttpHeaderParser<CookieHeaderValue>
{ {
internal CookieHeaderParser(bool supportsMultipleValues) internal CookieHeaderParser(bool supportsMultipleValues)
: base(supportsMultipleValues) : base(supportsMultipleValues)
{ {
} }
public sealed override bool TryParseValue(StringSegment value, ref int index, out CookieHeaderValue parsedValue) public override bool TryParseValue(StringSegment value, ref int index, out CookieHeaderValue parsedValue)
{ {
parsedValue = null; parsedValue = null;
@ -27,8 +27,7 @@ namespace Microsoft.Net.Http.Headers
return SupportsMultipleValues; return SupportsMultipleValues;
} }
var separatorFound = false; var current = GetNextNonEmptyOrWhitespaceIndex(value, index, SupportsMultipleValues, out bool separatorFound);
var current = GetNextNonEmptyOrWhitespaceIndex(value, index, SupportsMultipleValues, out separatorFound);
if (separatorFound && !SupportsMultipleValues) if (separatorFound && !SupportsMultipleValues)
{ {

View File

@ -11,7 +11,7 @@ namespace Microsoft.Net.Http.Headers
// type to throw if 'null' gets added. Collection<T> internally uses List<T> which comes at some cost. In addition // type to throw if 'null' gets added. Collection<T> internally uses List<T> which comes at some cost. In addition
// Collection<T>.Add() calls List<T>.InsertItem() which is an O(n) operation (compared to O(1) for List<T>.Add()). // Collection<T>.Add() calls List<T>.InsertItem() which is an O(n) operation (compared to O(1) for List<T>.Add()).
// This type is only used for very small collections (1-2 items) to keep the impact of using Collection<T> small. // This type is only used for very small collections (1-2 items) to keep the impact of using Collection<T> small.
internal class ObjectCollection<T> : Collection<T> internal sealed class ObjectCollection<T> : Collection<T>
{ {
internal static readonly Action<T> DefaultValidator = CheckNotNull; internal static readonly Action<T> DefaultValidator = CheckNotNull;
internal static readonly ObjectCollection<T> EmptyReadOnlyCollection internal static readonly ObjectCollection<T> EmptyReadOnlyCollection
@ -57,22 +57,12 @@ namespace Microsoft.Net.Http.Headers
public bool IsReadOnly => ((ICollection<T>)this).IsReadOnly; public bool IsReadOnly => ((ICollection<T>)this).IsReadOnly;
protected override void ClearItems()
{
base.ClearItems();
}
protected override void InsertItem(int index, T item) protected override void InsertItem(int index, T item)
{ {
_validator(item); _validator(item);
base.InsertItem(index, item); base.InsertItem(index, item);
} }
protected override void RemoveItem(int index)
{
base.RemoveItem(index);
}
protected override void SetItem(int index, T item) protected override void SetItem(int index, T item)
{ {
_validator(item); _validator(item);

View File

@ -472,7 +472,7 @@ namespace Microsoft.AspNetCore.Http
=> string.IsNullOrEmpty(s) ? new PathString(s) : FromUriComponent(s); => string.IsNullOrEmpty(s) ? new PathString(s) : FromUriComponent(s);
} }
internal class PathStringConverter : TypeConverter internal sealed class PathStringConverter : TypeConverter
{ {
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
=> sourceType == typeof(string) => sourceType == typeof(string)

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Http.Internal
/// <summary> /// <summary>
/// A Stream that wraps another stream starting at a certain offset and reading for the given length. /// A Stream that wraps another stream starting at a certain offset and reading for the given length.
/// </summary> /// </summary>
internal class ReferenceReadStream : Stream internal sealed class ReferenceReadStream : Stream
{ {
private readonly Stream _inner; private readonly Stream _inner;
private readonly long _innerOffset; private readonly long _innerOffset;

View File

@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace Microsoft.AspNetCore.WebUtilities namespace Microsoft.AspNetCore.WebUtilities
{ {
internal class MultipartReaderStream : Stream internal sealed class MultipartReaderStream : Stream
{ {
private readonly MultipartBoundary _boundary; private readonly MultipartBoundary _boundary;
private readonly BufferedReadStream _innerStream; private readonly BufferedReadStream _innerStream;

View File

@ -10,7 +10,7 @@ using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal
{ {
internal class LoggingStream : Stream internal sealed class LoggingStream : Stream
{ {
private readonly Stream _inner; private readonly Stream _inner;
private readonly ILogger _logger; private readonly ILogger _logger;

View File

@ -10,7 +10,7 @@ using System.Buffers;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal
{ {
internal class RawStream : Stream internal sealed class RawStream : Stream
{ {
private readonly PipeReader _input; private readonly PipeReader _input;
private readonly PipeWriter _output; private readonly PipeWriter _output;

View File

@ -10,7 +10,7 @@ using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Core namespace Microsoft.AspNetCore.Server.Kestrel.Core
{ {
internal class AnyIPListenOptions : ListenOptions internal sealed class AnyIPListenOptions : ListenOptions
{ {
internal AnyIPListenOptions(int port) internal AnyIPListenOptions(int port)
: base(new IPEndPoint(IPAddress.IPv6Any, port)) : base(new IPEndPoint(IPAddress.IPv6Any, port))

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
{ {
internal class ClosedStream : Stream internal sealed class ClosedStream : Stream
{ {
private static readonly Task<int> ZeroResultTask = Task.FromResult(result: 0); private static readonly Task<int> ZeroResultTask = Task.FromResult(result: 0);

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
/// <summary> /// <summary>
/// http://tools.ietf.org/html/rfc2616#section-3.6.1 /// http://tools.ietf.org/html/rfc2616#section-3.6.1
/// </summary> /// </summary>
internal class Http1ChunkedEncodingMessageBody : Http1MessageBody internal sealed class Http1ChunkedEncodingMessageBody : Http1MessageBody
{ {
// byte consts don't have a data type annotation so we pre-cast it // byte consts don't have a data type annotation so we pre-cast it
private const byte ByteCR = (byte)'\r'; private const byte ByteCR = (byte)'\r';
@ -209,7 +209,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
_requestBodyPipe.Reset(); _requestBodyPipe.Reset();
} }
protected void Copy(ReadOnlySequence<byte> readableBuffer, PipeWriter writableBuffer) private void Copy(ReadOnlySequence<byte> readableBuffer, PipeWriter writableBuffer)
{ {
if (readableBuffer.IsSingleSegment) if (readableBuffer.IsSingleSegment)
{ {
@ -229,7 +229,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
_pumpTask = PumpAsync(); _pumpTask = PumpAsync();
} }
protected bool Read(ReadOnlySequence<byte> readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined) private bool Read(ReadOnlySequence<byte> readableBuffer, PipeWriter writableBuffer, out SequencePosition consumed, out SequencePosition examined)
{ {
consumed = default; consumed = default;
examined = default; examined = default;

View File

@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Connections;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
{ {
internal class Http1ContentLengthMessageBody : Http1MessageBody internal sealed class Http1ContentLengthMessageBody : Http1MessageBody
{ {
private ReadResult _readResult; private ReadResult _readResult;
private readonly long _contentLength; private readonly long _contentLength;

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
/// The upgrade stream uses the raw connection stream instead of going through the RequestBodyPipe. This /// The upgrade stream uses the raw connection stream instead of going through the RequestBodyPipe. This
/// removes the redundant copy from the transport pipe to the body pipe. /// removes the redundant copy from the transport pipe to the body pipe.
/// </summary> /// </summary>
internal class Http1UpgradeMessageBody : Http1MessageBody internal sealed class Http1UpgradeMessageBody : Http1MessageBody
{ {
public bool _completed; public bool _completed;
public Http1UpgradeMessageBody(Http1Connection context) public Http1UpgradeMessageBody(Http1Connection context)

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
/// <summary> /// <summary>
/// Default HttpRequest PipeReader implementation to be used by Kestrel. /// Default HttpRequest PipeReader implementation to be used by Kestrel.
/// </summary> /// </summary>
internal class HttpRequestPipeReader : PipeReader internal sealed class HttpRequestPipeReader : PipeReader
{ {
private MessageBody _body; private MessageBody _body;
private HttpStreamState _state; private HttpStreamState _state;

View File

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
{ {
internal class HttpRequestStream : ReadOnlyPipeStream internal sealed class HttpRequestStream : ReadOnlyPipeStream
{ {
private HttpRequestPipeReader _pipeReader; private HttpRequestPipeReader _pipeReader;
private readonly IHttpBodyControlFeature _bodyControl; private readonly IHttpBodyControlFeature _bodyControl;

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
{ {
internal class HttpResponsePipeWriter : PipeWriter internal sealed class HttpResponsePipeWriter : PipeWriter
{ {
private HttpStreamState _state; private HttpStreamState _state;
private readonly IHttpResponseControl _pipeControl; private readonly IHttpResponseControl _pipeControl;

View File

@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
{ {
internal class HttpResponseStream : WriteOnlyPipeStream internal sealed class HttpResponseStream : WriteOnlyPipeStream
{ {
private readonly HttpResponsePipeWriter _pipeWriter; private readonly HttpResponsePipeWriter _pipeWriter;
private readonly IHttpBodyControlFeature _bodyControl; private readonly IHttpBodyControlFeature _bodyControl;

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
{ {
internal class HttpUpgradeStream : Stream internal sealed class HttpUpgradeStream : Stream
{ {
private readonly Stream _requestStream; private readonly Stream _requestStream;
private readonly Stream _responseStream; private readonly Stream _responseStream;

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
{ {
internal class ZeroContentLengthMessageBody : MessageBody internal sealed class ZeroContentLengthMessageBody : MessageBody
{ {
public ZeroContentLengthMessageBody(bool keepAlive) public ZeroContentLengthMessageBody(bool keepAlive)
: base(null, null) : base(null, null)

View File

@ -9,7 +9,7 @@ using System.Runtime.CompilerServices;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{ {
// Mimics BinaryPrimitives with oddly sized units // Mimics BinaryPrimitives with oddly sized units
internal class Bitshifter internal static class Bitshifter
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint ReadUInt24BigEndian(ReadOnlySpan<byte> source) public static uint ReadUInt24BigEndian(ReadOnlySpan<byte> source)

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack
{ {
internal class HPackDecodingException : Exception internal sealed class HPackDecodingException : Exception
{ {
public HPackDecodingException(string message) public HPackDecodingException(string message)
: base(message) : base(message)

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack
{ {
internal class HPackEncodingException : Exception internal sealed class HPackEncodingException : Exception
{ {
public HPackEncodingException(string message) public HPackEncodingException(string message)
: base(message) : base(message)

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack
{ {
internal class HuffmanDecodingException : Exception internal sealed class HuffmanDecodingException : Exception
{ {
public HuffmanDecodingException(string message) public HuffmanDecodingException(string message)
: base(message) : base(message)

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{ {
internal class Http2ConnectionErrorException : Exception internal sealed class Http2ConnectionErrorException : Exception
{ {
public Http2ConnectionErrorException(string message, Http2ErrorCode errorCode) public Http2ConnectionErrorException(string message, Http2ErrorCode errorCode)
: base($"HTTP/2 connection error ({errorCode}): {message}") : base($"HTTP/2 connection error ({errorCode}): {message}")

View File

@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{ {
internal class Http2MessageBody : MessageBody internal sealed class Http2MessageBody : MessageBody
{ {
private readonly Http2Stream _context; private readonly Http2Stream _context;
private ReadResult _readResult; private ReadResult _readResult;

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{ {
internal class Http2SettingsParameterOutOfRangeException : Exception internal sealed class Http2SettingsParameterOutOfRangeException : Exception
{ {
public Http2SettingsParameterOutOfRangeException(Http2SettingsParameter parameter, long lowerBound, long upperBound) public Http2SettingsParameterOutOfRangeException(Http2SettingsParameter parameter, long lowerBound, long upperBound)
: base($"HTTP/2 SETTINGS parameter {parameter} must be set to a value between {lowerBound} and {upperBound}") : base($"HTTP/2 SETTINGS parameter {parameter} must be set to a value between {lowerBound} and {upperBound}")

View File

@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.FlowControl;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{ {
internal class Http2StreamContext : HttpConnectionContext internal sealed class Http2StreamContext : HttpConnectionContext
{ {
public int StreamId { get; set; } public int StreamId { get; set; }
public IHttp2StreamLifetimeHandler StreamLifetimeHandler { get; set; } public IHttp2StreamLifetimeHandler StreamLifetimeHandler { get; set; }

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{ {
internal class Http2StreamErrorException : Exception internal sealed class Http2StreamErrorException : Exception
{ {
public Http2StreamErrorException(int streamId, string message, Http2ErrorCode errorCode) public Http2StreamErrorException(int streamId, string message, Http2ErrorCode errorCode)
: base($"HTTP/2 stream ID {streamId} error ({errorCode}): {message}") : base($"HTTP/2 stream ID {streamId} error ({errorCode}): {message}")

View File

@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Hosting.Server;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{ {
internal class Http2Stream<TContext> : Http2Stream internal sealed class Http2Stream<TContext> : Http2Stream
{ {
private readonly IHttpApplication<TContext> _application; private readonly IHttpApplication<TContext> _application;

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
{ {
internal class ThrowingWasUpgradedWriteOnlyStream : WriteOnlyStream internal sealed class ThrowingWasUpgradedWriteOnlyStream : WriteOnlyStream
{ {
public override bool CanSeek => false; public override bool CanSeek => false;

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
{ {
internal class WrappingStream : Stream internal sealed class WrappingStream : Stream
{ {
private Stream _inner; private Stream _inner;
private bool _disposed; private bool _disposed;

View File

@ -12,7 +12,7 @@ using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Core namespace Microsoft.AspNetCore.Server.Kestrel.Core
{ {
internal class LocalhostListenOptions : ListenOptions internal sealed class LocalhostListenOptions : ListenOptions
{ {
internal LocalhostListenOptions(int port) internal LocalhostListenOptions(int port)
: base(new IPEndPoint(IPAddress.Loopback, port)) : base(new IPEndPoint(IPAddress.Loopback, port))

View File

@ -10,7 +10,7 @@ namespace System.Buffers
/// <summary> /// <summary>
/// Used to allocate and distribute re-usable blocks of memory. /// Used to allocate and distribute re-usable blocks of memory.
/// </summary> /// </summary>
internal class SlabMemoryPool : MemoryPool<byte> internal sealed class SlabMemoryPool : MemoryPool<byte>
{ {
/// <summary> /// <summary>
/// The size of a block. 4096 is chosen because most operating systems use 4k pages. /// The size of a block. 4096 is chosen because most operating systems use 4k pages.