Commit 8242536d authored by titanium007's avatar titanium007

Separate Request & Response

parent 27fc293a
...@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy.EventArguments
internal bool RequestBodyRead { get; set; } internal bool RequestBodyRead { get; set; }
public List<HttpHeader> RequestHeaders { get; internal set; } public List<HttpHeader> RequestHeaders { get; internal set; }
internal bool RequestLocked { get; set; } internal bool RequestLocked { get; set; }
internal HttpWebClient ProxySession { get; set; } internal HttpWebSession ProxySession { get; set; }
internal Encoding ResponseEncoding { get; set; } internal Encoding ResponseEncoding { get; set; }
internal Stream ResponseStream { get; set; } internal Stream ResponseStream { get; set; }
...@@ -69,13 +69,13 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -69,13 +69,13 @@ namespace Titanium.Web.Proxy.EventArguments
public string RequestMethod public string RequestMethod
{ {
get { return ProxySession.Method; } get { return ProxySession.Request.Method; }
} }
public string ResponseStatusCode public string ResponseStatusCode
{ {
get { return ProxySession.ResponseStatusCode; } get { return ProxySession.Response.ResponseStatusCode; }
} }
public string ResponseContentType public string ResponseContentType
...@@ -102,7 +102,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -102,7 +102,7 @@ namespace Titanium.Web.Proxy.EventArguments
private void ReadRequestBody() private void ReadRequestBody()
{ {
if ((ProxySession.Method.ToUpper() != "POST" && ProxySession.Method.ToUpper() != "PUT")) if ((ProxySession.Request.Method.ToUpper() != "POST" && ProxySession.Request.Method.ToUpper() != "PUT"))
{ {
throw new BodyNotFoundException("Request don't have a body." + throw new BodyNotFoundException("Request don't have a body." +
"Please verify that this request is a Http POST/PUT and request content length is greater than zero before accessing the body."); "Please verify that this request is a Http POST/PUT and request content length is greater than zero before accessing the body.");
...@@ -189,7 +189,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -189,7 +189,7 @@ namespace Titanium.Web.Proxy.EventArguments
{ {
if (ResponseBody == null) if (ResponseBody == null)
{ {
switch ( ProxySession.ResponseContentEncoding) switch ( ProxySession.Response.ResponseContentEncoding)
{ {
case "gzip": case "gzip":
ResponseBody = CompressionHelper.DecompressGzip(ResponseStream); ResponseBody = CompressionHelper.DecompressGzip(ResponseStream);
......
...@@ -6,13 +6,13 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -6,13 +6,13 @@ namespace Titanium.Web.Proxy.Extensions
{ {
public static class HttpWebRequestExtensions public static class HttpWebRequestExtensions
{ {
public static Encoding GetEncoding(this HttpWebClient request) public static Encoding GetEncoding(this HttpWebSession request)
{ {
try try
{ {
if (request.RequestContentType == null) return Encoding.GetEncoding("ISO-8859-1"); if (request.Request.RequestContentType == null) return Encoding.GetEncoding("ISO-8859-1");
var contentTypes = request.RequestContentType.Split(';'); var contentTypes = request.Request.RequestContentType.Split(';');
foreach (var contentType in contentTypes) foreach (var contentType in contentTypes)
{ {
var encodingSplit = contentType.Split('='); var encodingSplit = contentType.Split('=');
......
...@@ -6,10 +6,10 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -6,10 +6,10 @@ namespace Titanium.Web.Proxy.Extensions
{ {
public static class HttpWebResponseExtensions public static class HttpWebResponseExtensions
{ {
public static Encoding GetResponseEncoding(this HttpWebClient response) public static Encoding GetResponseEncoding(this HttpWebSession response)
{ {
if (string.IsNullOrEmpty(response.ResponseCharacterSet)) return Encoding.GetEncoding("ISO-8859-1"); if (string.IsNullOrEmpty(response.Response.ResponseCharacterSet)) return Encoding.GetEncoding("ISO-8859-1");
return Encoding.GetEncoding(response.ResponseCharacterSet.Replace(@"""",string.Empty)); return Encoding.GetEncoding(response.Response.ResponseCharacterSet.Replace(@"""", string.Empty));
} }
} }
} }
\ No newline at end of file
...@@ -12,10 +12,8 @@ using Titanium.Web.Proxy.Models; ...@@ -12,10 +12,8 @@ using Titanium.Web.Proxy.Models;
namespace Titanium.Web.Proxy.Http namespace Titanium.Web.Proxy.Http
{ {
public class HttpWebClient public class Request
{ {
private const string Space = " ";
public string Method { get; set; } public string Method { get; set; }
public Uri RequestUri { get; set; } public Uri RequestUri { get; set; }
...@@ -24,30 +22,75 @@ namespace Titanium.Web.Proxy.Http ...@@ -24,30 +22,75 @@ namespace Titanium.Web.Proxy.Http
public List<HttpHeader> RequestHeaders { get; set; } public List<HttpHeader> RequestHeaders { get; set; }
public bool IsSecure public string RequestStatus { get; set; }
public int RequestContentLength { get; set; }
public bool RequestSendChunked { get; set; }
public string RequestContentType { get; set; }
public bool RequestKeepAlive { get; set; }
public string RequestHost { get; set; }
public Request()
{ {
get this.RequestHeaders = new List<HttpHeader>();
{
return this.RequestUri.Scheme == Uri.UriSchemeHttps;
}
} }
}
public TcpClient Client { get; set; } public class Response
{
public string RequestStatus { get; set; }
public List<HttpHeader> ResponseHeaders { get; set; } public List<HttpHeader> ResponseHeaders { get; set; }
public int RequestContentLength { get; set; } public string ResponseCharacterSet { get; set; }
public bool RequestSendChunked { get; set; } public string ResponseContentEncoding { get; set; }
public System.Version ResponseProtocolVersion { get; set; }
public string ResponseStatusCode { get; set; }
public string ResponseStatusDescription { get; set; }
public bool ResponseKeepAlive { get; set; }
public string ResponseContentType { get; set; }
public HttpWebClient() public Response()
{ {
this.RequestHeaders = new List<HttpHeader>();
this.ResponseHeaders = new List<HttpHeader>(); this.ResponseHeaders = new List<HttpHeader>();
} }
public int ContentLength { get; set; }
}
public class HttpWebSession
{
private const string Space = " ";
public bool IsSecure
{
get
{
return this.Request.RequestUri.Scheme == Uri.UriSchemeHttps;
}
}
public Request Request { get; set; }
public Response Response { get; set; }
public TcpClient Client { get; set; }
public HttpWebSession()
{
this.Request = new Request();
this.Response = new Response();
}
public CustomBinaryReader ServerStreamReader { get; set; } public CustomBinaryReader ServerStreamReader { get; set; }
public async Task SendRequest() public async Task SendRequest()
...@@ -58,12 +101,12 @@ namespace Titanium.Web.Proxy.Http ...@@ -58,12 +101,12 @@ namespace Titanium.Web.Proxy.Http
requestLines.AppendLine(string.Join(" ", new string[3] requestLines.AppendLine(string.Join(" ", new string[3]
{ {
this.Method, this.Request.Method,
this.RequestUri.AbsolutePath, this.Request.RequestUri.AbsolutePath,
this.Version this.Request.Version
})); }));
foreach (HttpHeader httpHeader in this.RequestHeaders) foreach (HttpHeader httpHeader in this.Request.RequestHeaders)
{ {
requestLines.AppendLine(httpHeader.Name + ':' + httpHeader.Value); requestLines.AppendLine(httpHeader.Name + ':' + httpHeader.Value);
...@@ -77,7 +120,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -77,7 +120,7 @@ namespace Titanium.Web.Proxy.Http
await AsyncExtensions.FlushAsync((Stream)stream); await AsyncExtensions.FlushAsync((Stream)stream);
} }
public void ReceiveResponse() public void ReceiveResponse()
{ {
Stream stream = Client.GetStream(); Stream stream = Client.GetStream();
ServerStreamReader = new CustomBinaryReader(stream, Encoding.ASCII); ServerStreamReader = new CustomBinaryReader(stream, Encoding.ASCII);
...@@ -95,46 +138,26 @@ namespace Titanium.Web.Proxy.Http ...@@ -95,46 +138,26 @@ namespace Titanium.Web.Proxy.Http
version = new Version(1, 0); version = new Version(1, 0);
} }
this.ResponseProtocolVersion = version; this.Response.ResponseProtocolVersion = version;
this.ResponseStatusCode = httpResult[1]; this.Response.ResponseStatusCode = httpResult[1];
string status = httpResult[2]; string status = httpResult[2];
for (int i = 3; i < httpResult.Length; i++) for (int i = 3; i < httpResult.Length; i++)
{ {
status = status + Space + httpResult[i]; status = status + Space + httpResult[i];
} }
this.ResponseStatusDescription = status; this.Response.ResponseStatusDescription = status;
List<string> responseLines = ServerStreamReader.ReadAllLines(); List<string> responseLines = ServerStreamReader.ReadAllLines();
for (int index = 0; index < responseLines.Count; ++index) for (int index = 0; index < responseLines.Count; ++index)
{ {
string[] strArray = responseLines[index].Split(':'); string[] strArray = responseLines[index].Split(':');
this.ResponseHeaders.Add(new HttpHeader(strArray[0], strArray[1])); this.Response.ResponseHeaders.Add(new HttpHeader(strArray[0], strArray[1]));
} }
} }
public string RequestContentType { get; set; }
public bool RequestKeepAlive { get; set; }
public string RequestHost { get; set; }
public string ResponseCharacterSet { get; set; }
public string ResponseContentEncoding { get; set; }
public System.Version ResponseProtocolVersion { get; set; }
public string ResponseStatusCode { get; set; }
public string ResponseStatusDescription { get; set; }
public bool ResponseKeepAlive { get; set; }
public string ResponseContentType { get; set; }
} }
......
...@@ -176,28 +176,28 @@ namespace Titanium.Web.Proxy ...@@ -176,28 +176,28 @@ 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.
args.ProxySession = new Http.HttpWebClient(); args.ProxySession = new Http.HttpWebSession();
args.ProxySession.RequestUri = httpRemoteUri; args.ProxySession.Request.RequestUri = httpRemoteUri;
//args.ProxyRequest.Proxy = null; //args.ProxyRequest.Proxy = null;
//args.ProxyRequest.UseDefaultCredentials = true; //args.ProxyRequest.UseDefaultCredentials = true;
args.ProxySession.Method = httpMethod; args.ProxySession.Request.Method = httpMethod;
args.ProxySession.Version = httpVersion; args.ProxySession.Request.Version = httpVersion;
// args.ProxyRequest.ProtocolVersion = version; // args.ProxyRequest.ProtocolVersion = version;
args.ClientStream = clientStream; args.ClientStream = clientStream;
args.ClientStreamReader = clientStreamReader; args.ClientStreamReader = clientStreamReader;
args.ClientStreamWriter = clientStreamWriter; args.ClientStreamWriter = clientStreamWriter;
// args.ProxyRequest.AllowAutoRedirect = false; // args.ProxyRequest.AllowAutoRedirect = false;
// args.ProxyRequest.AutomaticDecompression = DecompressionMethods.None; // args.ProxyRequest.AutomaticDecompression = DecompressionMethods.None;
args.RequestHostname = args.ProxySession.RequestUri.Host; args.RequestHostname = args.ProxySession.Request.RequestUri.Host;
args.RequestUrl = args.ProxySession.RequestUri.OriginalString; args.RequestUrl = args.ProxySession.Request.RequestUri.OriginalString;
args.ClientPort = ((IPEndPoint)client.Client.RemoteEndPoint).Port; args.ClientPort = ((IPEndPoint)client.Client.RemoteEndPoint).Port;
args.ClientIpAddress = ((IPEndPoint)client.Client.RemoteEndPoint).Address; args.ClientIpAddress = ((IPEndPoint)client.Client.RemoteEndPoint).Address;
args.RequestHttpVersion = version; args.RequestHttpVersion = version;
//args.RequestIsAlive = args.ProxyRequest.KeepAlive; //args.RequestIsAlive = args.ProxyRequest.KeepAlive;
//args.ProxyRequest.AllowWriteStreamBuffering = true; //args.ProxyRequest.AllowWriteStreamBuffering = true;
args.Client = await TcpConnectionManager.GetClient(args.ProxySession.RequestUri.Host, args.ProxySession.RequestUri.Port, args.IsHttps); args.Client = await TcpConnectionManager.GetClient(args.ProxySession.Request.RequestUri.Host, args.ProxySession.Request.RequestUri.Port, args.IsHttps);
args.ProxySession.Client = args.Client; args.ProxySession.Client = args.Client;
//If requested interception //If requested interception
if (BeforeRequest != null) if (BeforeRequest != null)
...@@ -221,7 +221,7 @@ namespace Titanium.Web.Proxy ...@@ -221,7 +221,7 @@ namespace Titanium.Web.Proxy
//If request was modified by user //If request was modified by user
if (args.RequestBodyRead) if (args.RequestBodyRead)
{ {
args.ProxySession.RequestContentLength = args.RequestBody.Length; args.ProxySession.Request.RequestContentLength = args.RequestBody.Length;
var newStream = args.ProxySession.ServerStreamReader.BaseStream; var newStream = args.ProxySession.ServerStreamReader.BaseStream;
newStream.Write(args.RequestBody, 0, args.RequestBody.Length); newStream.Write(args.RequestBody, 0, args.RequestBody.Length);
} }
...@@ -243,6 +243,7 @@ namespace Titanium.Web.Proxy ...@@ -243,6 +243,7 @@ namespace Titanium.Web.Proxy
return; return;
} }
//TcpConnectionManager.AddClient(args.ProxySession.Request.RequestUri.Host, args.ProxySession.Request.RequestUri.Port, args.IsHttps, args.ProxySession.Client);
// read the next request // read the next request
httpCmd = clientStreamReader.ReadLine(); httpCmd = clientStreamReader.ReadLine();
...@@ -264,7 +265,7 @@ namespace Titanium.Web.Proxy ...@@ -264,7 +265,7 @@ namespace Titanium.Web.Proxy
clientStreamWriter.Flush(); clientStreamWriter.Flush();
} }
private static void SetRequestHeaders(List<HttpHeader> requestHeaders, HttpWebClient webRequest) private static void SetRequestHeaders(List<HttpHeader> requestHeaders, HttpWebSession webRequest)
{ {
for (var i = 0; i < requestHeaders.Count; i++) for (var i = 0; i < requestHeaders.Count; i++)
{ {
...@@ -281,16 +282,16 @@ namespace Titanium.Web.Proxy ...@@ -281,16 +282,16 @@ 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.RequestKeepAlive = true; webRequest.Request.RequestKeepAlive = 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.RequestContentLength = contentLen; webRequest.Request.RequestContentLength = contentLen;
break; break;
case "content-type": case "content-type":
webRequest.RequestContentType = requestHeaders[i].Value; webRequest.Request.RequestContentType = requestHeaders[i].Value;
break; break;
case "expect": case "expect":
//if (requestHeaders[i].Value.ToLower() == "100-continue") //if (requestHeaders[i].Value.ToLower() == "100-continue")
...@@ -299,7 +300,7 @@ namespace Titanium.Web.Proxy ...@@ -299,7 +300,7 @@ namespace Titanium.Web.Proxy
// webRequest.Expect = requestHeaders[i].Value; // webRequest.Expect = requestHeaders[i].Value;
break; break;
case "host": case "host":
webRequest.RequestHost = requestHeaders[i].Value; webRequest.Request.RequestHost = requestHeaders[i].Value;
break; break;
case "if-modified-since": case "if-modified-since":
// var sb = requestHeaders[i].Value.Trim().Split(SemiSplit); // var sb = requestHeaders[i].Value.Trim().Split(SemiSplit);
...@@ -309,9 +310,9 @@ namespace Titanium.Web.Proxy ...@@ -309,9 +310,9 @@ namespace Titanium.Web.Proxy
break; break;
case "proxy-connection": case "proxy-connection":
if (requestHeaders[i].Value.ToLower() == "keep-alive") if (requestHeaders[i].Value.ToLower() == "keep-alive")
webRequest.RequestKeepAlive = true; webRequest.Request.RequestKeepAlive = true;
else if (requestHeaders[i].Value.ToLower() == "close") else if (requestHeaders[i].Value.ToLower() == "close")
webRequest.RequestKeepAlive = false; webRequest.Request.RequestKeepAlive = false;
break; break;
case "range": case "range":
// var startEnd = requestHeaders[i].Value.Replace(Environment.NewLine, "").Remove(0, 6).Split('-'); // var startEnd = requestHeaders[i].Value.Replace(Environment.NewLine, "").Remove(0, 6).Split('-');
...@@ -335,9 +336,9 @@ namespace Titanium.Web.Proxy ...@@ -335,9 +336,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.RequestSendChunked = true; webRequest.Request.RequestSendChunked = true;
else else
webRequest.RequestSendChunked = false; webRequest.Request.RequestSendChunked = false;
break; break;
case "upgrade": case "upgrade":
// if (requestHeaders[i].Value.ToLower() == "http/1.1") // if (requestHeaders[i].Value.ToLower() == "http/1.1")
...@@ -351,7 +352,7 @@ namespace Titanium.Web.Proxy ...@@ -351,7 +352,7 @@ namespace Titanium.Web.Proxy
} }
} }
webRequest.RequestHeaders = requestHeaders; webRequest.Request.RequestHeaders = requestHeaders;
} }
//This is called when the request is PUT/POST to read the body //This is called when the request is PUT/POST to read the body
...@@ -361,7 +362,7 @@ namespace Titanium.Web.Proxy ...@@ -361,7 +362,7 @@ namespace Titanium.Web.Proxy
var postStream = args.ProxySession.ServerStreamReader; var postStream = args.ProxySession.ServerStreamReader;
if (args.ProxySession.RequestContentLength > 0) if (args.ProxySession.Request.RequestContentLength > 0)
{ {
//args.ProxyRequest.AllowWriteStreamBuffering = true; //args.ProxyRequest.AllowWriteStreamBuffering = true;
try try
...@@ -369,20 +370,20 @@ namespace Titanium.Web.Proxy ...@@ -369,20 +370,20 @@ namespace Titanium.Web.Proxy
var totalbytesRead = 0; var totalbytesRead = 0;
int bytesToRead; int bytesToRead;
if (args.ProxySession.RequestContentLength < BUFFER_SIZE) if (args.ProxySession.Request.RequestContentLength < BUFFER_SIZE)
{ {
bytesToRead = (int)args.ProxySession.RequestContentLength; bytesToRead = (int)args.ProxySession.Request.RequestContentLength;
} }
else else
bytesToRead = BUFFER_SIZE; bytesToRead = BUFFER_SIZE;
while (totalbytesRead < (int)args.ProxySession.RequestContentLength) while (totalbytesRead < (int)args.ProxySession.Request.RequestContentLength)
{ {
var buffer = args.ClientStreamReader.ReadBytes(bytesToRead); var buffer = args.ClientStreamReader.ReadBytes(bytesToRead);
totalbytesRead += buffer.Length; totalbytesRead += buffer.Length;
var remainingBytes = (int)args.ProxySession.RequestContentLength - totalbytesRead; var remainingBytes = (int)args.ProxySession.Request.RequestContentLength - totalbytesRead;
if (remainingBytes < bytesToRead) if (remainingBytes < bytesToRead)
{ {
bytesToRead = remainingBytes; bytesToRead = remainingBytes;
...@@ -400,7 +401,7 @@ namespace Titanium.Web.Proxy ...@@ -400,7 +401,7 @@ namespace Titanium.Web.Proxy
} }
} }
//Need to revist, find any potential bugs //Need to revist, find any potential bugs
else if (args.ProxySession.RequestSendChunked) else if (args.ProxySession.Request.RequestSendChunked)
{ {
//args.ProxyRequest.AllowWriteStreamBuffering = true; //args.ProxyRequest.AllowWriteStreamBuffering = true;
......
...@@ -39,8 +39,8 @@ namespace Titanium.Web.Proxy ...@@ -39,8 +39,8 @@ namespace Titanium.Web.Proxy
if (args.ResponseBodyRead) if (args.ResponseBodyRead)
{ {
var isChunked = args.ProxySession.ResponseHeaders.Any(x => x.Name.ToLower() == "transfer-encoding" && x.Value.ToLower().Contains("chunked")); var isChunked = args.ProxySession.Response.ResponseHeaders.Any(x => x.Name.ToLower() == "transfer-encoding" && x.Value.ToLower().Contains("chunked"));
var contentEncoding = args.ProxySession.ResponseContentEncoding; var contentEncoding = args.ProxySession.Response.ResponseContentEncoding;
switch (contentEncoding.ToLower()) switch (contentEncoding.ToLower())
{ {
...@@ -55,8 +55,8 @@ namespace Titanium.Web.Proxy ...@@ -55,8 +55,8 @@ namespace Titanium.Web.Proxy
break; break;
} }
WriteResponseStatus(args.ProxySession.ResponseProtocolVersion, args.ProxySession.ResponseStatusCode, WriteResponseStatus(args.ProxySession.Response.ResponseProtocolVersion, args.ProxySession.Response.ResponseStatusCode,
args.ProxySession.ResponseStatusDescription, args.ClientStreamWriter); args.ProxySession.Response.ResponseStatusDescription, args.ClientStreamWriter);
WriteResponseHeaders(args.ClientStreamWriter, args.ResponseHeaders, args.ResponseBody.Length, WriteResponseHeaders(args.ClientStreamWriter, args.ResponseHeaders, args.ResponseBody.Length,
isChunked); isChunked);
WriteResponseBody(args.ClientStream, args.ResponseBody, isChunked); WriteResponseBody(args.ClientStream, args.ResponseBody, isChunked);
...@@ -65,10 +65,10 @@ namespace Titanium.Web.Proxy ...@@ -65,10 +65,10 @@ namespace Titanium.Web.Proxy
{ {
// var isChunked = args.ProxySession.ResponseHeaders.Any(x => x.Name.ToLower() == "transfer-encoding" && x.Value.ToLower().Contains("chunked")); // var isChunked = args.ProxySession.ResponseHeaders.Any(x => x.Name.ToLower() == "transfer-encoding" && x.Value.ToLower().Contains("chunked"));
WriteResponseStatus(args.ProxySession.ResponseProtocolVersion, args.ProxySession.ResponseStatusCode, WriteResponseStatus(args.ProxySession.Response.ResponseProtocolVersion, args.ProxySession.Response.ResponseStatusCode,
args.ProxySession.ResponseStatusDescription, args.ClientStreamWriter); args.ProxySession.Response.ResponseStatusDescription, args.ClientStreamWriter);
WriteResponseHeaders(args.ClientStreamWriter, args.ResponseHeaders); WriteResponseHeaders(args.ClientStreamWriter, args.ResponseHeaders);
WriteResponseBody(args.ResponseStream, args.ClientStream, false); WriteResponseBody(args.ResponseStream, args.ClientStream, false, args.ProxySession.Response.ContentLength);
} }
args.ClientStream.Flush(); args.ClientStream.Flush();
...@@ -84,24 +84,24 @@ namespace Titanium.Web.Proxy ...@@ -84,24 +84,24 @@ namespace Titanium.Web.Proxy
} }
} }
private static List<HttpHeader> ReadResponseHeaders(HttpWebClient response) private static List<HttpHeader> ReadResponseHeaders(HttpWebSession response)
{ {
for (var i = 0; i < response.ResponseHeaders.Count; i++) for (var i = 0; i < response.Response.ResponseHeaders.Count; i++)
{ {
switch (response.ResponseHeaders[i].Name.ToLower()) switch (response.Response.ResponseHeaders[i].Name.ToLower())
{ {
case "content-encoding": case "content-encoding":
response.ResponseContentEncoding = response.ResponseHeaders[i].Value; response.Response.ResponseContentEncoding = response.Response.ResponseHeaders[i].Value;
break; break;
case "content-type": case "content-type":
if (response.ResponseHeaders[i].Value.Contains(";")) if (response.Response.ResponseHeaders[i].Value.Contains(";"))
{ {
response.ResponseContentType = response.ResponseHeaders[i].Value.Split(';')[0].Trim(); response.Response.ResponseContentType = response.Response.ResponseHeaders[i].Value.Split(';')[0].Trim();
response.ResponseCharacterSet = response.ResponseHeaders[i].Value.Split(';')[1].Replace("charset=", string.Empty).Trim(); response.Response.ResponseCharacterSet = response.Response.ResponseHeaders[i].Value.Split(';')[1].Replace("charset=", string.Empty).Trim();
} }
else else
response.ResponseContentType = response.ResponseHeaders[i].Value.Trim(); response.Response.ResponseContentType = response.Response.ResponseHeaders[i].Value.Trim();
break; break;
...@@ -113,8 +113,8 @@ namespace Titanium.Web.Proxy ...@@ -113,8 +113,8 @@ namespace Titanium.Web.Proxy
} }
} }
// response.ResponseHeaders.RemoveAll(x => x.Name.ToLower() == "connection"); // response.ResponseHeaders.RemoveAll(x => x.Name.ToLower() == "connection");
return response.ResponseHeaders; return response.Response.ResponseHeaders;
} }
private static void WriteResponseStatus(Version version, string code, string description, private static void WriteResponseStatus(Version version, string code, string description,
...@@ -190,7 +190,7 @@ namespace Titanium.Web.Proxy ...@@ -190,7 +190,7 @@ namespace Titanium.Web.Proxy
WriteResponseBodyChunked(data, clientStream); WriteResponseBodyChunked(data, clientStream);
} }
private static void WriteResponseBody(Stream inStream, Stream outStream, bool isChunked) private static void WriteResponseBody(Stream inStream, Stream outStream, bool isChunked, int BodyLength)
{ {
if (!isChunked) if (!isChunked)
{ {
......
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