Commit 56270351 authored by titanium007's avatar titanium007

update comments

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