Example #1
0
    /// <summary>
    /// 检查客户端的 ETag 是否已经过期,若未过期则产生一个 HTTP 304 响应
    /// </summary>
    /// <param name="context">HTTP 上下文</param>
    /// <param name="etag">用于与客户端 ETag 比较的,生成的请求内容的 ETag</param>
    /// <param name="response">需要发出的 304 响应信息</param>
    /// <returns>ETag 是否未过期</returns>
    public static bool IsNotModified( HttpContextBase context, string etag, out RawResponse response )
    {
      if ( context == null )
        throw new ArgumentNullException( "context" );

      if ( etag == null )
        throw new ArgumentNullException( "etag" );


      var request = context.Request;
      var requestETag = request.Headers["If-None-Match"];


      if ( string.Equals( requestETag, etag ) )
      {
        response = NotModified();
        return true;

      }

      else
      {
        response = null;
        return false;
      }

    }
Example #2
0
        /// <summary>
        /// 检查客户端的 ETag 是否已经过期,若未过期则产生一个 HTTP 304 响应
        /// </summary>
        /// <param name="context">HTTP 上下文</param>
        /// <param name="etag">用于与客户端 ETag 比较的,生成的请求内容的 ETag</param>
        /// <param name="response">需要发出的 304 响应信息</param>
        /// <returns>ETag 是否未过期</returns>
        public static bool IsNotModified(HttpContextBase context, string etag, out RawResponse response)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (etag == null)
            {
                throw new ArgumentNullException("etag");
            }


            var request     = context.Request;
            var requestETag = request.Headers["If-None-Match"];


            if (string.Equals(requestETag, etag))
            {
                response = NotModified();
                return(true);
            }

            else
            {
                response = null;
                return(false);
            }
        }
Example #3
0
    /// <summary>
    /// 更新缓存
    /// </summary>
    /// <param name="content">渲染结果</param>
    protected virtual ICachedResponse UpdateCache( string content )
    {
      var response = new RawResponse();

      response.Content = content;
      response.Headers.Add( "ContentType", "text/html" );

      return response;
    }
Example #4
0
    private ICachedResponse CreateCachedResponse( ContentResult content )
    {
      var response = new RawResponse()
      {
        Content = content.Content,
        ContentEncoding = content.ContentEncoding,
      };

      response.Headers.Add( "ContentType", content.ContentType );

      return response;
    }