/* * Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Net.Http * File: HttpConfig.cs * * HttpConfig.cs is part of VNLib.Net.Http which is part of the larger * VNLib collection of libraries and utilities. * * VNLib.Net.Http is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * VNLib.Net.Http is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://www.gnu.org/licenses/. */ using System; using System.Text; using VNLib.Net.Http.Core; using VNLib.Utils.Logging; namespace VNLib.Net.Http { /// /// Represents configration variables used to create the instance and manage http connections /// public readonly record struct HttpConfig { /// /// Pre-encoded CRLF bytes /// internal readonly HttpEncodedSegment CrlfBytes; /// /// Pre-encoded HTTP chunking final chunk segment /// internal readonly HttpEncodedSegment FinalChunkBytes; /// /// The cached header-line termination value /// internal readonly ReadOnlyMemory HeaderLineTermination; /// /// Initializes a new instance of the struct /// /// public HttpConfig(Encoding httpEncoding) { ArgumentNullException.ThrowIfNull(httpEncoding); HttpEncoding = httpEncoding; //Init pre-encded segments CrlfBytes = HttpEncodedSegment.FromString(HttpHelpers.CRLF, httpEncoding); FinalChunkBytes = HttpEncodedSegment.FromString("0\r\n\r\n", httpEncoding); //Store a ref to the crlf memory segment HeaderLineTermination = CrlfBytes.Buffer.AsMemory(); } /// /// A log provider that all server related log entiries will be written to /// public required readonly ILogProvider ServerLog { get; init; } /// /// Server memory pool to use for allocating buffers /// public required readonly IHttpMemoryPool MemoryPool { get; init; } /// /// The absolute request entity body size limit in bytes /// public readonly long MaxUploadSize { get; init; } = 5 * 1000 * 1024; /// /// The maximum size in bytes allowed for an MIME form-data content type upload /// /// Set to 0 to disabled mulit-part/form-data uploads public readonly int MaxFormDataUploadSize { get; init; } = 40 * 1024; /// /// The maximum number of file uploads allowed per request /// public readonly ushort MaxUploadsPerRequest { get; init; } = 5; /// /// The maximum response entity size in bytes for which the library will allow compresssing response data /// /// Set this value to 0 to disable response compression public readonly long CompressionLimit { get; init; } = 1000 * 1024; /// /// The minimum size (in bytes) of respones data that will be compressed /// public readonly int CompressionMinimum { get; init; } = 4096; /// /// The maximum amount of time to listen for data from a connected, but inactive transport connection /// before closing them /// public readonly TimeSpan ConnectionKeepAlive { get; init; } = TimeSpan.FromSeconds(100); /// /// The encoding to use when sending and receiving HTTP data /// public readonly Encoding HttpEncoding { get; init; } = Encoding.UTF8; /// /// Sets the default Http version for responses when the client version cannot be parsed from the request /// public readonly HttpVersion DefaultHttpVersion { get; init; } = HttpVersion.Http11; /// /// The amount of time (in milliseconds) to wait for data on a connection that is in a receive /// state, aka active receive. /// public readonly int ActiveConnectionRecvTimeout { get; init; } = 5000; /// /// The amount of time (in milliseconds) to wait for data to be send to the client before /// the connection is closed /// public readonly int SendTimeout { get; init; } = 5000; /// /// The maximum number of request headers allowed per request /// public readonly int MaxRequestHeaderCount { get; init; } = 100; /// /// The maximum number of open transport connections, before 503 errors /// will be returned and new connections closed. /// /// Set to 0 to disable request processing. Causes perminant 503 results public readonly int MaxOpenConnections { get; init; } = int.MaxValue; /// /// An for writing verbose request logs. Set to null /// to disable verbose request logging /// public readonly ILogProvider? RequestDebugLog { get; init; } = null; /// /// The buffer configuration for the server /// public readonly HttpBufferConfig BufferConfig { get; init; } = new(); /// /// Gets the used to manage response compression for /// the server. /// public readonly IHttpCompressorManager? CompressorManager { get; init; } = null; /// /// Enables debug performance counters /// public readonly bool DebugPerformanceCounters { get; init; } = false; } }