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

毕业论文移动版

毕业论文 > 计算机论文 >

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


        public static byte[] GetHeader(int lenght, MimeType type, bool dropConnection, bool gzip)
        {
            string cutOffConnection = "";
            if (dropConnection)
            {
                cutOffConnection = "\r\n" + "Connection: close";
            }
            string _type = GetStringMimeType(type);

            string header = "HTTP/1.1 200 OK" +
             "\r\n" + "Cache-Control: private" +
             "\r\n" + "Server: my" +
             "\r\n" + "Content-Type: " + _type +
             "\r\n" + "Content-Length: " + lenght +
             (gzip ? "\r\n" + "Content-Encoding: gzip" : "") +
             "\r\n" + "Server: vws" +
             "\r\n" + "Date: " + String.Format("{0:r}", DateTime.Now) +
             "\r\n\r\n";
            return Encoding.UTF8.GetBytes(header);
        }

        /// <summary>
        /// 这个函数返回一个字节数组GZIP算法压缩。
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static byte[] CompressGZIP(byte[] data)
        {
            System.IO.MemoryStream streamoutput = new System.IO.MemoryStream();
            System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(streamoutput, System.IO.Compression.CompressionMode.Compress, false);
            gzip.Write(data, 0, data.Length);
            gzip.Close();
            return streamoutput.ToArray();
        }

        /// <summary>
        /// 这个函数返回默认的错误页面,应用程序响应。
        /// </summary>
        /// <param name="request"></param>
        /// <param name="ex"></param>
        /// <returns></returns> (责任编辑:qin)