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

            var requestLine = SazHttpRequestLine.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 SazHttpRequest(requestLine, headers, parser.Body, SazHttpHeaders.Parse(parser.Trailers)));
            }
            return(new SazHttpRequest(requestLine, headers, body, SazHttpHeaders.Parse("")));
        }