HTTP服务器软件系统的设计与实现(18)_毕业论文

毕业论文移动版

毕业论文 > 计算机论文 >

HTTP服务器软件系统的设计与实现(18)


        }

        /// <summary>
        /// 返回true,如果资源是动态资源组的一部分
        /// </summary>
        /// <param name="resource">resource name</param>
        /// <returns></returns>
        public static bool IsDynamicResource(string resource)
        {
            return Regex.IsMatch(resource, @"(.*?)\.(htm|html|xhtml|dhtml)$");
        }

        /// <summary>
        ///返回HTTP 404字节格式pageHeader。
        /// </summary>
        /// <param name="response_data_length"></param>
        /// <param name="response_data"></param>
        /// <returns></returns>
        public static byte[] GetHtml404Header(int response_data_length, MimeType type, string response_data = null)
        {
            return Encoding.UTF8.GetBytes(
                "HTTP/1.1 404 Not Found" +
                "\r\n" + "Date: " + String.Format("{0:r}", DateTime.Now) +
                "\r\n" + "Server: my" +
                (response_data != null ?
                "\r\n" + "Content-Length: " + response_data_length +
                "\r\n" + "Location: " + response_data +
                "\r\n" + "Content-Location: " + response_data
                : string.Empty) +
                "\r\n" + "Content-Type: " + GetStringMimeType(type) +
                "\r\n\r\n");
        }

        /// <summary>
        /// 返回一个很小的的HTTP响应pageHeader字节格式。       
        /// </summary>
        /// <param name="lenght"></param>
        /// <param name="type"></param>
        /// <param name="dropConnection"></param>
        /// <param name="gzip"></param>
        /// <returns></returns> (责任编辑:qin)