Refactored a few for HttpListenerResponse.cs

This commit is contained in:
sta 2015-06-19 17:26:59 +09:00
parent d9d35a6527
commit 78aa91c115

View File

@ -326,7 +326,15 @@ namespace WebSocketSharp.Net
/// A <see cref="string"/> that represents the value of the Location response-header. /// A <see cref="string"/> that represents the value of the Location response-header.
/// </value> /// </value>
/// <exception cref="ArgumentException"> /// <exception cref="ArgumentException">
/// The value specified for a set operation is empty. /// <para>
/// The value specified for a set operation is empty.
/// </para>
/// <para>
/// -or-
/// </para>
/// <para>
/// The value specified for a set operation isn't an absolute URL.
/// </para>
/// </exception> /// </exception>
/// <exception cref="ObjectDisposedException"> /// <exception cref="ObjectDisposedException">
/// This object is closed. /// This object is closed.
@ -338,9 +346,18 @@ namespace WebSocketSharp.Net
set { set {
checkDisposed (); checkDisposed ();
if (value != null && value.Length == 0) if (value == null) {
_location = null;
return;
}
if (value.Length == 0)
throw new ArgumentException ("An empty string.", "value"); throw new ArgumentException ("An empty string.", "value");
Uri uri = null;
if (!value.MaybeUri () || !Uri.TryCreate (value, UriKind.Absolute, out uri))
throw new ArgumentException ("Not an absolute URL.", "value");
_location = value; _location = value;
} }
} }
@ -776,6 +793,12 @@ namespace WebSocketSharp.Net
/// Configures the response to redirect the client's request to /// Configures the response to redirect the client's request to
/// the specified <paramref name="url"/>. /// the specified <paramref name="url"/>.
/// </summary> /// </summary>
/// <remarks>
/// This method sets the <see cref="HttpListenerResponse.RedirectLocation"/> property to
/// <paramref name="url"/>, the <see cref="HttpListenerResponse.StatusCode"/> property to
/// <c>302</c>, and the <see cref="HttpListenerResponse.StatusDescription"/> property to
/// <c>"Found"</c>.
/// </remarks>
/// <param name="url"> /// <param name="url">
/// A <see cref="string"/> that represents the URL to redirect the client's request to. /// A <see cref="string"/> that represents the URL to redirect the client's request to.
/// </param> /// </param>
@ -783,7 +806,15 @@ namespace WebSocketSharp.Net
/// <paramref name="url"/> is <see langword="null"/>. /// <paramref name="url"/> is <see langword="null"/>.
/// </exception> /// </exception>
/// <exception cref="ArgumentException"> /// <exception cref="ArgumentException">
/// <paramref name="url"/> is empty. /// <para>
/// <paramref name="url"/> is empty.
/// </para>
/// <para>
/// -or-
/// </para>
/// <para>
/// <paramref name="url"/> isn't an absolute URL.
/// </para>
/// </exception> /// </exception>
/// <exception cref="InvalidOperationException"> /// <exception cref="InvalidOperationException">
/// The response has already been sent. /// The response has already been sent.
@ -800,6 +831,10 @@ namespace WebSocketSharp.Net
if (url.Length == 0) if (url.Length == 0)
throw new ArgumentException ("An empty string.", "url"); throw new ArgumentException ("An empty string.", "url");
Uri uri = null;
if (!url.MaybeUri () || !Uri.TryCreate (url, UriKind.Absolute, out uri))
throw new ArgumentException ("Not an absolute URL.", "url");
_location = url; _location = url;
_statusCode = 302; _statusCode = 302;
_statusDescription = "Found"; _statusDescription = "Found";