Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
ExpectContinue correctly handle
Browse files Browse the repository at this point in the history
Send request before user call back only for expectcontinue
  • Loading branch information
justcoding121 committed Apr 28, 2016
1 parent 5303951 commit e4c68b0
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions Titanium.Web.Proxy/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static void HandleClient(TransparentProxyEndPoint endPoint, TcpClient tc
//if(endPoint.UseServerNameIndication)
//{
// //implement in future once SNI supported by SSL stream
// certificate = CertManager.CreateCertificate(endPoint.GenericCertificateName);
// certificate = CertManager.CreateCertificate(hostName);
//}
//else
certificate = CertManager.CreateCertificate(endPoint.GenericCertificateName);
Expand Down Expand Up @@ -207,7 +207,6 @@ private static void HandleHttpSessionRequest(TcpClient client, string httpCmd, S
version = new Version(1, 0);
}


args.ProxySession.Request.RequestHeaders = new List<HttpHeader>();

string tmpLine;
Expand All @@ -217,13 +216,9 @@ private static void HandleHttpSessionRequest(TcpClient client, string httpCmd, S
args.ProxySession.Request.RequestHeaders.Add(new HttpHeader(header[0], header[1]));
}



var httpRemoteUri = new Uri(!IsHttps ? httpCmdSplit[1] : (string.Concat("https://", args.ProxySession.Request.Host, httpCmdSplit[1])));
args.IsHttps = IsHttps;



args.ProxySession.Request.RequestUri = httpRemoteUri;

args.ProxySession.Request.Method = httpMethod;
Expand All @@ -249,24 +244,8 @@ private static void HandleHttpSessionRequest(TcpClient client, string httpCmd, S

lastRequestHostName = args.ProxySession.Request.RequestUri.Host;
args.ProxySession.Request.Host = args.ProxySession.Request.RequestUri.Host;
args.ProxySession.SetConnection(connection);
args.ProxySession.SendRequest();

if (Enable100ContinueBehaviour)
if (args.ProxySession.Request.Is100Continue)
{
WriteResponseStatus(args.ProxySession.Response.HttpVersion, "100",
"Continue", args.Client.ClientStreamWriter);
args.Client.ClientStreamWriter.WriteLine();
}
else if (args.ProxySession.Request.ExpectationFailed)
{
WriteResponseStatus(args.ProxySession.Response.HttpVersion, "417",
"Expectation Failed", args.Client.ClientStreamWriter);
args.Client.ClientStreamWriter.WriteLine();
}



//If requested interception
if (BeforeRequest != null)
{
Expand All @@ -275,12 +254,37 @@ private static void HandleHttpSessionRequest(TcpClient client, string httpCmd, S

args.ProxySession.Request.RequestLocked = true;

if (args.ProxySession.Request.ExpectContinue)
{
args.ProxySession.SetConnection(connection);
args.ProxySession.SendRequest();
}

if (Enable100ContinueBehaviour)
if (args.ProxySession.Request.Is100Continue)
{
WriteResponseStatus(args.ProxySession.Response.HttpVersion, "100",
"Continue", args.Client.ClientStreamWriter);
args.Client.ClientStreamWriter.WriteLine();
}
else if (args.ProxySession.Request.ExpectationFailed)
{
WriteResponseStatus(args.ProxySession.Response.HttpVersion, "417",
"Expectation Failed", args.Client.ClientStreamWriter);
args.Client.ClientStreamWriter.WriteLine();
}

if (args.ProxySession.Request.CancelRequest)
{
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args);
break;
}

if (!args.ProxySession.Request.ExpectContinue)
{
args.ProxySession.SetConnection(connection);
args.ProxySession.SendRequest();
}

//If request was modified by user
if (args.ProxySession.Request.RequestBodyRead)
Expand Down

0 comments on commit e4c68b0

Please sign in to comment.