Exemple #1
0
 private SazHttpResponse(SazHttpStatusLine statusLine, SazHttpHeaders headers, byte[] body, SazHttpHeaders trailers)
 {
     this.StatusLine = statusLine;
     this.Headers    = headers;
     this.Body       = body;
     this.Trailers   = trailers;
 }
Exemple #2
0
        public static SazHttpResponse Parse(byte[] source)
        {
            var strings = Encoding.ASCII.GetString(source);
            var lines   = strings.Split(new[] { "\r\n" }, StringSplitOptions.None);

            var statusLine = SazHttpStatusLine.Parse(lines[0] + "\r\n");

            var headersSource = string.Join("\r\n", lines.Skip(1).TakeWhile(x => !string.IsNullOrEmpty(x))) + "\r\n\r\n";
            var headers       = SazHttpHeaders.Parse(headersSource);

            var bodySkipCount = strings.Split(new[] { "\r\n\r\n" }, StringSplitOptions.None).First().Length + 4;
            var body          = source.Skip(bodySkipCount).ToArray();

            if (headers.HasHeader("Transfer-Encoding") && headers.GetValues("Transfer-Encoding").Contains("chunked"))
            {
                var parser = new ChunkedBodyParser(true, int.MaxValue, false);
                foreach (var b in body)
                {
                    parser.WriteByte(b);
                }
                return(new SazHttpResponse(statusLine, headers, parser.Body, SazHttpHeaders.Parse(parser.Trailers)));
            }
            return(new SazHttpResponse(statusLine, headers, body, SazHttpHeaders.Parse("")));
        }