// Copyright © WireMock.Net using System; using System.Collections.Generic; using System.Text.RegularExpressions; using HandlebarsDotNet; using JetBrains.Annotations; using Newtonsoft.Json; using WireMock.Admin.Mappings; using WireMock.Handlers; using WireMock.Logging; using WireMock.Matchers; using WireMock.RegularExpressions; using WireMock.Types; using System.Globalization; using WireMock.Models; #if USE_ASPNETCORE using Microsoft.Extensions.DependencyInjection; #endif namespace WireMock.Settings; /// /// WireMockServerSettings /// public class WireMockServerSettings { internal const int DefaultStartTimeout = 10000; /// /// Gets or sets the http port. /// [PublicAPI] public int? Port { get; set; } /// /// Gets or sets the use SSL. /// // ReSharper disable once InconsistentNaming [PublicAPI] public bool? UseSSL { get; set; } /// /// Defines on which scheme (http/https) to host. (This overrides the UseSSL value). /// [PublicAPI] public HostingScheme? HostingScheme { get; set; } /// /// Gets or sets to use HTTP 2 (used for Grpc). /// [PublicAPI] public bool? UseHttp2 { get; set; } /// /// Gets or sets whether to start admin interface. /// [PublicAPI] public bool? StartAdminInterface { get; set; } /// /// Gets or sets if the static mappings should be read at startup. /// [PublicAPI] public bool? ReadStaticMappings { get; set; } /// /// Watch the static mapping files + folder for changes when running. /// [PublicAPI] public bool? WatchStaticMappings { get; set; } /// /// A value indicating whether subdirectories within the static mappings path should be monitored. /// [PublicAPI] public bool? WatchStaticMappingsInSubdirectories { get; set; } /// /// Gets or sets if the proxy and record settings. /// [PublicAPI] public ProxyAndRecordSettings? ProxyAndRecordSettings { get; set; } /// /// Gets or sets the urls. /// [PublicAPI] public string[]? Urls { get; set; } /// /// StartTimeout /// [PublicAPI] public int StartTimeout { get; set; } = DefaultStartTimeout; /// /// Allow Partial Mapping (default set to false). /// [PublicAPI] public bool? AllowPartialMapping { get; set; } /// /// The username needed for __admin access. /// [PublicAPI] public string? AdminUsername { get; set; } /// /// The password needed for __admin access. /// [PublicAPI] public string? AdminPassword { get; set; } /// /// The AzureAD Tenant needed for __admin access. /// [PublicAPI] public string? AdminAzureADTenant { get; set; } /// /// The AzureAD Audience / Resource for __admin access. /// [PublicAPI] public string? AdminAzureADAudience { get; set; } /// /// The RequestLog expiration in hours (optional). /// [PublicAPI] public int? RequestLogExpirationDuration { get; set; } /// /// The MaxRequestLog count (optional). /// [PublicAPI] public int? MaxRequestLogCount { get; set; } /// /// Action which is called (with the IAppBuilder or IApplicationBuilder) before the internal WireMockMiddleware is initialized. [Optional] /// [PublicAPI] [JsonIgnore] public Action? PreWireMockMiddlewareInit { get; set; } /// /// Action which is called (with the IAppBuilder or IApplicationBuilder) after the internal WireMockMiddleware is initialized. [Optional] /// [PublicAPI] [JsonIgnore] public Action? PostWireMockMiddlewareInit { get; set; } #if USE_ASPNETCORE /// /// Action which is called with IServiceCollection when ASP.NET Core DI is being configured. [Optional] /// [PublicAPI] [JsonIgnore] public Action? AdditionalServiceRegistration { get; set; } /// /// Policies to use when using CORS. By default CORS is disabled. [Optional] /// [PublicAPI] public CorsPolicyOptions? CorsPolicyOptions { get; set; } #endif /// /// The IWireMockLogger which logs Debug, Info, Warning or Error /// [PublicAPI] [JsonIgnore] public IWireMockLogger Logger { get; set; } = null!; /// /// Handler to interact with the file system to read and write static mapping files. /// [PublicAPI] [JsonIgnore] public IFileSystemHandler FileSystemHandler { get; set; } = null!; /// /// Action which can be used to add additional Handlebars registrations. [Optional] /// [PublicAPI] [JsonIgnore] public Action? HandlebarsRegistrationCallback { get; set; } /// /// Allow the usage of CSharpCodeMatcher (default is not allowed). /// [PublicAPI] public bool? AllowCSharpCodeMatcher { get; set; } /// /// Allow a Body for all HTTP Methods. (default set to false). /// [PublicAPI] public bool? AllowBodyForAllHttpMethods { get; set; } /// /// Allow only a HttpStatus Code in the response which is defined. (default set to false). /// - false : also null, 0, empty or invalid HttpStatus codes are allowed. /// - true : only codes defined in are allowed. /// [PublicAPI] public bool? AllowOnlyDefinedHttpStatusCodeInResponse { get; set; } /// /// Set to true to disable Json deserialization when processing requests. (default set to false). /// [PublicAPI] public bool? DisableJsonBodyParsing { get; set; } /// /// Disable support for GZip and Deflate request body decompression. (default set to false). /// [PublicAPI] public bool? DisableRequestBodyDecompressing { get; set; } /// /// Set to true to disable FormUrlEncoded deserializing when processing requests. (default set to false). /// [PublicAPI] public bool? DisableDeserializeFormUrlEncoded { get; set; } /// /// Handle all requests synchronously. (default set to false). /// [PublicAPI] public bool? HandleRequestsSynchronously { get; set; } /// /// If https is used, these settings can be used to configure the CertificateSettings in case a custom certificate instead the default .NET certificate should be used. /// /// X509StoreName and X509StoreLocation should be defined /// OR /// X509CertificateFilePath should be defined /// OR /// X509Certificate should be defined /// [PublicAPI] public WireMockCertificateSettings? CertificateSettings { get; set; } /// /// Defines if custom CertificateSettings are defined /// [PublicAPI] public bool CustomCertificateDefined => CertificateSettings?.IsDefined == true; #if USE_ASPNETCORE /// /// Client certificate mode for the server /// [PublicAPI] public ClientCertificateMode ClientCertificateMode { get; set; } /// /// Whether to accept any client certificate /// public bool AcceptAnyClientCertificate { get; set; } #endif /// /// Defines the global IWebhookSettings to use. /// [PublicAPI] public WebhookSettings? WebhookSettings { get; set; } /// /// Use the instead of the default (default set to true). /// [PublicAPI] public bool? UseRegexExtended { get; set; } = true; /// /// Save unmatched requests to a file using the (default set to false). /// [PublicAPI] public bool? SaveUnmatchedRequests { get; set; } /// /// Don't save the response-string in the LogEntry when WithBody(Func{IRequestMessage, string}) or WithBody(Func{IRequestMessage, Task{string}}) is used. (default set to false). /// [PublicAPI] public bool? DoNotSaveDynamicResponseInLogEntry { get; set; } /// /// See . /// /// Default value = "All". /// [PublicAPI] public QueryParameterMultipleValueSupport? QueryParameterMultipleValueSupport { get; set; } /// /// Custom matcher mappings for static mappings /// [PublicAPI, JsonIgnore] public IDictionary>? CustomMatcherMappings { get; set; } /// /// The used when the JSON response is generated. /// [PublicAPI, JsonIgnore] public JsonSerializerSettings? JsonSerializerSettings { get; set; } /// /// The Culture to use. /// Currently used for: /// - Handlebars Transformer /// [JsonIgnore] public CultureInfo Culture { get; set; } = CultureInfo.CurrentCulture; /// /// A list of Grpc ProtoDefinitions which can be used. /// [PublicAPI] public Dictionary? ProtoDefinitions { get; set; } /// /// A list of GraphQL Schemas which can be used. /// [PublicAPI] public Dictionary? GraphQLSchemas { get; set; } /// /// The admin path to use for accessing the Admin REST interface. /// If not set __/admin is used. /// [PublicAPI] public string? AdminPath { get; set; } /// /// Defines the additional Handlebars Settings. /// [PublicAPI] public HandlebarsSettings? HandlebarsSettings { get; set; } }