Unosquare
    Show / Hide Table of Contents

    Class WebServerBase<TOptions>

    Base class for IWebServer implementations.

    Inheritance
    Object
    WebServerBase<TOptions>
    WebServer
    Implements
    IWebServer
    IDisposable
    IWebModuleContainer
    IMimeTypeCustomizer
    IMimeTypeProvider
    IHttpContextHandler
    Namespace: EmbedIO
    Syntax
    public abstract class WebServerBase<TOptions> : ConfiguredObject, IWebServer, IDisposable, IWebModuleContainer, IMimeTypeCustomizer, IMimeTypeProvider, IHttpContextHandler where TOptions : WebServerOptionsBase, new()
    Type Parameters
    Name Description
    TOptions

    The type of the options object used to configure an instance.

    Constructors

    WebServerBase()

    Initializes a new instance of the WebServerBase<TOptions> class.

    Declaration
    protected WebServerBase()

    WebServerBase(TOptions)

    Initializes a new instance of the WebServerBase<TOptions> class.

    Declaration
    protected WebServerBase(TOptions options)
    Parameters
    Type Name Description
    TOptions options

    A TOptions instance that will be used to configure the server.

    WebServerBase(Action<TOptions>)

    Initializes a new instance of the WebServerBase<TOptions> class.

    Declaration
    protected WebServerBase(Action<TOptions> configure)
    Parameters
    Type Name Description
    Action<TOptions> configure

    A callback that will be used to configure the server's options.

    Properties

    LogSource

    Gets a string to use as a source for log messages.

    Declaration
    protected string LogSource { get; }
    Property Value
    Type Description
    String

    Modules

    Gets the modules.

    Declaration
    public IComponentCollection<IWebModule> Modules { get; }
    Property Value
    Type Description
    IComponentCollection<IWebModule>

    The modules.

    OnHttpException

    Gets or sets a callback that is called every time a HTTP exception is thrown during the processing of a request.

    This property can never be null.

    Declaration
    public HttpExceptionHandlerCallback OnHttpException { get; set; }
    Property Value
    Type Description
    HttpExceptionHandlerCallback
    Remarks

    The default value for this property is Default.

    See Also
    HttpExceptionHandler

    OnUnhandledException

    Gets or sets a callback that is called every time an unhandled exception occurs during the processing of a request.

    This property can never be null. If it is still

    Declaration
    public ExceptionHandlerCallback OnUnhandledException { get; set; }
    Property Value
    Type Description
    ExceptionHandlerCallback
    Remarks

    The default value for this property is Default.

    See Also
    ExceptionHandler

    Options

    Gets the options object used to configure this instance.

    Declaration
    public TOptions Options { get; }
    Property Value
    Type Description
    TOptions

    SessionManager

    Gets or sets the registered session ID manager, if any.

    A session ID manager is an implementation of .

    Note that this property can only be set before starting the web server.

    Declaration
    public ISessionManager? SessionManager { get; set; }
    Property Value
    Type Description
    Nullable<ISessionManager>

    The session manager, or null if no session manager is present.

    SharedItems

    Gets a dictionary of data shared among the modules in a container.

    This API mainly supports the EmbedIO infrastructure; it is not intended to be used directly from your code, unless to address specific needs in module development.

    Declaration
    public ConcurrentDictionary<object, object> SharedItems { get; }
    Property Value
    Type Description
    ConcurrentDictionary<Object, Object>

    State

    Gets the state of the web server.

    Declaration
    public WebServerState State { get; }
    Property Value
    Type Description
    WebServerState

    The state.

    See Also
    WebServerState

    Methods

    AddCustomMimeType(String, String)

    Adds a custom association between a file extension and a MIME type.

    Declaration
    public void AddCustomMimeType(string extension, string mimeType)
    Parameters
    Type Name Description
    String extension

    The file extension to associate to mimeType.

    String mimeType

    The MIME type to associate to extension.

    Dispose()

    Declaration
    public void Dispose()

    Dispose(Boolean)

    Releases unmanaged and - optionally - managed resources.

    Declaration
    protected virtual void Dispose(bool disposing)
    Parameters
    Type Name Description
    Boolean disposing

    true to release both managed and unmanaged resources; false to release only unmanaged resources.

    DoHandleContextAsync(IHttpContextImpl)

    Asynchronously handles a received request.

    Declaration
    protected Task DoHandleContextAsync(IHttpContextImpl context)
    Parameters
    Type Name Description
    IHttpContextImpl context

    The context of the request.

    Returns
    Type Description
    Task

    A representing the ongoing operation.

    Finalize()

    Finalizes an instance of the WebServerBase<TOptions> class.

    Declaration
    protected void Finalize()

    GetMimeType(String)

    Gets the MIME type associated to a file extension.

    Declaration
    public string GetMimeType(string extension)
    Parameters
    Type Name Description
    String extension

    The file extension for which a corresponding MIME type is wanted.

    Returns
    Type Description
    String

    The MIME type corresponding to extension, if one is found; otherwise, null.

    HandleContextAsync(IHttpContextImpl)

    Asynchronously handles a HTTP context, generating a suitable response for an incoming request.

    This API supports the EmbedIO infrastructure and is not intended to be used directly from your code.

    Declaration
    public Task HandleContextAsync(IHttpContextImpl context)
    Parameters
    Type Name Description
    IHttpContextImpl context

    The HTTP context.

    Returns
    Type Description
    Task

    A representing the ongoing operation.

    OnBeforeLockConfiguration()

    Declaration
    protected override void OnBeforeLockConfiguration()

    OnFatalException()

    Called when an exception is caught in the web server's request processing loop.

    This method should tell the server socket to stop accepting further requests.

    Declaration
    protected abstract void OnFatalException()

    PreferCompression(String, Boolean)

    Indicates whether to prefer compression when negotiating content encoding for a response with the specified content type, or whose content type is in the specified media range.

    Declaration
    public void PreferCompression(string mimeType, bool preferCompression)
    Parameters
    Type Name Description
    String mimeType

    The MIME type or media range.

    Boolean preferCompression

    true to prefer compression; otherwise, false.

    Prepare(CancellationToken)

    Prepares a web server for running.

    Declaration
    protected virtual void Prepare(CancellationToken cancellationToken)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    A used to stop the web server.

    ProcessRequestsAsync(CancellationToken)

    Asynchronously receives requests and processes them.

    Declaration
    protected abstract Task ProcessRequestsAsync(CancellationToken cancellationToken)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    A used to stop the web server.

    Returns
    Type Description
    Task

    A representing the ongoing operation.

    RunAsync(CancellationToken)

    Starts the listener and the registered modules.

    Declaration
    public Task RunAsync(CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    The cancellation token; when cancelled, the server cancels all pending requests and stops.

    Returns
    Type Description
    Task

    Returns the task that the HTTP listener is running inside of, so that it can be waited upon after it's been canceled.

    TryDetermineCompression(String, out Boolean)

    Attempts to determine whether compression should be preferred when negotiating content encoding for a response with the specified content type.

    Declaration
    public bool TryDetermineCompression(string mimeType, out bool preferCompression)
    Parameters
    Type Name Description
    String mimeType

    The MIME type to check.

    Boolean preferCompression

    When this method returns true, a value indicating whether compression should be preferred. This parameter is passed uninitialized.

    Returns
    Type Description
    Boolean

    true if a value is found for mimeType; otherwise, false.

    Events

    StateChanged

    Declaration
    public event EventHandler<WebServerStateChangedEventArgs>? StateChanged
    Event Type
    Type Description
    Nullable<EventHandler<WebServerStateChangedEventArgs>>

    Implements

    IWebServer
    IDisposable
    IWebModuleContainer
    IMimeTypeCustomizer
    IMimeTypeProvider
    IHttpContextHandler

    See Also

    IHttpContextHandler
    IWebServer

    Comments

    Back to top Copyright © 2017-2019 Unosquare