Skip to content

Commit

Permalink
produce more error messages and less crashes on exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
cloverhap committed Apr 25, 2018
1 parent e6afe37 commit 335ef0b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 30 deletions.
64 changes: 36 additions & 28 deletions Src/EngineIoClientDotNet.mono/Client/Transports/PollingXHR_net40.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,50 +312,58 @@ public void Create()
{
var log2 = LogManager.GetLogger(Global.CallerName());
log2.Info("Task.Run Create start");
using (var res = Xhr.GetResponse())
try
{
log.Info("Xhr.GetResponse ");

var responseHeaders = new Dictionary<string, string>();
for (int i = 0; i < res.Headers.Count; i++)
using (var res = Xhr.GetResponse())
{
responseHeaders.Add(res.Headers.Keys[i], res.Headers[i]);
}
OnResponseHeaders(responseHeaders);
log.Info("Xhr.GetResponse ");

var contentType = res.Headers["Content-Type"];
var responseHeaders = new Dictionary<string, string>();
for (int i = 0; i < res.Headers.Count; i++)
{
responseHeaders.Add(res.Headers.Keys[i], res.Headers[i]);
}
OnResponseHeaders(responseHeaders);

var contentType = res.Headers["Content-Type"];


using (var resStream = res.GetResponseStream())
{
Debug.Assert(resStream != null, "resStream != null");
if (contentType.Equals("application/octet-stream",
StringComparison.OrdinalIgnoreCase))

using (var resStream = res.GetResponseStream())
{
var buffer = new byte[16*1024];
using (var ms = new MemoryStream())
Debug.Assert(resStream != null, "resStream != null");
if (contentType.Equals("application/octet-stream",
StringComparison.OrdinalIgnoreCase))
{
int read;
while ((read = resStream.Read(buffer, 0, buffer.Length)) > 0)
var buffer = new byte[16 * 1024];
using (var ms = new MemoryStream())
{
ms.Write(buffer, 0, read);
int read;
while ((read = resStream.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
var a = ms.ToArray();
OnData(a);
}
var a = ms.ToArray();
OnData(a);
}
}
else
{
using (var sr = new StreamReader(resStream))
else
{
OnData(sr.ReadToEnd());
using (var sr = new StreamReader(resStream))
{
OnData(sr.ReadToEnd());
}
}
}
}
}
log2.Info("Task.Run Create finish");
log2.Info("Task.Run Create finish");

}
catch (System.Net.WebException e)
{
log2.Error("Task.Run Create failed", e);
OnError(e);
}
});

}
Expand Down
14 changes: 12 additions & 2 deletions Src/EngineIoClientDotNet.net40/Client/HttpConnectProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ protected override void ProcessConnect(Socket socket, object targetEndPoint, Soc

string authorizationHeader = "";
if (m_StatusCode == 401 || m_StatusCode == 407)
authorizationHeader = m_AuthTokens.Aggregate("", (sum, next) => sum + next.Value.GetAuthorizationHeader());
{
try
{
authorizationHeader = m_AuthTokens.Aggregate("", (sum, next) => sum + next.Value.GetAuthorizationHeader());
}
catch (Exception ex)
{
OnException(ex);
}
}

m_TargetEndPoint = (EndPoint)targetEndPoint;
if (targetEndPoint is DnsEndPoint)
Expand Down Expand Up @@ -267,7 +276,7 @@ protected override void ProcessReceive(SocketAsyncEventArgs e)
}
else if (statusCode > 299 || statusCode < 200)
{
OnException("the proxy server refused the connection");
OnException("the proxy server refused the connection with " + statusCode);
return;
}

Expand Down Expand Up @@ -368,6 +377,7 @@ public void SetNextHeaders(StringReader headersLineReader)
m_Client = GetAlternateClientContext();
m_ClientToken = null;
m_ServerAuthChallenge = null;
throw new Exception("authentication from server missing authentication challenge");
}
}
}
Expand Down

0 comments on commit 335ef0b

Please sign in to comment.