예제 #1
0
        public static HttpHeaderCollection Parse(byte[] buffer, int start)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (start < 0 || start >= buffer.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(start));
            }

            var headers = new HttpHeaderCollection();

            while (true)
            {
                try
                {
                    var header = HttpHeader.Parse(buffer, start);
                    if (header == null)
                    {
                        break;
                    }

                    headers.Add(header);
                    start += header.ByteCount;
                }
                catch (Exception ex)
                {
                    throw new BadHttpDataException("Could not parse header", ex);
                }
            }

            return(headers);
        }
예제 #2
0
        public static HttpRequestMetadata Parse(byte[] buffer, int start)
        {
            // parse line
            var line = HttpRequestLine.Parse(buffer, start);

            start += line.ByteCount;

            // parse headers
            var headers = HttpHeaderCollection.Parse(buffer, start);

            var metadata = new HttpRequestMetadata(line, headers);

            return(metadata);
        }
예제 #3
0
 public HttpRequestMetadata(HttpRequestLine line, HttpHeaderCollection headers)
 {
     this.Line    = line ?? throw new ArgumentNullException(nameof(line));
     this.Headers = headers ?? throw new ArgumentNullException(nameof(headers));
 }