Commit 56270351 authored by titanium007's avatar titanium007

update comments

parent 3042d211
......@@ -133,18 +133,22 @@ namespace Titanium.Web.Proxy.Http
if (this.Response.ResponseStatusCode.Equals("100")
&& this.Response.ResponseStatusDescription.ToLower().Equals("continue"))
{
//Read the next line after 100-continue
this.Response.Is100Continue = true;
this.Response.ResponseStatusCode = null;
await ServerConnection.StreamReader.ReadLineAsync();
//now receive response
await ReceiveResponse();
return;
}
else if (this.Response.ResponseStatusCode.Equals("417")
&& this.Response.ResponseStatusDescription.ToLower().Equals("expectation failed"))
{
//read next line after expectation failed response
this.Response.ExpectationFailed = true;
this.Response.ResponseStatusCode = null;
await ServerConnection.StreamReader.ReadLineAsync();
//now receive response
await ReceiveResponse();
return;
}
......
......@@ -64,8 +64,8 @@ namespace Titanium.Web.Proxy
version = new Version(1, 0);
}
}
var excluded = endPoint.ExcludedHttpsHostNameRegex != null ?
//filter out excluded host names
var excluded = endPoint.ExcludedHttpsHostNameRegex != null ?
endPoint.ExcludedHttpsHostNameRegex.Any(x => Regex.IsMatch(httpRemoteUri.Host, x)) : false;
//Client wants to create a secure tcp tunnel (its a HTTPS request)
......@@ -82,8 +82,8 @@ namespace Titanium.Web.Proxy
{
//create the Tcp Connection to server and then release it to connection cache
//Just doing what CONNECT request is asking as to do
var tunnelClient = await TcpConnectionManager.GetClient(httpRemoteUri.Host, httpRemoteUri.Port, true, version);
await TcpConnectionManager.ReleaseClient(tunnelClient);
var tunnelClient = await TcpConnectionManager.GetClient(httpRemoteUri.Host, httpRemoteUri.Port, true, version);
await TcpConnectionManager.ReleaseClient(tunnelClient);
sslStream = new SslStream(clientStream, true);
var certificate = await CertManager.CreateCertificate(httpRemoteUri.Host, false);
......@@ -148,12 +148,8 @@ namespace Titanium.Web.Proxy
if (endPoint.EnableSsl)
{
var sslStream = new SslStream(clientStream, true);
//if(endPoint.UseServerNameIndication)
//{
// //implement in future once SNI supported by SSL stream
// certificate = CertManager.CreateCertificate(hostName);
//}
//else
//implement in future once SNI supported by SSL stream, for now use the same certificate
certificate = await CertManager.CreateCertificate(endPoint.GenericCertificateName, false);
try
......@@ -182,6 +178,7 @@ namespace Titanium.Web.Proxy
clientStreamReader = new CustomBinaryReader(clientStream);
}
//now read the request line
var httpCmd = await clientStreamReader.ReadLineAsync();
//Now create the request
......@@ -411,6 +408,7 @@ namespace Titanium.Web.Proxy
{
switch (requestHeaders[i].Name.ToLower())
{
//these are the only encoding this proxy can read
case "accept-encoding":
requestHeaders[i].Value = "gzip,deflate,zlib";
break;
......@@ -457,28 +455,18 @@ namespace Titanium.Web.Proxy
// End the operation
var postStream = args.WebSession.ServerConnection.Stream;
//send the request body bytes to server
if (args.WebSession.Request.ContentLength > 0)
{
try
{
await args.ProxyClient.ClientStreamReader.CopyBytesToStream(postStream, args.WebSession.Request.ContentLength);
}
catch
{
throw;
}
await args.ProxyClient.ClientStreamReader.CopyBytesToStream(postStream, args.WebSession.Request.ContentLength);
}
//Need to revist, find any potential bugs
//send the request body bytes to server in chunks
else if (args.WebSession.Request.IsChunked)
{
try
{
await args.ProxyClient.ClientStreamReader.CopyBytesToStreamChunked(postStream);
}
catch
{
throw;
}
await args.ProxyClient.ClientStreamReader.CopyBytesToStreamChunked(postStream);
}
}
......
......@@ -83,8 +83,13 @@ namespace Titanium.Web.Proxy
{
await WriteResponseHeaders(args.ProxyClient.ClientStreamWriter, args.WebSession.Response.ResponseHeaders);
if (args.WebSession.Response.IsChunked || args.WebSession.Response.ContentLength > 0 ||
(args.WebSession.Response.HttpVersion.Major == 1 && args.WebSession.Response.HttpVersion.Minor == 0))
//Write body only if response is chunked or content length >0
//Is none are true then check if connection:close header exist, if so write response until server or client terminates the connection
if (args.WebSession.Response.IsChunked || args.WebSession.Response.ContentLength > 0 || !args.WebSession.Response.ResponseKeepAlive)
await args.WebSession.ServerConnection.StreamReader.WriteResponseBody(args.ProxyClient.ClientStream, args.WebSession.Response.IsChunked, args.WebSession.Response.ContentLength);
//write response if connection:keep-alive header exist and when version is http/1.0
//Because in Http 1.0 server can return a response without content-length (expectation being client would read until end of stream)
else if (args.WebSession.Response.ResponseKeepAlive && args.WebSession.Response.HttpVersion.Minor == 0)
await args.WebSession.ServerConnection.StreamReader.WriteResponseBody(args.ProxyClient.ClientStream, args.WebSession.Response.IsChunked, args.WebSession.Response.ContentLength);
}
......@@ -172,7 +177,7 @@ namespace Titanium.Web.Proxy
headers.RemoveAll(x => x.Name.ToLower() == "proxy-connection");
}
/// <summary>
/// Handle dispose of a client/server session
/// </summary>
......
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