private void SaveCache(byte[] buffer, int offset, int length, bool isBody) { if (this.PipesChain.ChainState.ContainsKey(HttpTracerPipe.STATE_KEY) == false) { return; } if ((outStreamBody == null || outStreamHeader == null) && this.Configuration is EngineSuProxyConfiguration) { try { ResponseHeaderDumpFilesInfo header = new ResponseHeaderDumpFilesInfo((EngineSuProxyConfiguration)this.Configuration); ResponseBodyDumpFilesInfo body = new ResponseBodyDumpFilesInfo((EngineSuProxyConfiguration)this.Configuration); String guid = null; do { guid = Guid.NewGuid().ToString().Replace("-", "").ToLower(); } while (header.Exist(guid) || body.Exist(guid)); Stream b = body.Open(FileAccess.Write, guid); if (b != null) { outStreamBody = new BinaryWriter(b); } Stream h = header.Open(FileAccess.Write, guid); if (h != null) { outStreamHeader = new BinaryWriter(h); } HttpTransaction httpTranc = (HttpTransaction)this.PipesChain.ChainState[HttpTracerPipe.STATE_KEY]; httpTranc.FileGUID = guid; } catch { } } try { if (isBody && outStreamBody != null) { outStreamBody.Write(buffer, offset, length); } else if (outStreamHeader != null) { outStreamHeader.Write(buffer, offset, length); } } catch { } }
public Response(DownloadState ds, ProcessedDataPackage package) { ResponseHeaderDumpFilesInfo responseHeaderFileInfo = new ResponseHeaderDumpFilesInfo(package); ResponseBodyDumpFilesInfo responseBodyFileInfo = new ResponseBodyDumpFilesInfo(package); StatusText = "OK"; /*TODO - Parse Header*/ HttpVersion = "HTTP/1.1"; /*TODO - Parse Header*/ Cookies = new Cookie[0]; /*TODO - Parse Header*/ Headers = new Header[0]; /*TODO - Parse Header*/ RedirectURL = ""; /*TODO - Parse Header*/ HeadersSize = -1; BodySize = -1; Status = 200; try { FileInfo fi = new FileInfo(responseBodyFileInfo.GetFullPath(ds.FileGUID)); if (fi != null && fi.Exists) { this.BodySize = fi.Length; } MemoryStream ms = new MemoryStream(); Stream s = responseBodyFileInfo.Open(FileAccess.Read, ds.FileGUID); byte[] buffer = new byte[2000]; int len; while ((len = s.Read(buffer, 0, 2000)) > 0) { ms.Write(buffer, 0, len); } ms.Flush(); s.Close(); String cont = Convert.ToBase64String(ms.ToArray()); this.Content = new Content() { Size = this.BodySize, Text = cont, MimeType = "text/html" /*TODO - Parse Header*/ }; } catch { } }
public override ValidationResults <DownloadStateOccurance> ValidateData(ProcessedDataPackage package) { ValidationResults <DownloadStateOccurance> results = new ValidationResults <DownloadStateOccurance>(); results.Score = -1; DownloadData data = package.GetData <DownloadData>(); ResponseHeaderDumpFilesInfo rbdfi = new ResponseHeaderDumpFilesInfo(package); if (data == null || data.Count == 0) { return(results); } results.Score = 100; String headerBuffer = null; StreamReader sr = null; DateTime now = DateTime.Now.AddDays(2); Stream stream = null; foreach (DownloadState ds in data) { try { stream = rbdfi.Open(FileAccess.Read, ds.FileGUID); if (stream != null) { sr = new StreamReader(stream); if (sr != null) { headerBuffer = sr.ReadToEnd(); sr.Close(); sr.Dispose(); if (regexContentType.IsMatch(headerBuffer) == false) { continue; } if (regexContentEncoding.IsMatch(headerBuffer) == false) { results.Add(new DownloadStateOccurance(ds)); } } } } catch { } } results.Score -= Math.Min(results.Count, 4) * 10; if (results.Count > 0) { if (results.Count == 1) { results.ResultsExplenation = message_single; } else { results.ResultsExplenation = String.Format(message_more, results.Count); } } return(results); }
public override ValidationResults <DownloadStateOccurance> ValidateData(ProcessedDataPackage package) { ValidationResults <DownloadStateOccurance> results = new ValidationResults <DownloadStateOccurance>(); results.Score = -1; DownloadData data = package.GetData <DownloadData>(); ResponseHeaderDumpFilesInfo rbdfi = new ResponseHeaderDumpFilesInfo(package); if (data == null || data.Count == 0) { return(results); } results.Score = 100; String headerBuffer = null; StreamReader sr = null; Match m = null; DateTime now = DateTime.Now.AddDays(2); Stream stream = null; foreach (DownloadState ds in data) { try { stream = rbdfi.Open(FileAccess.Read, ds.FileGUID); if (stream != null) { sr = new StreamReader(stream); if (sr != null) { headerBuffer = sr.ReadToEnd(); sr.Close(); sr.Dispose(); m = regex.Match(headerBuffer); if (m.Success == false || m.Groups.Count <= 1 || String.IsNullOrEmpty(m.Groups[1].ToString())) { DownloadStateOccurance dso = new DownloadStateOccurance(ds); dso.Comment = "(no expires)"; results.Add(dso); } else { try { if (m.Groups[1].ToString() == "-1") { DownloadStateOccurance dso = new DownloadStateOccurance(ds); dso.Comment = "(-1)"; results.Add(dso); } else { DateTime dt = DateTime.Parse(m.Groups[1].ToString()); if (dt < now) { DownloadStateOccurance dso = new DownloadStateOccurance(ds); dso.Comment = String.Format("({0})", dt.Date); results.Add(dso); } } } catch { } } } } } catch { } } results.Score -= Math.Min(results.Count, 4) * 10; if (results.Count > 0) { if (results.Count == 1) { results.ResultsExplenation = message_single; } else { results.ResultsExplenation = String.Format(message_more, results.Count); } } return(results); }