예제 #1
0
 public void ClearTest()
 {
     ReceiveBuffer target = new ReceiveBuffer(); // TODO: 初始化为适当的值
     target.Write(new byte[] { 1, 2 }, 0, 2);
     target.Clear();
     Assert.IsTrue(target.Length == 0);
 }
예제 #2
0
 public void ClearTest1()
 {
     ReceiveBuffer target = new ReceiveBuffer(); // TODO: 初始化为适当的值
     target.Add(new byte[] { 1, 2 }, 0, 2);
     int count = 1; // TODO: 初始化为适当的值
     target.Clear(count);
     Assert.IsTrue(target.Length == 1 && target[0] == 2);
 }
예제 #3
0
        /// <summary>
        /// 解析连接请求信息
        /// </summary>
        /// <param name="buffer">接收到的原始数量</param>
        /// <returns></returns>
        public static HttpRequest From(ReceiveBuffer buffer)
        {
            buffer.Position = 0;
            var bytes = buffer.ReadArray();

            var request = HttpRequest.From(bytes, "http");
            if (request == null)
            {
                return null;
            }

            if (string.Equals(request.Method, "POST", StringComparison.OrdinalIgnoreCase))
            {
                var contentLength = int.Parse(request["Content-Length"]);
                if (request.Body.Length < contentLength)
                {
                    return null;
                }
            }

            buffer.Clear();
            return request;
        }