11// Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
4- using Microsoft . AspNetCore . Http . Features ;
4+ using System ;
5+ using System . Net . WebSockets ;
56
67namespace Microsoft . AspNetCore . Http
78{
@@ -10,9 +11,63 @@ namespace Microsoft.AspNetCore.Http
1011 /// </summary>
1112 public class WebSocketAcceptContext
1213 {
14+ private int _serverMaxWindowBits = 15 ;
15+
1316 /// <summary>
1417 /// Gets or sets the subprotocol being negotiated.
1518 /// </summary>
1619 public virtual string ? SubProtocol { get ; set ; }
20+
21+ /// <summary>
22+ /// The interval to send pong frames. This is a heart-beat that keeps the connection alive.
23+ /// </summary>
24+ public virtual TimeSpan ? KeepAliveInterval { get ; set ; }
25+
26+ /// <summary>
27+ /// Enables support for the 'permessage-deflate' WebSocket extension.<para />
28+ /// Be aware that enabling compression over encrypted connections makes the application subject to CRIME/BREACH type attacks.
29+ /// It is strongly advised to turn off compression when sending data containing secrets by
30+ /// specifying <see cref="WebSocketMessageFlags.DisableCompression"/> when sending such messages.
31+ /// </summary>
32+ public bool DangerousEnableCompression { get ; set ; }
33+
34+ /// <summary>
35+ /// Disables server context takeover when using compression.
36+ /// This setting reduces the memory overhead of compression at the cost of a potentially worse compresson ratio.
37+ /// </summary>
38+ /// <remarks>
39+ /// This property does nothing when <see cref="DangerousEnableCompression"/> is false,
40+ /// or when the client does not use compression.
41+ /// </remarks>
42+ /// <value>
43+ /// false
44+ /// </value>
45+ public bool DisableServerContextTakeover { get ; set ; }
46+
47+ /// <summary>
48+ /// Sets the maximum base-2 logarithm of the LZ77 sliding window size that can be used for compression.
49+ /// This setting reduces the memory overhead of compression at the cost of a potentially worse compresson ratio.
50+ /// </summary>
51+ /// <remarks>
52+ /// This property does nothing when <see cref="DangerousEnableCompression"/> is false,
53+ /// or when the client does not use compression.
54+ /// Valid values are 9 through 15.
55+ /// </remarks>
56+ /// <value>
57+ /// 15
58+ /// </value>
59+ public int ServerMaxWindowBits
60+ {
61+ get => _serverMaxWindowBits ;
62+ set
63+ {
64+ if ( value < 9 || value > 15 )
65+ {
66+ throw new ArgumentOutOfRangeException ( nameof ( ServerMaxWindowBits ) ,
67+ "The argument must be a value from 9 to 15." ) ;
68+ }
69+ _serverMaxWindowBits = value ;
70+ }
71+ }
1772 }
1873}
0 commit comments