Exemplo n.º 1
0
        internal static CdxWebResponse Build(CdxEntry entry, Stream warcFile)
        {
            CdxWebResponse result = new CdxWebResponse();

            warcFile.Position = entry.Offset;
            GZipStream   gz     = new GZipStream(warcFile, CompressionMode.Decompress, true);
            BinaryReader br     = new BinaryReader(gz);
            string       srLine = br.ReadAsciiLine();

            while (!srLine.Equals(""))
            {
                srLine = br.ReadAsciiLine();
                if (srLine.StartsWith(WARC_TARGET_URI))
                {
                    result.responseUri = new Uri(srLine.Substring(WARC_TARGET_URI.Length));
                }
            }


            string httpStatusCode = br.ReadAsciiLine();

            while (true)
            {
                srLine = br.ReadAsciiLine();
                if (srLine.Equals(""))
                {
                    break;
                }
                int    colonPos    = srLine.IndexOf(':');
                string headerKey   = srLine.Substring(0, colonPos);
                string headerValue = srLine.Substring(colonPos + 1);
                headerValue = headerValue.Trim();
                result.Headers.Add(headerKey, headerValue);
            }

            switch (result.TransferEncoding)
            {
            case "chunked":
                result.responseStream = unchunk(gz);
                gz.Dispose();
                break;

            case null:
                result.responseStream = gz;
                break;

            default:
                throw new NotImplementedException(result.TransferEncoding);
            }

            return(result);
        }
Exemplo n.º 2
0
        public CdxWebResponse GetResponse(CdxEntry ce)
        {
            if (currentWarcFileInfo != ce.Warc)
            {
                if (currentWarcFileStream != null)
                {
                    currentWarcFileStream.Dispose();
                }

                currentWarcFileInfo   = ce.Warc;
                currentWarcFileStream = ce.Warc.OpenRead();
                currentWarcFileName   = ce.Warc.Name;
            }

            return(CdxWebResponse.Build(ce, currentWarcFileStream));
        }