| | | 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 | | |
| | | 4 | | using System.Threading; |
| | | 5 | | |
| | | 6 | | namespace 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; |
| | 8642 | 14 | | private TimeSpan _keepAliveInterval = WebSocketDefaults.DefaultKeepAliveInterval; |
| | 8642 | 15 | | 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> |
| | 19309 | 20 | | 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 | | { |
| | 8642 | 27 | | get => _subProtocol; |
| | | 28 | | set |
| | 0 | 29 | | { |
| | 0 | 30 | | if (value is not null) |
| | 0 | 31 | | { |
| | 0 | 32 | | WebSocketValidate.ValidateSubprotocol(value); |
| | 0 | 33 | | } |
| | 0 | 34 | | _subProtocol = value; |
| | 0 | 35 | | } |
| | | 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 | | { |
| | 8642 | 46 | | get => _keepAliveInterval; |
| | | 47 | | set |
| | 8642 | 48 | | { |
| | 8642 | 49 | | if (value != Timeout.InfiniteTimeSpan && value < TimeSpan.Zero) |
| | 0 | 50 | | { |
| | 0 | 51 | | throw new ArgumentOutOfRangeException(nameof(KeepAliveInterval), value, |
| | 0 | 52 | | SR.Format(SR.net_WebSockets_ArgumentOutOfRange_TooSmall, 0)); |
| | | 53 | | } |
| | 8642 | 54 | | _keepAliveInterval = value; |
| | 8642 | 55 | | } |
| | | 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 | | { |
| | 8642 | 65 | | get => _keepAliveTimeout; |
| | | 66 | | set |
| | 8642 | 67 | | { |
| | 8642 | 68 | | if (value != Timeout.InfiniteTimeSpan && value < TimeSpan.Zero) |
| | 0 | 69 | | { |
| | 0 | 70 | | throw new ArgumentOutOfRangeException(nameof(KeepAliveTimeout), value, |
| | 0 | 71 | | SR.Format(SR.net_WebSockets_ArgumentOutOfRange_TooSmall, 0)); |
| | | 72 | | } |
| | 8642 | 73 | | _keepAliveTimeout = value; |
| | 8642 | 74 | | } |
| | | 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> |
| | 17284 | 83 | | public WebSocketDeflateOptions? DangerousDeflateOptions { get; set; } |
| | | 84 | | } |
| | | 85 | | } |
| | | 86 | | |