Commit ecff9ef1 authored by justcoding121's avatar justcoding121

refactor

parent 3114902b
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
namespace Titanium.Web.Proxy.Exceptions namespace Titanium.Web.Proxy.Exceptions
{ {
/// <summary> /// <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> /// </summary>
public class ServerConnectionException : ProxyException public class ServerConnectionException : ProxyException
{ {
......
...@@ -124,7 +124,19 @@ namespace Titanium.Web.Proxy.Http ...@@ -124,7 +124,19 @@ namespace Titanium.Web.Proxy.Http
{ {
if (Request.ExpectContinue) 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, Response.ParseResponseLine(httpStatus, out _, out int responseStatusCode,
out string responseStatusDescription); out string responseStatusDescription);
...@@ -158,11 +170,19 @@ namespace Titanium.Web.Proxy.Http ...@@ -158,11 +170,19 @@ namespace Titanium.Web.Proxy.Http
return; return;
} }
string httpStatus = await ServerConnection.Stream.ReadLineAsync(cancellationToken); string httpStatus;
try
{
httpStatus = await ServerConnection.Stream.ReadLineAsync(cancellationToken);
if (httpStatus == null) if (httpStatus == null)
{ {
throw new ServerConnectionException("Server connection was closed."); throw new ServerConnectionException("Server connection was closed.");
} }
}
catch (Exception e) when (!(e is ServerConnectionException))
{
throw new ServerConnectionException("Server connection was closed.");
}
if (httpStatus == string.Empty) if (httpStatus == string.Empty)
{ {
......
...@@ -195,8 +195,8 @@ namespace Titanium.Web.Proxy ...@@ -195,8 +195,8 @@ namespace Titanium.Web.Proxy
connectionChanged = true; connectionChanged = true;
} }
//for connection pool retry attempt until we get a good connection
var attemt = 0; var attemt = 0;
//for connection pool retry
while (attemt < 3) while (attemt < 3)
{ {
try try
...@@ -436,6 +436,7 @@ namespace Titanium.Web.Proxy ...@@ -436,6 +436,7 @@ namespace Titanium.Web.Proxy
TcpServerConnection serverConnection, TcpServerConnection serverConnection,
CancellationTokenSource cancellationTokenSource, CancellationToken cancellationToken) CancellationTokenSource cancellationTokenSource, CancellationToken cancellationToken)
{ {
// prepare the prefix content // prepare the prefix content
await serverConnection.StreamWriter.WriteLineAsync(httpCmd, cancellationToken); await serverConnection.StreamWriter.WriteLineAsync(httpCmd, cancellationToken);
await serverConnection.StreamWriter.WriteHeadersAsync(request.Headers, 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