Refactored WebHeaderCollection.cs
This commit is contained in:
parent
117aa1089a
commit
5e19c5cb1a
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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 ();
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
/// <param name="index">
|
||||
/// An <see cref="int"/> that represents the zero-based index of the header to find.
|
||||
/// </param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// <paramref name="index"/> is out of allowable range of indexes for the collection.
|
||||
/// </exception>
|
||||
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 <paramref name="name"/> in the collection.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="string"/> that receives the value of the header. <see langword="null"/> if
|
||||
/// there is no header with <paramref name="name"/> in the collection.
|
||||
/// A <see cref="string"/> that receives the value of the header if found; otherwise,
|
||||
/// <see langword="null"/>.
|
||||
/// </returns>
|
||||
/// <param name="name">
|
||||
/// A <see cref="string"/> that represents the name of the header to find.
|
||||
@ -1165,21 +1168,28 @@ namespace WebSocketSharp.Net
|
||||
/// <param name="index">
|
||||
/// An <see cref="int"/> that represents the zero-based index of the header to find.
|
||||
/// </param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// <paramref name="index"/> is out of allowable range of indexes for the collection.
|
||||
/// </exception>
|
||||
public override string GetKey (int index)
|
||||
{
|
||||
return base.GetKey (index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an array of header values stored in the specified <paramref name="index"/> position of
|
||||
/// the collection.
|
||||
/// Gets an array of header values stored in the specified <paramref name="index"/> position
|
||||
/// of the collection.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An array of <see cref="string"/> that receives the header values.
|
||||
/// An array of <see cref="string"/> that receives the header values if found; otherwise,
|
||||
/// <see langword="null"/>.
|
||||
/// </returns>
|
||||
/// <param name="index">
|
||||
/// An <see cref="int"/> that represents the zero-based index of the header to find.
|
||||
/// </param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// <paramref name="index"/> is out of allowable range of indexes for the collection.
|
||||
/// </exception>
|
||||
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 <paramref name="header"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An array of <see cref="string"/> that receives the header values.
|
||||
/// An array of <see cref="string"/> that receives the header values if found; otherwise,
|
||||
/// <see langword="null"/>.
|
||||
/// </returns>
|
||||
/// <param name="header">
|
||||
/// A <see cref="string"/> that represents the name of the header to find.
|
||||
|
Loading…
Reference in New Issue
Block a user