Commit ecff9ef1 authored by justcoding121's avatar justcoding121

refactor

parent 3114902b
......@@ -3,7 +3,8 @@
namespace Titanium.Web.Proxy.Exceptions
{
/// <summary>
/// The server connection was closed.
/// The server connection was closed upon first read with the new connection from pool.
/// Should retry the request with a new connection.
/// </summary>
public class ServerConnectionException : ProxyException
{
......
......@@ -124,7 +124,19 @@ namespace Titanium.Web.Proxy.Http
{
if (Request.ExpectContinue)
{
string httpStatus = await ServerConnection.Stream.ReadLineAsync(cancellationToken);
string httpStatus;
try
{
httpStatus = await ServerConnection.Stream.ReadLineAsync(cancellationToken);
if (httpStatus == null)
{
throw new ServerConnectionException("Server connection was closed.");
}
}
catch (Exception e) when (!(e is ServerConnectionException))
{
throw new ServerConnectionException("Server connection was closed.");
}
Response.ParseResponseLine(httpStatus, out _, out int responseStatusCode,
out string responseStatusDescription);
......@@ -158,8 +170,16 @@ namespace Titanium.Web.Proxy.Http
return;
}
string httpStatus = await ServerConnection.Stream.ReadLineAsync(cancellationToken);
if (httpStatus == null)
string httpStatus;
try
{
httpStatus = await ServerConnection.Stream.ReadLineAsync(cancellationToken);
if (httpStatus == null)
{
throw new ServerConnectionException("Server connection was closed.");
}
}
catch (Exception e) when (!(e is ServerConnectionException))
{
throw new ServerConnectionException("Server connection was closed.");
}
......
......@@ -195,8 +195,8 @@ namespace Titanium.Web.Proxy
connectionChanged = true;
}
//for connection pool retry attempt until we get a good connection
var attemt = 0;
//for connection pool retry
while (attemt < 3)
{
try
......@@ -436,6 +436,7 @@ namespace Titanium.Web.Proxy
TcpServerConnection serverConnection,
CancellationTokenSource cancellationTokenSource, CancellationToken cancellationToken)
{
// prepare the prefix content
await serverConnection.StreamWriter.WriteLineAsync(httpCmd, cancellationToken);
await serverConnection.StreamWriter.WriteHeadersAsync(request.Headers,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment