Exemple #1
0
        /// <summary>
        /// 响应上下文中接收100Continue请求消息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnContext100Continue(object sender, ContinueEventArgs e)
        {
            // 100状态码的目的在于允许客户端判定服务器是否愿意接受客户端发来的消息主体(基于请求头域)在客户端发送此请求消息主体前。
            var response = new Response(e.Request.HttpVersion, HttpStatusCode.Continue, "Please continue.");

            // 如果服务器认为客户端准备发送的消息体长度超过限制范围,则回复417状态码拒绝接收
            if (ContentLengthLimit != 0 && e.Request.ContentLength.Value > ContentLengthLimit)
            {
                Logger.Warning("Requested to send " + e.Request.ContentLength.Value + " bytes, but we only allow " + ContentLengthLimit);
                response.Status = HttpStatusCode.ExpectationFailed;
                response.Reason = "Too large content length";
            }

            string responseString = string.Format("{0} {1} {2}\r\n\r\n",
                                                  e.Request.HttpVersion, (int)response.Status, response.Reason);

            byte[] buffer = e.Request.Encoding.GetBytes(responseString);
            HttpContext.Current.Stream.Write(buffer, 0, buffer.Length);
            HttpContext.Current.Stream.Flush();
            Logger.Info(responseString);
        }
Exemple #2
0
 /// <summary>
 /// 消息解析器解析出一个100Continue消息
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void On100Continue(object sender, ContinueEventArgs e)
 {
     ContinueResponseRequested(this, e);
 }
Exemple #3
0
    /// <summary>
    /// 响应上下文中接收100Continue请求消息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void OnContext100Continue(object sender, ContinueEventArgs e)
    {
      // 100状态码的目的在于允许客户端判定服务器是否愿意接受客户端发来的消息主体(基于请求头域)在客户端发送此请求消息主体前。
      var response = new Response(e.Request.HttpVersion, HttpStatusCode.Continue, "Please continue.");

      // 如果服务器认为客户端准备发送的消息体长度超过限制范围,则回复417状态码拒绝接收
      if (ContentLengthLimit != 0 && e.Request.ContentLength.Value > ContentLengthLimit)
      {
        Logger.Warning("Requested to send " + e.Request.ContentLength.Value + " bytes, but we only allow " + ContentLengthLimit);
        response.Status = HttpStatusCode.ExpectationFailed;
        response.Reason = "Too large content length";
      }

      string responseString = string.Format("{0} {1} {2}\r\n\r\n",
        e.Request.HttpVersion, (int)response.Status, response.Reason);
      byte[] buffer = e.Request.Encoding.GetBytes(responseString);
      HttpContext.Current.Stream.Write(buffer, 0, buffer.Length);
      HttpContext.Current.Stream.Flush();
      Logger.Info(responseString);
    }
Exemple #4
0
 /// <summary>
 /// 消息解析器解析出一个100Continue消息
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void On100Continue(object sender, ContinueEventArgs e)
 {
   ContinueResponseRequested(this, e);
 }