Commit 0cc53a6e authored by titanium007's avatar titanium007

Reduce exceptions

parent f898a590
......@@ -15,27 +15,27 @@ namespace Titanium.Web.Proxy.Helpers
internal string ReadLine()
{
var readBuffer = new StringBuilder();
try
{
var lastChar = default(char);
var buffer = new char[1];
while (true)
while (Read(buffer, 0, 1) > 0)
{
var buf = ReadChar();
if (lastChar == '\r' && buf == '\n')
if (lastChar == '\r' && buffer[0] == '\n')
{
return readBuffer.Remove(readBuffer.Length - 1, 1).ToString();
}
if (buf == '\0')
if (buffer[0] == '\0')
{
return readBuffer.ToString();
}
readBuffer.Append(buf);
lastChar = buf;
readBuffer.Append(buffer);
lastChar = buffer[0];
}
return readBuffer.ToString();
}
catch (IOException)
{
......
......@@ -33,7 +33,8 @@ namespace Titanium.Web.Proxy
if (string.IsNullOrEmpty(httpCmd))
{
throw new EndOfStreamException();
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, null);
return;
}
//break up the line into three components (method, remote URL & Http Version)
......@@ -80,11 +81,13 @@ namespace Titanium.Web.Proxy
if (sslStream != null)
sslStream.Dispose();
throw;
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, null);
return;
}
httpCmd = clientStreamReader.ReadLine();
}
else if (httpVerb.ToUpper() == "CONNECT")
{
......@@ -121,7 +124,6 @@ namespace Titanium.Web.Proxy
var args = new SessionEventArgs(BUFFER_SIZE);
args.Client = client;
try
{
//break up the line into three components (method, remote URL & Http Version)
......@@ -227,26 +229,21 @@ namespace Titanium.Web.Proxy
HandleHttpSessionResponse(args);
//if connection is closing exit
if (args.ResponseHeaders.Any(x => x.Name.ToLower() == "connection" && x.Value.ToLower() == "close"))
{
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args);
return;
}
//Now read the next request (if keep-Alive is enabled, otherwise exit this thread)
//If client is pipeling the request, this will be immediately hit before response for previous request was made
httpCmd = clientStreamReader.ReadLine();
//Http request body sent, now wait for next request
client = args.Client;
clientStream = args.ClientStream;
clientStreamReader = args.ClientStreamReader;
args.ClientStreamWriter = clientStreamWriter;
// read the next request
httpCmd = clientStreamReader.ReadLine();
}
catch
{
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args);
throw;
return;
}
}
}
......
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