Reformat JustAMan review pt3 changes

This commit is contained in:
Erwin de Haan
2019-01-18 16:48:01 +01:00
parent 38f96af079
commit c1f76eb8ab
20 changed files with 117 additions and 117 deletions

View File

@@ -161,7 +161,7 @@ namespace SocketHttpListener
internal static bool Contains<T>(this IEnumerable<T> source, Func<T, bool> condition)
{
foreach (var elm in source)
foreach (T elm in source)
if (condition(elm))
return true;

View File

@@ -73,7 +73,7 @@ namespace SocketHttpListener.Net
protected override int ReadCore(byte[] buffer, int offset, int count)
{
var ares = BeginReadCore(buffer, offset, count, null, null);
IAsyncResult ares = BeginReadCore(buffer, offset, count, null, null);
return EndRead(ares);
}
@@ -115,7 +115,7 @@ namespace SocketHttpListener.Net
private void OnRead(IAsyncResult base_ares)
{
var rb = (ReadBufferState)base_ares.AsyncState;
ReadBufferState rb = (ReadBufferState)base_ares.AsyncState;
var ares = rb.Ares;
try
{

View File

@@ -269,7 +269,7 @@ namespace SocketHttpListener.Net
Close(true);
return;
}
var listener = _epl.Listener;
HttpListener listener = _epl.Listener;
if (_lastListener != listener)
{
RemoveConnection();
@@ -417,7 +417,7 @@ namespace SocketHttpListener.Net
{
try
{
var response = _context.Response;
HttpListenerResponse response = _context.Response;
response.StatusCode = status;
response.ContentType = "text/html";
string description = HttpStatusDescription.Get(status);
@@ -509,7 +509,7 @@ namespace SocketHttpListener.Net
return;
}
var s = _socket;
Socket s = _socket;
_socket = null;
try
{

View File

@@ -277,7 +277,7 @@ namespace SocketHttpListener.Net
public bool BindContext(HttpListenerContext context)
{
var req = context.Request;
var listener = SearchListener(req.Url, out var prefix);
HttpListener listener = SearchListener(req.Url, out var prefix);
if (listener == null)
return false;
@@ -309,7 +309,7 @@ namespace SocketHttpListener.Net
if (host != null && host != "")
{
var localPrefixes = _prefixes;
Dictionary<ListenerPrefix, HttpListener> localPrefixes = _prefixes;
foreach (var p in localPrefixes.Keys)
{
string ppath = p.Path;
@@ -330,7 +330,7 @@ namespace SocketHttpListener.Net
return bestMatch;
}
var list = _unhandledPrefixes;
List<ListenerPrefix> list = _unhandledPrefixes;
bestMatch = MatchFromList(host, path, list, out prefix);
if (path != pathSlash && bestMatch == null)
@@ -360,7 +360,7 @@ namespace SocketHttpListener.Net
HttpListener bestMatch = null;
int bestLength = -1;
foreach (var p in list)
foreach (ListenerPrefix p in list)
{
string ppath = p.Path;
if (ppath.Length < bestLength)
@@ -382,7 +382,7 @@ namespace SocketHttpListener.Net
if (list == null)
return;
foreach (var p in list)
foreach (ListenerPrefix p in list)
{
if (p.Path == prefix.Path)
throw new Exception("net_listener_already");
@@ -398,7 +398,7 @@ namespace SocketHttpListener.Net
int c = list.Count;
for (int i = 0; i < c; i++)
{
var p = list[i];
ListenerPrefix p = list[i];
if (p.Path == prefix.Path)
{
list.RemoveAt(i);
@@ -413,7 +413,7 @@ namespace SocketHttpListener.Net
if (_prefixes.Count > 0)
return;
var list = _unhandledPrefixes;
List<ListenerPrefix> list = _unhandledPrefixes;
if (list != null && list.Count > 0)
return;
@@ -433,7 +433,7 @@ namespace SocketHttpListener.Net
// Clone the list because RemoveConnection can be called from Close
var connections = new List<HttpConnection>(_unregisteredConnections.Keys);
foreach (var c in connections)
foreach (HttpConnection c in connections)
c.Close(true);
_unregisteredConnections.Clear();
}

View File

@@ -74,7 +74,7 @@ namespace SocketHttpListener.Net
throw new HttpListenerException((int)HttpStatusCode.BadRequest, "net_invalid_path");
// listens on all the interfaces if host name cannot be parsed by IPAddress.
var epl = GetEPListener(logger, lp.Host, lp.Port, listener, lp.Secure);
HttpEndPointListener epl = GetEPListener(logger, lp.Host, lp.Port, listener, lp.Secure);
epl.AddPrefix(lp, listener);
}
@@ -185,7 +185,7 @@ namespace SocketHttpListener.Net
if (lp.Path.IndexOf("//", StringComparison.Ordinal) != -1)
return;
var epl = GetEPListener(logger, lp.Host, lp.Port, listener, lp.Secure);
HttpEndPointListener epl = GetEPListener(logger, lp.Host, lp.Port, listener, lp.Secure);
epl.RemovePrefix(lp, listener);
}
}

View File

@@ -44,7 +44,7 @@ namespace SocketHttpListener.Net
}
internal IPrincipal ParseBasicAuthentication(string authData) =>
TryParseBasicAuth(authData, out var errorCode, out string username, out string password) ?
TryParseBasicAuth(authData, out HttpStatusCode errorCode, out string username, out string password) ?
new GenericPrincipal(new HttpListenerBasicIdentity(username, password), Array.Empty<string>()) :
null;

View File

@@ -180,7 +180,7 @@ namespace SocketHttpListener.Net
if (string.Compare(Headers[HttpKnownHeaderNames.Expect], "100-continue", StringComparison.OrdinalIgnoreCase) == 0)
{
var output = _context.Connection.GetResponseStream();
HttpResponseStream output = _context.Connection.GetResponseStream();
output.InternalWrite(s_100continue, 0, s_100continue.Length);
}
}
@@ -256,7 +256,7 @@ namespace SocketHttpListener.Net
{
try
{
var ares = InputStream.BeginRead(bytes, 0, length, null, null);
IAsyncResult ares = InputStream.BeginRead(bytes, 0, length, null, null);
if (!ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne(1000))
return false;
if (InputStream.EndRead(ares) <= 0)

View File

@@ -94,10 +94,10 @@ namespace SocketHttpListener.Net
// Try to check the raw path using first the primary encoding (according to http.sys settings);
// if it fails try the secondary encoding.
var result = BuildRequestUriUsingRawPath(GetEncoding(EncodingType.Primary));
ParsingResult result = BuildRequestUriUsingRawPath(GetEncoding(EncodingType.Primary));
if (result == ParsingResult.EncodingError)
{
var secondaryEncoding = GetEncoding(EncodingType.Secondary);
Encoding secondaryEncoding = GetEncoding(EncodingType.Secondary);
result = BuildRequestUriUsingRawPath(secondaryEncoding);
}
isValid = (result == ParsingResult.Success) ? true : false;
@@ -136,7 +136,7 @@ namespace SocketHttpListener.Net
_requestUriString.Append(Uri.SchemeDelimiter);
_requestUriString.Append(_cookedUriHost);
var result = ParseRawPath(encoding);
ParsingResult result = ParseRawPath(encoding);
if (result == ParsingResult.Success)
{
_requestUriString.Append(_cookedUriQuery);
@@ -263,7 +263,7 @@ namespace SocketHttpListener.Net
private bool AddPercentEncodedOctetToRawOctetsList(Encoding encoding, string escapedCharacter)
{
if (!byte.TryParse(escapedCharacter, NumberStyles.HexNumber, null, out var encodedValue))
if (!byte.TryParse(escapedCharacter, NumberStyles.HexNumber, null, out byte encodedValue))
{
//if (NetEventSource.IsEnabled) NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_convert_percent_value, escapedCharacter));
return false;

View File

@@ -70,7 +70,7 @@ namespace SocketHttpListener.Net
private void DisposeCore()
{
byte[] bytes = null;
var ms = GetHeaders(true);
MemoryStream ms = GetHeaders(true);
bool chunked = _response.SendChunked;
if (_stream.CanWrite)
{
@@ -110,7 +110,7 @@ namespace SocketHttpListener.Net
if (_stream.CanWrite)
{
var ms = GetHeaders(closing: false, isWebSocketHandshake: true);
MemoryStream ms = GetHeaders(closing: false, isWebSocketHandshake: true);
bool chunked = _response.SendChunked;
long start = ms.Position;
@@ -146,7 +146,7 @@ namespace SocketHttpListener.Net
return null;
}
var ms = new MemoryStream();
MemoryStream ms = new MemoryStream();
_response.SendHeaders(closing, ms, isWebSocketHandshake);
return ms;
}
@@ -190,7 +190,7 @@ namespace SocketHttpListener.Net
return;
byte[] bytes = null;
var ms = GetHeaders(false);
MemoryStream ms = GetHeaders(false);
bool chunked = _response.SendChunked;
if (ms != null)
{
@@ -234,7 +234,7 @@ namespace SocketHttpListener.Net
}
byte[] bytes = null;
var ms = GetHeaders(false);
MemoryStream ms = GetHeaders(false);
bool chunked = _response.SendChunked;
if (ms != null)
{

View File

@@ -208,7 +208,7 @@ namespace SocketHttpListener.Net
if (!IsHeaderName(headerName))
throw new ArgumentException("Invalid character in header");
if (!headers.TryGetValue(headerName, out var info))
if (!headers.TryGetValue(headerName, out HeaderInfo info))
return false;
var flag = response ? HeaderInfo.Response : HeaderInfo.Request;
@@ -312,7 +312,7 @@ namespace SocketHttpListener.Net
if (headerName == null)
return false;
return headers.TryGetValue(headerName, out var info) && (info & HeaderInfo.MultiValue) != 0;
return headers.TryGetValue(headerName, out HeaderInfo info) && (info & HeaderInfo.MultiValue) != 0;
}
internal static bool IsHeaderValue(string value)

View File

@@ -16,8 +16,8 @@ namespace SocketHttpListener.Net.WebSockets
ValidateOptions(subProtocol, receiveBufferSize, MinSendBufferSize, keepAliveInterval);
// get property will create a new response if one doesn't exist.
var response = context.Response;
var request = context.Request;
HttpListenerResponse response = context.Response;
HttpListenerRequest request = context.Request;
ValidateWebSocketHeaders(context);
string secWebSocketVersion = request.Headers[HttpKnownHeaderNames.SecWebSocketVersion];

View File

@@ -20,7 +20,7 @@ namespace SocketHttpListener.Net.WebSockets
if (validStates != null && validStates.Length > 0)
{
foreach (var validState in validStates)
foreach (WebSocketState validState in validStates)
{
if (currentState == validState)
{

View File

@@ -78,6 +78,7 @@ namespace SocketHttpListener
init();
}
// In the .NET Framework, this pulls the value from a P/Invoke. Here we just hardcode it to a reasonable default.
public static TimeSpan DefaultKeepAliveInterval => TimeSpan.FromSeconds(30);
#endregion