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