Commit de33f72d authored by titanium007's avatar titanium007

Fix issues identified from review issue #27

parent 4ac7568b
...@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy.Test ...@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy.Test
//Read browser URL send back to proxy by the injection script in OnResponse event //Read browser URL send back to proxy by the injection script in OnResponse event
public void OnRequest(object sender, SessionEventArgs e) public void OnRequest(object sender, SessionEventArgs e)
{ {
Console.WriteLine(e.ProxySession.Request.RequestUrl); Console.WriteLine(e.ProxySession.Request.Url);
////read request headers ////read request headers
//var requestHeaders = e.ProxySession.Request.RequestHeaders; //var requestHeaders = e.ProxySession.Request.RequestHeaders;
...@@ -74,29 +74,23 @@ namespace Titanium.Web.Proxy.Test ...@@ -74,29 +74,23 @@ namespace Titanium.Web.Proxy.Test
//Insert script to read the Browser URL and send it back to proxy //Insert script to read the Browser URL and send it back to proxy
public void OnResponse(object sender, SessionEventArgs e) public void OnResponse(object sender, SessionEventArgs e)
{ {
////read response headers ////read response headers
var responseHeaders = e.ProxySession.Response.ResponseHeaders; var responseHeaders = e.ProxySession.Response.ResponseHeaders;
//if (e.ResponseStatusCode == "200")
//{ //if (!e.ProxySession.Request.Hostname.Equals("medeczane.sgk.gov.tr")) return;
// if (e.ResponseContentType.Trim().ToLower().Contains("text/html")) if (e.RequestMethod == "GET" || e.RequestMethod == "POST")
// { {
// //Get/Set response body bytes if (e.ProxySession.Response.ResponseStatusCode == "200")
// byte[] responseBodyBytes = e.GetResponseBody(); {
// e.SetResponseBody(responseBodyBytes); if (e.ProxySession.Response.ContentType.Trim().ToLower().Contains("text/html"))
{
// //Get response body as string string body = e.GetResponseBodyAsString(); //This line crashes
// string responseBody = e.GetResponseBodyAsString(); }
}
// //Modify e.ServerResponse }
// Regex rex = new Regex("</body>", RegexOptions.RightToLeft | RegexOptions.IgnoreCase | RegexOptions.Multiline);
// string modified = rex.Replace(responseBody, "<script type =\"text/javascript\">alert('Response was modified by this script!');</script></body>", 1);
// //Set modifed response Html Body
// e.SetResponseBodyString(modified);
// }
//}
} }
} }
} }
\ No newline at end of file
...@@ -35,24 +35,18 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -35,24 +35,18 @@ namespace Titanium.Web.Proxy.EventArguments
ProxySession = new HttpWebSession(); ProxySession = new HttpWebSession();
} }
public Client Client { get; set; } internal Client Client { get; set; }
public bool IsHttps { get; internal set; } public bool IsHttps { get; internal set; }
public HttpWebSession ProxySession { get; set; } public HttpWebSession ProxySession { get; set; }
public int RequestContentLength public int RequestContentLength
{ {
get get
{ {
if (ProxySession.Request.RequestHeaders.All(x => x.Name.ToLower() != "content-length")) return -1; return ProxySession.Request.ContentLength;
int contentLen;
int.TryParse(ProxySession.Request.RequestHeaders.First(x => x.Name.ToLower() == "content-length").Value, out contentLen);
if (contentLen != 0)
return contentLen;
return -1;
} }
} }
...@@ -71,9 +65,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -71,9 +65,7 @@ namespace Titanium.Web.Proxy.EventArguments
{ {
get get
{ {
return ProxySession.Response.ResponseHeaders.Any(x => x.Name.ToLower() == "content-type") return ProxySession.Response.ContentType;
? ProxySession.Response.ResponseHeaders.First(x => x.Name.ToLower() == "content-type").Value
: null;
} }
} }
...@@ -201,7 +193,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -201,7 +193,7 @@ namespace Titanium.Web.Proxy.EventArguments
responseBodyStream.Write(buffer, 0, buffer.Length); responseBodyStream.Write(buffer, 0, buffer.Length);
} }
switch (ProxySession.Response.ResponseContentEncoding) switch (ProxySession.Response.ContentEncoding)
{ {
case "gzip": case "gzip":
ProxySession.Response.ResponseBody = CompressionHelper.DecompressGzip(responseBodyStream.ToArray()); ProxySession.Response.ResponseBody = CompressionHelper.DecompressGzip(responseBodyStream.ToArray());
...@@ -223,12 +215,11 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -223,12 +215,11 @@ namespace Titanium.Web.Proxy.EventArguments
} }
public Encoding GetRequestBodyEncoding() public Encoding GetRequestBodyEncoding()
{ {
if (ProxySession.Request.RequestLocked) throw new Exception("You cannot call this function after request is made to server."); if (ProxySession.Request.RequestLocked) throw new Exception("You cannot call this function after request is made to server.");
return ProxySession.Request.RequestEncoding; return ProxySession.Request.Encoding;
} }
public byte[] GetRequestBody() public byte[] GetRequestBody()
...@@ -246,7 +237,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -246,7 +237,7 @@ namespace Titanium.Web.Proxy.EventArguments
ReadRequestBody(); ReadRequestBody();
return ProxySession.Request.RequestBodyString ?? (ProxySession.Request.RequestBodyString = ProxySession.Request.RequestEncoding.GetString(ProxySession.Request.RequestBody)); return ProxySession.Request.RequestBodyString ?? (ProxySession.Request.RequestBodyString = ProxySession.Request.Encoding.GetString(ProxySession.Request.RequestBody));
} }
public void SetRequestBody(byte[] body) public void SetRequestBody(byte[] body)
...@@ -271,7 +262,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -271,7 +262,7 @@ namespace Titanium.Web.Proxy.EventArguments
ReadRequestBody(); ReadRequestBody();
} }
ProxySession.Request.RequestBody = ProxySession.Request.RequestEncoding.GetBytes(body); ProxySession.Request.RequestBody = ProxySession.Request.Encoding.GetBytes(body);
ProxySession.Request.RequestBodyRead = true; ProxySession.Request.RequestBodyRead = true;
} }
...@@ -279,7 +270,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -279,7 +270,7 @@ namespace Titanium.Web.Proxy.EventArguments
{ {
if (!ProxySession.Request.RequestLocked) throw new Exception("You cannot call this function before request is made to server."); if (!ProxySession.Request.RequestLocked) throw new Exception("You cannot call this function before request is made to server.");
return ProxySession.Response.ResponseEncoding; return ProxySession.Response.Encoding;
} }
public byte[] GetResponseBody() public byte[] GetResponseBody()
...@@ -296,7 +287,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -296,7 +287,7 @@ namespace Titanium.Web.Proxy.EventArguments
GetResponseBody(); GetResponseBody();
return ProxySession.Response.ResponseBodyString ?? (ProxySession.Response.ResponseBodyString = ProxySession.Response.ResponseEncoding.GetString(ProxySession.Response.ResponseBody)); return ProxySession.Response.ResponseBodyString ?? (ProxySession.Response.ResponseBodyString = ProxySession.Response.Encoding.GetString(ProxySession.Response.ResponseBody));
} }
public void SetResponseBody(byte[] body) public void SetResponseBody(byte[] body)
...@@ -320,7 +311,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -320,7 +311,7 @@ namespace Titanium.Web.Proxy.EventArguments
GetResponseBody(); GetResponseBody();
} }
var bodyBytes = ProxySession.Response.ResponseEncoding.GetBytes(body); var bodyBytes = ProxySession.Response.Encoding.GetBytes(body);
SetResponseBody(bodyBytes); SetResponseBody(bodyBytes);
} }
...@@ -335,22 +326,20 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -335,22 +326,20 @@ namespace Titanium.Web.Proxy.EventArguments
var result = Encoding.Default.GetBytes(html); var result = Encoding.Default.GetBytes(html);
var connectStreamWriter = new StreamWriter(this.Client.ClientStream); var connectStreamWriter = new StreamWriter(this.Client.ClientStream);
var s = string.Format("HTTP/{0}.{1} {2} {3}", ProxySession.Request.RequestHttpVersion.Major, ProxySession.Request.RequestHttpVersion.Minor, 200, "Ok"); connectStreamWriter.WriteLine(string.Format("{0} {2} {3}", ProxySession.Request.HttpVersion, 200, "Ok"));
connectStreamWriter.WriteLine(s);
connectStreamWriter.WriteLine("Timestamp: {0}", DateTime.Now); connectStreamWriter.WriteLine("Timestamp: {0}", DateTime.Now);
connectStreamWriter.WriteLine("content-length: " + result.Length); connectStreamWriter.WriteLine("content-length: " + result.Length);
connectStreamWriter.WriteLine("Cache-Control: no-cache, no-store, must-revalidate"); connectStreamWriter.WriteLine("Cache-Control: no-cache, no-store, must-revalidate");
connectStreamWriter.WriteLine("Pragma: no-cache"); connectStreamWriter.WriteLine("Pragma: no-cache");
connectStreamWriter.WriteLine("Expires: 0"); connectStreamWriter.WriteLine("Expires: 0");
connectStreamWriter.WriteLine(ProxySession.Request.RequestIsAlive ? "Connection: Keep-Alive" : "Connection: close"); connectStreamWriter.WriteLine(ProxySession.Request.IsAlive ? "Connection: Keep-Alive" : "Connection: close");
connectStreamWriter.WriteLine(); connectStreamWriter.WriteLine();
connectStreamWriter.Flush(); connectStreamWriter.Flush();
this.Client.ClientStream.Write(result, 0, result.Length); this.Client.ClientStream.Write(result, 0, result.Length);
ProxySession.Request.CancelRequest = true; ProxySession.Request.CancelRequest = true;
} }
} }
......
...@@ -10,9 +10,9 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -10,9 +10,9 @@ namespace Titanium.Web.Proxy.Extensions
{ {
try try
{ {
if (request.Request.RequestContentType == null) return Encoding.GetEncoding("ISO-8859-1"); if (request.Request.ContentType == null) return Encoding.GetEncoding("ISO-8859-1");
var contentTypes = request.Request.RequestContentType.Split(';'); var contentTypes = request.Request.ContentType.Split(';');
foreach (var contentType in contentTypes) foreach (var contentType in contentTypes)
{ {
var encodingSplit = contentType.Split('='); var encodingSplit = contentType.Split('=');
......
...@@ -8,8 +8,8 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -8,8 +8,8 @@ namespace Titanium.Web.Proxy.Extensions
{ {
public static Encoding GetResponseEncoding(this HttpWebSession response) public static Encoding GetResponseEncoding(this HttpWebSession response)
{ {
if (string.IsNullOrEmpty(response.Response.ResponseCharacterSet)) return Encoding.GetEncoding("ISO-8859-1"); if (string.IsNullOrEmpty(response.Response.CharacterSet)) return Encoding.GetEncoding("ISO-8859-1");
return Encoding.GetEncoding(response.Response.ResponseCharacterSet.Replace(@"""", string.Empty)); return Encoding.GetEncoding(response.Response.CharacterSet.Replace(@"""", string.Empty));
} }
} }
} }
\ No newline at end of file
...@@ -16,20 +16,19 @@ namespace Titanium.Web.Proxy.Network ...@@ -16,20 +16,19 @@ namespace Titanium.Web.Proxy.Network
{ {
public string Method { get; internal set; } public string Method { get; internal set; }
public Uri RequestUri { get; internal set; } public Uri RequestUri { get; internal set; }
public string Version { get; internal set; } public string HttpVersion { get; internal set; }
public string RequestStatus { get; internal set; } public string Status { get; internal set; }
public int RequestContentLength { get; internal set; } public int ContentLength { get; internal set; }
public bool RequestSendChunked { get; internal set; } public bool SendChunked { get; internal set; }
public string RequestContentType { get; internal set; } public string ContentType { get; internal set; }
public bool RequestKeepAlive { get; internal set; } public bool KeepAlive { get; internal set; }
public string RequestHost { get; internal set; } public string Hostname { get; internal set; }
public string RequestUrl { get; internal set; } public string Url { get; internal set; }
internal Encoding RequestEncoding { get; set; } internal Encoding Encoding { get; set; }
internal Version RequestHttpVersion { get; set; } internal bool IsAlive { get; set; }
internal bool RequestIsAlive { get; set; }
internal bool CancelRequest { get; set; } internal bool CancelRequest { get; set; }
internal byte[] RequestBody { get; set; } internal byte[] RequestBody { get; set; }
internal string RequestBodyString { get; set; } internal string RequestBodyString { get; set; }
...@@ -48,20 +47,20 @@ namespace Titanium.Web.Proxy.Network ...@@ -48,20 +47,20 @@ namespace Titanium.Web.Proxy.Network
public class Response public class Response
{ {
internal Encoding ResponseEncoding { get; set; } internal Encoding Encoding { get; set; }
internal Stream ResponseStream { get; set; } internal Stream ResponseStream { get; set; }
internal byte[] ResponseBody { get; set; } internal byte[] ResponseBody { get; set; }
internal string ResponseBodyString { get; set; } internal string ResponseBodyString { get; set; }
internal bool ResponseBodyRead { get; set; } internal bool ResponseBodyRead { get; set; }
internal bool ResponseLocked { get; set; } internal bool ResponseLocked { get; set; }
public List<HttpHeader> ResponseHeaders { get; internal set; } public List<HttpHeader> ResponseHeaders { get; internal set; }
internal string ResponseCharacterSet { get; set; } internal string CharacterSet { get; set; }
internal string ResponseContentEncoding { get; set; } internal string ContentEncoding { get; set; }
internal System.Version ResponseProtocolVersion { get; set; } internal string HttpVersion { get; set; }
internal string ResponseStatusCode { get; set; } public string ResponseStatusCode { get; internal set; }
internal string ResponseStatusDescription { get; set; } public string ResponseStatusDescription { get; internal set; }
internal bool ResponseKeepAlive { get; set; } internal bool ResponseKeepAlive { get; set; }
internal string ResponseContentType { get; set; } public string ContentType { get; internal set; }
internal int ContentLength { get; set; } internal int ContentLength { get; set; }
internal bool IsChunked { get; set; } internal bool IsChunked { get; set; }
...@@ -110,7 +109,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -110,7 +109,7 @@ namespace Titanium.Web.Proxy.Network
{ {
this.Request.Method, this.Request.Method,
this.Request.RequestUri.PathAndQuery, this.Request.RequestUri.PathAndQuery,
this.Request.Version this.Request.HttpVersion
})); }));
foreach (HttpHeader httpHeader in this.Request.RequestHeaders) foreach (HttpHeader httpHeader in this.Request.RequestHeaders)
...@@ -134,19 +133,8 @@ namespace Titanium.Web.Proxy.Network ...@@ -134,19 +133,8 @@ namespace Titanium.Web.Proxy.Network
{ {
var s = ProxyClient.ServerStreamReader.ReadLine(); var s = ProxyClient.ServerStreamReader.ReadLine();
} }
var httpVersion = httpResult[0];
Version version; this.Response.HttpVersion = httpResult[0];
if (httpVersion == "HTTP/1.1")
{
version = new Version(1, 1);
}
else
{
version = new Version(1, 0);
}
this.Response.ResponseProtocolVersion = version;
this.Response.ResponseStatusCode = httpResult[1]; this.Response.ResponseStatusCode = httpResult[1];
string status = httpResult[2]; string status = httpResult[2];
......
...@@ -177,21 +177,20 @@ namespace Titanium.Web.Proxy ...@@ -177,21 +177,20 @@ namespace Titanium.Web.Proxy
args.ProxySession.Request.RequestUri = httpRemoteUri; args.ProxySession.Request.RequestUri = httpRemoteUri;
args.ProxySession.Request.Method = httpMethod; args.ProxySession.Request.Method = httpMethod;
args.ProxySession.Request.Version = httpVersion; args.ProxySession.Request.HttpVersion = httpVersion;
args.Client.ClientStream = clientStream; args.Client.ClientStream = clientStream;
args.Client.ClientStreamReader = clientStreamReader; args.Client.ClientStreamReader = clientStreamReader;
args.Client.ClientStreamWriter = clientStreamWriter; args.Client.ClientStreamWriter = clientStreamWriter;
args.ProxySession.Request.RequestHost = args.ProxySession.Request.RequestUri.Host; args.ProxySession.Request.Hostname = args.ProxySession.Request.RequestUri.Host;
args.ProxySession.Request.RequestUrl = args.ProxySession.Request.RequestUri.OriginalString; args.ProxySession.Request.Url = args.ProxySession.Request.RequestUri.OriginalString;
args.Client.ClientPort = ((IPEndPoint)client.Client.RemoteEndPoint).Port; args.Client.ClientPort = ((IPEndPoint)client.Client.RemoteEndPoint).Port;
args.Client.ClientIpAddress = ((IPEndPoint)client.Client.RemoteEndPoint).Address; args.Client.ClientIpAddress = ((IPEndPoint)client.Client.RemoteEndPoint).Address;
args.ProxySession.Request.RequestHttpVersion = version;
//If requested interception //If requested interception
if (BeforeRequest != null) if (BeforeRequest != null)
{ {
args.ProxySession.Request.RequestEncoding = args.ProxySession.GetEncoding(); args.ProxySession.Request.Encoding = args.ProxySession.GetEncoding();
BeforeRequest(null, args); BeforeRequest(null, args);
} }
...@@ -207,10 +206,10 @@ namespace Titanium.Web.Proxy ...@@ -207,10 +206,10 @@ namespace Titanium.Web.Proxy
//construct the web request that we are going to issue on behalf of the client. //construct the web request that we are going to issue on behalf of the client.
connection = connection == null ? connection = connection == null ?
TcpConnectionManager.GetClient(args.ProxySession.Request.RequestUri.Host, args.ProxySession.Request.RequestUri.Port, args.IsHttps) TcpConnectionManager.GetClient(args.ProxySession.Request.RequestUri.Host, args.ProxySession.Request.RequestUri.Port, args.IsHttps)
: lastRequestHostName != args.ProxySession.Request.RequestHost ? TcpConnectionManager.GetClient(args.ProxySession.Request.RequestUri.Host, args.ProxySession.Request.RequestUri.Port, args.IsHttps) : lastRequestHostName != args.ProxySession.Request.Hostname ? TcpConnectionManager.GetClient(args.ProxySession.Request.RequestUri.Host, args.ProxySession.Request.RequestUri.Port, args.IsHttps)
: connection; : connection;
lastRequestHostName = args.ProxySession.Request.RequestHost; lastRequestHostName = args.ProxySession.Request.Hostname;
args.ProxySession.SetConnection(connection); args.ProxySession.SetConnection(connection);
args.ProxySession.SendRequest(); args.ProxySession.SendRequest();
...@@ -218,7 +217,7 @@ namespace Titanium.Web.Proxy ...@@ -218,7 +217,7 @@ namespace Titanium.Web.Proxy
//If request was modified by user //If request was modified by user
if (args.ProxySession.Request.RequestBodyRead) if (args.ProxySession.Request.RequestBodyRead)
{ {
args.ProxySession.Request.RequestContentLength = args.ProxySession.Request.RequestBody.Length; args.ProxySession.Request.ContentLength = args.ProxySession.Request.RequestBody.Length;
var newStream = args.ProxySession.ProxyClient.ServerStreamReader.BaseStream; var newStream = args.ProxySession.ProxyClient.ServerStreamReader.BaseStream;
newStream.Write(args.ProxySession.Request.RequestBody, 0, args.ProxySession.Request.RequestBody.Length); newStream.Write(args.ProxySession.Request.RequestBody, 0, args.ProxySession.Request.RequestBody.Length);
} }
...@@ -276,25 +275,25 @@ namespace Titanium.Web.Proxy ...@@ -276,25 +275,25 @@ namespace Titanium.Web.Proxy
break; break;
case "connection": case "connection":
if (requestHeaders[i].Value.ToLower() == "keep-alive") if (requestHeaders[i].Value.ToLower() == "keep-alive")
webRequest.Request.RequestKeepAlive = true; webRequest.Request.KeepAlive = true;
break; break;
case "content-length": case "content-length":
int contentLen; int contentLen;
int.TryParse(requestHeaders[i].Value, out contentLen); int.TryParse(requestHeaders[i].Value, out contentLen);
if (contentLen != 0) if (contentLen != 0)
webRequest.Request.RequestContentLength = contentLen; webRequest.Request.ContentLength = contentLen;
break; break;
case "content-type": case "content-type":
webRequest.Request.RequestContentType = requestHeaders[i].Value; webRequest.Request.ContentType = requestHeaders[i].Value;
break; break;
case "host": case "host":
webRequest.Request.RequestHost = requestHeaders[i].Value; webRequest.Request.Hostname = requestHeaders[i].Value;
break; break;
case "proxy-connection": case "proxy-connection":
if (requestHeaders[i].Value.ToLower() == "keep-alive") if (requestHeaders[i].Value.ToLower() == "keep-alive")
webRequest.Request.RequestKeepAlive = true; webRequest.Request.KeepAlive = true;
else if (requestHeaders[i].Value.ToLower() == "close") else if (requestHeaders[i].Value.ToLower() == "close")
webRequest.Request.RequestKeepAlive = false; webRequest.Request.KeepAlive = false;
break; break;
case "upgrade": case "upgrade":
...@@ -306,9 +305,9 @@ namespace Titanium.Web.Proxy ...@@ -306,9 +305,9 @@ namespace Titanium.Web.Proxy
//But how to identify if client is sending chunked body for PUT/POST? //But how to identify if client is sending chunked body for PUT/POST?
case "transfer-encoding": case "transfer-encoding":
if (requestHeaders[i].Value.ToLower().Contains("chunked")) if (requestHeaders[i].Value.ToLower().Contains("chunked"))
webRequest.Request.RequestSendChunked = true; webRequest.Request.SendChunked = true;
else else
webRequest.Request.RequestSendChunked = false; webRequest.Request.SendChunked = false;
break; break;
default: default:
...@@ -343,7 +342,7 @@ namespace Titanium.Web.Proxy ...@@ -343,7 +342,7 @@ namespace Titanium.Web.Proxy
var postStream = args.ProxySession.ProxyClient.Stream; var postStream = args.ProxySession.ProxyClient.Stream;
if (args.ProxySession.Request.RequestContentLength > 0) if (args.ProxySession.Request.ContentLength > 0)
{ {
//args.ProxyRequest.AllowWriteStreamBuffering = true; //args.ProxyRequest.AllowWriteStreamBuffering = true;
try try
...@@ -351,20 +350,20 @@ namespace Titanium.Web.Proxy ...@@ -351,20 +350,20 @@ namespace Titanium.Web.Proxy
var totalbytesRead = 0; var totalbytesRead = 0;
int bytesToRead; int bytesToRead;
if (args.ProxySession.Request.RequestContentLength < BUFFER_SIZE) if (args.ProxySession.Request.ContentLength < BUFFER_SIZE)
{ {
bytesToRead = (int)args.ProxySession.Request.RequestContentLength; bytesToRead = (int)args.ProxySession.Request.ContentLength;
} }
else else
bytesToRead = BUFFER_SIZE; bytesToRead = BUFFER_SIZE;
while (totalbytesRead < (int)args.ProxySession.Request.RequestContentLength) while (totalbytesRead < (int)args.ProxySession.Request.ContentLength)
{ {
var buffer = args.Client.ClientStreamReader.ReadBytes(bytesToRead); var buffer = args.Client.ClientStreamReader.ReadBytes(bytesToRead);
totalbytesRead += buffer.Length; totalbytesRead += buffer.Length;
var remainingBytes = (int)args.ProxySession.Request.RequestContentLength - totalbytesRead; var remainingBytes = (int)args.ProxySession.Request.ContentLength - totalbytesRead;
if (remainingBytes < bytesToRead) if (remainingBytes < bytesToRead)
{ {
bytesToRead = remainingBytes; bytesToRead = remainingBytes;
...@@ -378,7 +377,7 @@ namespace Titanium.Web.Proxy ...@@ -378,7 +377,7 @@ namespace Titanium.Web.Proxy
} }
} }
//Need to revist, find any potential bugs //Need to revist, find any potential bugs
else if (args.ProxySession.Request.RequestSendChunked) else if (args.ProxySession.Request.SendChunked)
{ {
try try
{ {
......
...@@ -31,7 +31,7 @@ namespace Titanium.Web.Proxy ...@@ -31,7 +31,7 @@ namespace Titanium.Web.Proxy
if (BeforeResponse != null) if (BeforeResponse != null)
{ {
args.ProxySession.Response.ResponseEncoding = args.ProxySession.GetResponseEncoding(); args.ProxySession.Response.Encoding = args.ProxySession.GetResponseEncoding();
BeforeResponse(null, args); BeforeResponse(null, args);
} }
...@@ -40,7 +40,7 @@ namespace Titanium.Web.Proxy ...@@ -40,7 +40,7 @@ namespace Titanium.Web.Proxy
if (args.ProxySession.Response.ResponseBodyRead) if (args.ProxySession.Response.ResponseBodyRead)
{ {
var isChunked = args.ProxySession.Response.IsChunked; var isChunked = args.ProxySession.Response.IsChunked;
var contentEncoding = args.ProxySession.Response.ResponseContentEncoding; var contentEncoding = args.ProxySession.Response.ContentEncoding;
if(contentEncoding!=null) if(contentEncoding!=null)
switch (contentEncoding) switch (contentEncoding)
...@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy ...@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy
break; break;
} }
WriteResponseStatus(args.ProxySession.Response.ResponseProtocolVersion, args.ProxySession.Response.ResponseStatusCode, WriteResponseStatus(args.ProxySession.Response.HttpVersion, args.ProxySession.Response.ResponseStatusCode,
args.ProxySession.Response.ResponseStatusDescription, args.Client.ClientStreamWriter); args.ProxySession.Response.ResponseStatusDescription, args.Client.ClientStreamWriter);
WriteResponseHeaders(args.Client.ClientStreamWriter, args.ProxySession.Response.ResponseHeaders, args.ProxySession.Response.ResponseBody.Length, WriteResponseHeaders(args.Client.ClientStreamWriter, args.ProxySession.Response.ResponseHeaders, args.ProxySession.Response.ResponseBody.Length,
isChunked); isChunked);
...@@ -64,7 +64,7 @@ namespace Titanium.Web.Proxy ...@@ -64,7 +64,7 @@ namespace Titanium.Web.Proxy
} }
else else
{ {
WriteResponseStatus(args.ProxySession.Response.ResponseProtocolVersion, args.ProxySession.Response.ResponseStatusCode, WriteResponseStatus(args.ProxySession.Response.HttpVersion, args.ProxySession.Response.ResponseStatusCode,
args.ProxySession.Response.ResponseStatusDescription, args.Client.ClientStreamWriter); args.ProxySession.Response.ResponseStatusDescription, args.Client.ClientStreamWriter);
WriteResponseHeaders(args.Client.ClientStreamWriter, args.ProxySession.Response.ResponseHeaders); WriteResponseHeaders(args.Client.ClientStreamWriter, args.ProxySession.Response.ResponseHeaders);
...@@ -96,17 +96,17 @@ namespace Titanium.Web.Proxy ...@@ -96,17 +96,17 @@ namespace Titanium.Web.Proxy
break; break;
case "content-encoding": case "content-encoding":
response.Response.ResponseContentEncoding = response.Response.ResponseHeaders[i].Value.Trim().ToLower(); response.Response.ContentEncoding = response.Response.ResponseHeaders[i].Value.Trim().ToLower();
break; break;
case "content-type": case "content-type":
if (response.Response.ResponseHeaders[i].Value.Contains(";")) if (response.Response.ResponseHeaders[i].Value.Contains(";"))
{ {
response.Response.ResponseContentType = response.Response.ResponseHeaders[i].Value.Split(';')[0].Trim(); response.Response.ContentType = response.Response.ResponseHeaders[i].Value.Split(';')[0].Trim();
response.Response.ResponseCharacterSet = response.Response.ResponseHeaders[i].Value.Split(';')[1].ToLower().Replace("charset=", string.Empty).Trim(); response.Response.CharacterSet = response.Response.ResponseHeaders[i].Value.Split(';')[1].ToLower().Replace("charset=", string.Empty).Trim();
} }
else else
response.Response.ResponseContentType = response.Response.ResponseHeaders[i].Value.ToLower().Trim(); response.Response.ContentType = response.Response.ResponseHeaders[i].Value.ToLower().Trim();
break; break;
case "transfer-encoding": case "transfer-encoding":
...@@ -128,11 +128,10 @@ namespace Titanium.Web.Proxy ...@@ -128,11 +128,10 @@ namespace Titanium.Web.Proxy
} }
private static void WriteResponseStatus(Version version, string code, string description, private static void WriteResponseStatus(string version, string code, string description,
StreamWriter responseWriter) StreamWriter responseWriter)
{ {
var s = string.Format("HTTP/{0}.{1} {2} {3}", version.Major, version.Minor, code, description); responseWriter.WriteLine(string.Format("{0} {1} {2}", version, code, description));
responseWriter.WriteLine(s);
} }
private static void WriteResponseHeaders(StreamWriter responseWriter, List<HttpHeader> headers) private static void WriteResponseHeaders(StreamWriter responseWriter, List<HttpHeader> 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