From 5e19c5cb1adcb45a4ceae8467e5c944001b72b23 Mon Sep 17 00:00:00 2001 From: sta Date: Sun, 20 Apr 2014 17:21:38 +0900 Subject: [PATCH] Refactored WebHeaderCollection.cs --- websocket-sharp/Ext.cs | 2 +- websocket-sharp/HandshakeRequest.cs | 2 +- websocket-sharp/HandshakeResponse.cs | 2 +- websocket-sharp/Net/HttpListenerRequest.cs | 2 +- websocket-sharp/Net/HttpListenerResponse.cs | 24 ++++++++-------- websocket-sharp/Net/WebHeaderCollection.cs | 31 ++++++++++++++------- 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index 8aaecf0e..b1c09412 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -313,7 +313,7 @@ namespace WebSocketSharp internal static void CloseWithAuthChallenge ( this HttpListenerResponse response, string challenge) { - response.Headers.SetInternal ("WWW-Authenticate", challenge, true); + response.Headers.SetInternally ("WWW-Authenticate", challenge, true); response.Close (HttpStatusCode.Unauthorized); } diff --git a/websocket-sharp/HandshakeRequest.cs b/websocket-sharp/HandshakeRequest.cs index 79ecfee4..92d90776 100644 --- a/websocket-sharp/HandshakeRequest.cs +++ b/websocket-sharp/HandshakeRequest.cs @@ -162,7 +162,7 @@ namespace WebSocketSharp var headers = new WebHeaderCollection (); for (int i = 1; i < headerParts.Length; i++) - headers.SetInternal (headerParts [i], false); + headers.SetInternally (headerParts [i], false); return new HandshakeRequest { Headers = headers, diff --git a/websocket-sharp/HandshakeResponse.cs b/websocket-sharp/HandshakeResponse.cs index a52a64fc..de7e6bc7 100644 --- a/websocket-sharp/HandshakeResponse.cs +++ b/websocket-sharp/HandshakeResponse.cs @@ -140,7 +140,7 @@ namespace WebSocketSharp var headers = new WebHeaderCollection (); for (int i = 1; i < headerParts.Length; i++) - headers.SetInternal (headerParts [i], true); + headers.SetInternally (headerParts [i], true); return new HandshakeResponse { Headers = headers, diff --git a/websocket-sharp/Net/HttpListenerRequest.cs b/websocket-sharp/Net/HttpListenerRequest.cs index ad36028b..282b1200 100644 --- a/websocket-sharp/Net/HttpListenerRequest.cs +++ b/websocket-sharp/Net/HttpListenerRequest.cs @@ -527,7 +527,7 @@ namespace WebSocketSharp.Net var name = header.Substring (0, colon).Trim (); var val = header.Substring (colon + 1).Trim (); var lower = name.ToLower (CultureInfo.InvariantCulture); - _headers.SetInternal (name, val, false); + _headers.SetInternally (name, val, false); if (lower == "accept") { _acceptTypes = val.SplitHeaderValue (',').ToArray (); diff --git a/websocket-sharp/Net/HttpListenerResponse.cs b/websocket-sharp/Net/HttpListenerResponse.cs index 68ec1c33..5e8d8fa5 100644 --- a/websocket-sharp/Net/HttpListenerResponse.cs +++ b/websocket-sharp/Net/HttpListenerResponse.cs @@ -538,20 +538,20 @@ namespace WebSocketSharp.Net if (_contentEncoding != null && _contentType.IndexOf ("charset=", StringComparison.Ordinal) == -1) { var charset = _contentEncoding.WebName; - _headers.SetInternal ( + _headers.SetInternally ( "Content-Type", _contentType + "; charset=" + charset, true); } else { - _headers.SetInternal ("Content-Type", _contentType, true); + _headers.SetInternally ("Content-Type", _contentType, true); } } if (_headers ["Server"] == null) - _headers.SetInternal ("Server", "websocket-sharp/1.0", true); + _headers.SetInternally ("Server", "websocket-sharp/1.0", true); var provider = CultureInfo.InvariantCulture; if (_headers ["Date"] == null) - _headers.SetInternal ( + _headers.SetInternally ( "Date", DateTime.UtcNow.ToString ("r", provider), true); if (!_chunked) { @@ -561,7 +561,7 @@ namespace WebSocketSharp.Net } if (_contentLengthSet) - _headers.SetInternal ( + _headers.SetInternally ( "Content-Length", _contentLength.ToString (provider), true); } @@ -591,36 +591,36 @@ namespace WebSocketSharp.Net // They sent both KeepAlive: true and Connection: close!? if (!_keepAlive || connClose) { - _headers.SetInternal ("Connection", "close", true); + _headers.SetInternally ("Connection", "close", true); connClose = true; } if (_chunked) - _headers.SetInternal ("Transfer-Encoding", "chunked", true); + _headers.SetInternally ("Transfer-Encoding", "chunked", true); int reuses = _context.Connection.Reuses; if (reuses >= 100) { _forceCloseChunked = true; if (!connClose) { - _headers.SetInternal ("Connection", "close", true); + _headers.SetInternally ("Connection", "close", true); connClose = true; } } if (!connClose) { - _headers.SetInternal ( + _headers.SetInternally ( "Keep-Alive", String.Format ("timeout=15,max={0}", 100 - reuses), true); if (_context.Request.ProtocolVersion <= HttpVersion.Version10) - _headers.SetInternal ("Connection", "keep-alive", true); + _headers.SetInternally ("Connection", "keep-alive", true); } if (_location != null) - _headers.SetInternal ("Location", _location, true); + _headers.SetInternally ("Location", _location, true); if (_cookies != null) { foreach (Cookie cookie in _cookies) - _headers.SetInternal ("Set-Cookie", cookie.ToResponseString (), true); + _headers.SetInternally ("Set-Cookie", cookie.ToResponseString (), true); } var encoding = _contentEncoding ?? Encoding.Default; diff --git a/websocket-sharp/Net/WebHeaderCollection.cs b/websocket-sharp/Net/WebHeaderCollection.cs index ebf7242a..f328f935 100644 --- a/websocket-sharp/Net/WebHeaderCollection.cs +++ b/websocket-sharp/Net/WebHeaderCollection.cs @@ -886,18 +886,18 @@ namespace WebSocketSharp.Net return info != null && info.IsMultiValue (response); } - internal void RemoveInternal (string name) + internal void RemoveInternally (string name) { base.Remove (name); } - internal void SetInternal (string header, bool response) + internal void SetInternally (string header, bool response) { var pos = checkColonSeparated (header); - SetInternal (header.Substring (0, pos), header.Substring (pos + 1), response); + SetInternally (header.Substring (0, pos), header.Substring (pos + 1), response); } - internal void SetInternal (string name, string value, bool response) + internal void SetInternally (string name, string value, bool response) { value = checkValue (value); if (IsMultiValue (name, response)) @@ -1124,6 +1124,9 @@ namespace WebSocketSharp.Net /// /// An that represents the zero-based index of the header to find. /// + /// + /// is out of allowable range of indexes for the collection. + /// public override string Get (int index) { return base.Get (index); @@ -1133,8 +1136,8 @@ namespace WebSocketSharp.Net /// Get the value of the header with the specified in the collection. /// /// - /// A that receives the value of the header. if - /// there is no header with in the collection. + /// A that receives the value of the header if found; otherwise, + /// . /// /// /// A that represents the name of the header to find. @@ -1165,21 +1168,28 @@ namespace WebSocketSharp.Net /// /// An that represents the zero-based index of the header to find. /// + /// + /// is out of allowable range of indexes for the collection. + /// public override string GetKey (int index) { return base.GetKey (index); } /// - /// Gets an array of header values stored in the specified position of - /// the collection. + /// Gets an array of header values stored in the specified position + /// of the collection. /// /// - /// An array of that receives the header values. + /// An array of that receives the header values if found; otherwise, + /// . /// /// /// An that represents the zero-based index of the header to find. /// + /// + /// is out of allowable range of indexes for the collection. + /// public override string [] GetValues (int index) { var values = base.GetValues (index); @@ -1192,7 +1202,8 @@ namespace WebSocketSharp.Net /// Gets an array of header values stored in the specified . /// /// - /// An array of that receives the header values. + /// An array of that receives the header values if found; otherwise, + /// . /// /// /// A that represents the name of the header to find.