From 78aa91c115d64d6007ce8f59262d944639589c72 Mon Sep 17 00:00:00 2001 From: sta Date: Fri, 19 Jun 2015 17:26:59 +0900 Subject: [PATCH] Refactored a few for HttpListenerResponse.cs --- websocket-sharp/Net/HttpListenerResponse.cs | 41 +++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/websocket-sharp/Net/HttpListenerResponse.cs b/websocket-sharp/Net/HttpListenerResponse.cs index 4084703d..21ff83bc 100644 --- a/websocket-sharp/Net/HttpListenerResponse.cs +++ b/websocket-sharp/Net/HttpListenerResponse.cs @@ -326,7 +326,15 @@ namespace WebSocketSharp.Net /// A that represents the value of the Location response-header. /// /// - /// The value specified for a set operation is empty. + /// + /// The value specified for a set operation is empty. + /// + /// + /// -or- + /// + /// + /// The value specified for a set operation isn't an absolute URL. + /// /// /// /// This object is closed. @@ -338,9 +346,18 @@ namespace WebSocketSharp.Net set { checkDisposed (); - if (value != null && value.Length == 0) + if (value == null) { + _location = null; + return; + } + + if (value.Length == 0) 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; } } @@ -776,6 +793,12 @@ namespace WebSocketSharp.Net /// Configures the response to redirect the client's request to /// the specified . /// + /// + /// This method sets the property to + /// , the property to + /// 302, and the property to + /// "Found". + /// /// /// A that represents the URL to redirect the client's request to. /// @@ -783,7 +806,15 @@ namespace WebSocketSharp.Net /// is . /// /// - /// is empty. + /// + /// is empty. + /// + /// + /// -or- + /// + /// + /// isn't an absolute URL. + /// /// /// /// The response has already been sent. @@ -800,6 +831,10 @@ namespace WebSocketSharp.Net if (url.Length == 0) 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; _statusCode = 302; _statusDescription = "Found";