Modified some set operation
This commit is contained in:
parent
2c1078d75c
commit
68ab8e9ea9
@ -201,13 +201,12 @@ namespace WebSocketSharp
|
|||||||
#region Public Properties
|
#region Public Properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the compression method used to compress the payload data of
|
/// Gets or sets the compression method used to compress the message.
|
||||||
/// the WebSocket Data frame.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// One of the <see cref="CompressionMethod"/> values that represents the
|
/// One of the <see cref="CompressionMethod"/> enum values, indicates the
|
||||||
/// compression method used to compress.
|
/// compression method used to compress the message. The default value is
|
||||||
/// The default value is <see cref="CompressionMethod.NONE"/>.
|
/// <see cref="CompressionMethod.NONE"/>.
|
||||||
/// </value>
|
/// </value>
|
||||||
public CompressionMethod Compression {
|
public CompressionMethod Compression {
|
||||||
get {
|
get {
|
||||||
@ -216,11 +215,8 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
set {
|
set {
|
||||||
lock (_forConn) {
|
lock (_forConn) {
|
||||||
var msg = !_client
|
var msg = checkIfAvailable (
|
||||||
? "Set operation of Compression isn't available as a server."
|
"Set operation of Compression", false, false);
|
||||||
: IsConnected
|
|
||||||
? "A WebSocket connection has already been established."
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
_logger.Error (msg);
|
_logger.Error (msg);
|
||||||
@ -235,7 +231,8 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the cookies used in the WebSocket connection request.
|
/// Gets the HTTP cookies used in the WebSocket connection request and
|
||||||
|
/// response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// An IEnumerable<Cookie> interface that provides an enumerator which
|
/// An IEnumerable<Cookie> interface that provides an enumerator which
|
||||||
@ -244,8 +241,8 @@ namespace WebSocketSharp
|
|||||||
public IEnumerable<Cookie> Cookies {
|
public IEnumerable<Cookie> Cookies {
|
||||||
get {
|
get {
|
||||||
lock (_cookies.SyncRoot) {
|
lock (_cookies.SyncRoot) {
|
||||||
return from Cookie cookie in _cookies
|
foreach (Cookie cookie in _cookies)
|
||||||
select cookie;
|
yield return cookie;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,7 +264,7 @@ namespace WebSocketSharp
|
|||||||
/// Gets the WebSocket extensions selected by the server.
|
/// Gets the WebSocket extensions selected by the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="string"/> that represents the WebSocket extensions if any.
|
/// A <see cref="string"/> that represents the extensions if any.
|
||||||
/// The default value is <see cref="String.Empty"/>.
|
/// The default value is <see cref="String.Empty"/>.
|
||||||
/// </value>
|
/// </value>
|
||||||
public string Extensions {
|
public string Extensions {
|
||||||
@ -304,9 +301,9 @@ namespace WebSocketSharp
|
|||||||
/// Gets the logging functions.
|
/// Gets the logging functions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// The default logging level is the <see cref="LogLevel.ERROR"/>. If you
|
/// The default logging level is <see cref="LogLevel.ERROR"/>. If you would
|
||||||
/// change the current logging level, you set the <c>Log.Level</c> property
|
/// like to change it, you should set the <c>Log.Level</c> property to any of
|
||||||
/// to any of the <see cref="LogLevel"/> values.
|
/// the <see cref="LogLevel"/> enum values.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="Logger"/> that provides the logging functions.
|
/// A <see cref="Logger"/> that provides the logging functions.
|
||||||
@ -322,8 +319,8 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the value of the Origin header used in the WebSocket
|
/// Gets or sets the value of the Origin header to send with the WebSocket
|
||||||
/// connection request.
|
/// connection request to the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// The <see cref="WebSocket"/> sends the Origin header if this property has
|
/// The <see cref="WebSocket"/> sends the Origin header if this property has
|
||||||
@ -347,16 +344,13 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
set {
|
set {
|
||||||
lock (_forConn) {
|
lock (_forConn) {
|
||||||
string msg = null;
|
var msg = checkIfAvailable ("Set operation of Origin", false, false);
|
||||||
if (!_client)
|
if (msg == null) {
|
||||||
msg = "Set operation of Origin isn't available as a server.";
|
if (value.IsNullOrEmpty ()) {
|
||||||
else if (IsConnected)
|
_origin = value;
|
||||||
msg = "A WebSocket connection has already been established.";
|
return;
|
||||||
else if (value.IsNullOrEmpty ()) {
|
}
|
||||||
_origin = value;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Uri origin;
|
Uri origin;
|
||||||
if (!Uri.TryCreate (value, UriKind.Absolute, out origin) ||
|
if (!Uri.TryCreate (value, UriKind.Absolute, out origin) ||
|
||||||
origin.Segments.Length > 1)
|
origin.Segments.Length > 1)
|
||||||
@ -392,7 +386,8 @@ namespace WebSocketSharp
|
|||||||
/// Gets the state of the WebSocket connection.
|
/// Gets the state of the WebSocket connection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// One of the <see cref="WebSocketState"/> values.
|
/// One of the <see cref="WebSocketState"/> enum values, indicates the state
|
||||||
|
/// of the WebSocket connection.
|
||||||
/// The default value is <see cref="WebSocketState.CONNECTING"/>.
|
/// The default value is <see cref="WebSocketState.CONNECTING"/>.
|
||||||
/// </value>
|
/// </value>
|
||||||
public WebSocketState ReadyState {
|
public WebSocketState ReadyState {
|
||||||
@ -421,12 +416,8 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
set {
|
set {
|
||||||
lock (_forConn) {
|
lock (_forConn) {
|
||||||
var msg =
|
var msg = checkIfAvailable (
|
||||||
!_client
|
"Set operation of ServerCertificateValidationCallback", false, false);
|
||||||
? "Set operation of ServerCertificateValidationCallback isn't available as a server."
|
|
||||||
: IsConnected
|
|
||||||
? "A WebSocket connection has already been established."
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
_logger.Error (msg);
|
_logger.Error (msg);
|
||||||
@ -637,6 +628,16 @@ namespace WebSocketSharp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string checkIfAvailable (
|
||||||
|
string operation, bool availableAsServer, bool availableAsConnected)
|
||||||
|
{
|
||||||
|
return !_client && !availableAsServer
|
||||||
|
? operation + " isn't available as a server."
|
||||||
|
: !availableAsConnected
|
||||||
|
? _readyState.CheckIfConnectable ()
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
private string checkIfCanConnect ()
|
private string checkIfCanConnect ()
|
||||||
{
|
{
|
||||||
return !_client && _readyState == WebSocketState.CLOSED
|
return !_client && _readyState == WebSocketState.CLOSED
|
||||||
@ -2083,21 +2084,17 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets a <see cref="Cookie"/> used in the WebSocket connection request.
|
/// Sets an HTTP <paramref name="cookie"/> to send with the WebSocket
|
||||||
|
/// connection request to the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cookie">
|
/// <param name="cookie">
|
||||||
/// A <see cref="Cookie"/> that represents an HTTP Cookie to set.
|
/// A <see cref="Cookie"/> that represents the HTTP Cookie to send.
|
||||||
/// </param>
|
/// </param>
|
||||||
public void SetCookie (Cookie cookie)
|
public void SetCookie (Cookie cookie)
|
||||||
{
|
{
|
||||||
lock (_forConn) {
|
lock (_forConn) {
|
||||||
var msg = !_client
|
var msg = checkIfAvailable ("SetCookie", false, false) ??
|
||||||
? "SetCookie isn't available as a server."
|
(cookie == null ? "'cookie' must not be null." : null);
|
||||||
: IsConnected
|
|
||||||
? "A WebSocket connection has already been established."
|
|
||||||
: cookie == null
|
|
||||||
? "'cookie' must not be null."
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
_logger.Error (msg);
|
_logger.Error (msg);
|
||||||
@ -2131,19 +2128,16 @@ namespace WebSocketSharp
|
|||||||
public void SetCredentials (string username, string password, bool preAuth)
|
public void SetCredentials (string username, string password, bool preAuth)
|
||||||
{
|
{
|
||||||
lock (_forConn) {
|
lock (_forConn) {
|
||||||
string msg = null;
|
var msg = checkIfAvailable ("SetCredentials", false, false);
|
||||||
if (!_client)
|
if (msg == null) {
|
||||||
msg = "SetCredentials isn't available as a server.";
|
if (username.IsNullOrEmpty ()) {
|
||||||
else if (IsConnected)
|
_credentials = null;
|
||||||
msg = "A WebSocket connection has already been established.";
|
_preAuth = false;
|
||||||
else if (username.IsNullOrEmpty ()) {
|
_logger.Warn ("Credentials was set back to the default.");
|
||||||
_credentials = null;
|
|
||||||
_preAuth = false;
|
return;
|
||||||
_logger.Warn ("Credentials was set back to the default.");
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
msg = username.Contains (':') || !username.IsText ()
|
msg = username.Contains (':') || !username.IsText ()
|
||||||
? "'username' contains an invalid character."
|
? "'username' contains an invalid character."
|
||||||
: !password.IsNullOrEmpty () && !password.IsText ()
|
: !password.IsNullOrEmpty () && !password.IsText ()
|
||||||
@ -2160,6 +2154,7 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
_credentials = new NetworkCredential (
|
_credentials = new NetworkCredential (
|
||||||
username, password, _uri.PathAndQuery);
|
username, password, _uri.PathAndQuery);
|
||||||
|
|
||||||
_preAuth = preAuth;
|
_preAuth = preAuth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user