Example #1
0
        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
            {
            }
        }
Example #2
0
        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
            {
            }
        }
Example #3
0
        public override ValidationResults <DownloadStateOccurance> ValidateData(ProcessedDataPackage package)
        {
            ValidationResults <DownloadStateOccurance> results = new ValidationResults <DownloadStateOccurance>();

            results.Score = -1;

            DownloadData data = package.GetData <DownloadData>();

            ResponseBodyDumpFilesInfo rbdfi = new ResponseBodyDumpFilesInfo(package);

            if (data == null ||
                data.Count == 0)
            {
                return(results);
            }

            results.Score = 100;

            String          bodyBuffer = null;
            StreamReader    sr         = null;
            MatchCollection m          = null;

            int count = 0;

            Stream stream = null;


            foreach (DownloadState ds in data)
            {
                if (ds.URLType != URLType.CSS)
                {
                    continue;
                }

                try
                {
                    stream = rbdfi.Open(FileAccess.Read, ds.FileGUID);

                    if (stream != null)
                    {
                        sr = new StreamReader(stream);

                        if (sr != null)
                        {
                            bodyBuffer = sr.ReadToEnd();
                            sr.Close();
                            sr.Dispose();

                            m = regex.Matches(bodyBuffer);

                            if (m.Count > 0)
                            {
                                count += m.Count;
                                results.Add(new DownloadStateOccurance(ds));
                            }
                        }
                    }
                }
                catch
                {
                }
            }

            results.ResultsExplenation = String.Format(message, count);

            int c = 0;

            for (int xx = 0; xx < grades.Length; xx++)
            {
                if (grades[xx] < count)
                {
                    c++;
                }
                else
                {
                    break;
                }
            }
            results.Score -= c * 10;

            return(results);
        }