internal MinimalServer ToServer() { var srv = new MinimalServer(Http.Create()); srv.Endpoints.Add(new IPEndPoint(Endpoint.Scope, Endpoint.Port)); srv.Handlers.Add(this); srv.LoggerProvider = new LogLoggerProvider(); srv.OnError += SrvOnOnError; return(srv); }
/// <summary> /// Sets the <see cref="ListenerProvider" /> on the <see cref="MinimalServer" /> to one that provides /// <see cref="SslListener" />s with <see cref="TcpConnectionListener" />s, using the given /// <see cref="X509Certificate2" />. The given certificate must have a private key already set. /// </summary> /// <param name="server">the server</param> /// <param name="certificateWithKey">the certificate with the private key already set</param> public static void AddSsl(this MinimalServer server, X509Certificate2 certificateWithKey) { AddSsl(server, server.Protocol is HttpTwo ? new SslServerAuthenticationOptions { ServerCertificate = certificateWithKey, EnabledSslProtocols = SslProtocols.Tls12, ClientCertificateRequired = false, EncryptionPolicy = EncryptionPolicy.RequireEncryption, AllowRenegotiation = false, ApplicationProtocols = new List <SslApplicationProtocol> { SslApplicationProtocol.Http2 }, CertificateRevocationCheckMode = X509RevocationMode.Online } : new SslServerAuthenticationOptions { ServerCertificate = certificateWithKey, EnabledSslProtocols = SslProtocols.Tls12, ClientCertificateRequired = false, EncryptionPolicy = EncryptionPolicy.RequireEncryption, CertificateRevocationCheckMode = X509RevocationMode.Online }); }
/// <summary> /// Sets the <see cref="ListenerProvider" /> on the <see cref="MinimalServer" /> to one that provides /// <see cref="SslListener" />s with <see cref="TcpConnectionListener" />s, using the given /// <see cref="SslServerAuthenticationOptions" />. /// </summary> /// <param name="server">the server</param> /// <param name="serverAuthenticationOptions"> /// SSL Server Authentication Options to be passed to the /// <see cref="SslListener" /> constructor /// </param> public static void AddSsl(this MinimalServer server, SslServerAuthenticationOptions serverAuthenticationOptions) { server.ListenerProvider = endpoint => new SslListener(new TcpConnectionListener(endpoint), serverAuthenticationOptions); }
/// <summary> /// Sets the <see cref="ListenerProvider" /> on the <see cref="MinimalServer" /> to one that provides /// <see cref="SslListener" />s with <see cref="TcpConnectionListener" />s, using the given /// <see cref="X509Certificate2" /> and <see cref="ECDsa" /> private key. /// </summary> /// <param name="server">the server</param> /// <param name="certificate">the certificate</param> /// <param name="key">the private key</param> public static void AddSsl(this MinimalServer server, X509Certificate2 certificate, ECDsa key) { AddSsl(server, certificate.CopyWithPrivateKey(key)); }
/// <summary> /// Searches the methods contained within a given <see cref="object" /> using an /// <see cref="IAttributeHandlerResolver" />, for methods which can be defined as handlers. This method then adds the /// resolved handlers to the given <see cref="MinimalServer" /> /// </summary> /// <param name="server">the server to add resolved handlers to</param> /// <param name="obj">the object to search for given handlers</param> public static void RegisterHandler(this MinimalServer server, object obj) { server.Handlers.AddRange( server.Protocol?.AttributeHandlerResolver?.GetHandlers(obj) ?? new List <IHandler>()); }