< Summary

Information
Class: System.Net.WebSockets.WebSocketCreationOptions
Assembly: System.Net.WebSockets
File(s): D:\runner\runtime\src\libraries\System.Net.WebSockets\src\System\Net\WebSockets\WebSocketCreationOptions.cs
Line coverage
53%
Covered lines: 15
Uncovered lines: 13
Coverable lines: 28
Total lines: 85
Line coverage: 53.5%
Branch coverage
40%
Covered branches: 4
Total branches: 10
Branch coverage: 40%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%

File(s)

D:\runner\runtime\src\libraries\System.Net.WebSockets\src\System\Net\WebSockets\WebSocketCreationOptions.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Threading;
 5
 6namespace System.Net.WebSockets
 7{
 8    /// <summary>
 9    /// Options that control how a <seealso cref="WebSocket"/> is created.
 10    /// </summary>
 11    public sealed class WebSocketCreationOptions
 12    {
 13        private string? _subProtocol;
 931414        private TimeSpan _keepAliveInterval = WebSocketDefaults.DefaultKeepAliveInterval;
 931415        private TimeSpan _keepAliveTimeout = WebSocketDefaults.DefaultKeepAliveTimeout;
 16
 17        /// <summary>
 18        /// Defines if this websocket is the server-side of the connection. The default value is false.
 19        /// </summary>
 2660620        public bool IsServer { get; set; }
 21
 22        /// <summary>
 23        /// The agreed upon sub-protocol that was used when creating the connection.
 24        /// </summary>
 25        public string? SubProtocol
 26        {
 931427            get => _subProtocol;
 28            set
 029            {
 030                if (value is not null)
 031                {
 032                    WebSocketValidate.ValidateSubprotocol(value);
 033                }
 034                _subProtocol = value;
 035            }
 36        }
 37
 38        /// <summary>
 39        /// The keep-alive interval to use, or <see cref="TimeSpan.Zero"/> or <see cref="Timeout.InfiniteTimeSpan"/> to 
 40        /// If <see cref="WebSocketCreationOptions.KeepAliveTimeout"/> is set, then PING messages are sent and peer's PO
 41        /// unsolicited PONG messages are used as a keep-alive heartbeat.
 42        /// The default is <see cref="TimeSpan.Zero"/>.
 43        /// </summary>
 44        public TimeSpan KeepAliveInterval
 45        {
 931446            get => _keepAliveInterval;
 47            set
 931448            {
 931449                if (value != Timeout.InfiniteTimeSpan && value < TimeSpan.Zero)
 050                {
 051                    throw new ArgumentOutOfRangeException(nameof(KeepAliveInterval), value,
 052                        SR.Format(SR.net_WebSockets_ArgumentOutOfRange_TooSmall, 0));
 53                }
 931454                _keepAliveInterval = value;
 931455            }
 56        }
 57
 58        /// <summary>
 59        /// The timeout to use when waiting for the peer's PONG in response to us sending a PING; or <see cref="TimeSpan
 60        /// <see cref="Timeout.InfiniteTimeSpan"/> to disable waiting for peer's response, and use an unsolicited PONG a
 61        /// The default is <see cref="Timeout.InfiniteTimeSpan"/>.
 62        /// </summary>
 63        public TimeSpan KeepAliveTimeout
 64        {
 931465            get => _keepAliveTimeout;
 66            set
 931467            {
 931468                if (value != Timeout.InfiniteTimeSpan && value < TimeSpan.Zero)
 069                {
 070                    throw new ArgumentOutOfRangeException(nameof(KeepAliveTimeout), value,
 071                        SR.Format(SR.net_WebSockets_ArgumentOutOfRange_TooSmall, 0));
 72                }
 931473                _keepAliveTimeout = value;
 931474            }
 75        }
 76
 77        /// <summary>
 78        /// The agreed upon options for per message deflate.<para />
 79        /// Be aware that enabling compression makes the application subject to CRIME/BREACH type of attacks.
 80        /// It is strongly advised to turn off compression when sending data containing secrets by
 81        /// specifying <see cref="WebSocketMessageFlags.DisableCompression" /> flag for such messages.
 82        /// </summary>
 1862883        public WebSocketDeflateOptions? DangerousDeflateOptions { get; set; }
 84    }
 85}