Ejemplo n.º 1
0
        /// <summary>
        /// 生成http回复头
        /// </summary>
        /// <param name="status">状态</param>
        /// <param name="statusDescription">说明</param>
        public static HttpHeaderBuilder Resonse(int status, string statusDescription)
        {
            var header = new HttpHeaderBuilder();

            header.builder.AppendFormat("HTTP/1.1 {0} {1}", status, statusDescription).Append(CRLF);
            return(header);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 生成头部数据
        /// </summary>
        /// <param name="contentLength">内容长度</param>
        /// <param name="gzip">gzip模式</param>
        /// <returns></returns>
        private byte[] GenerateResponseHeader(int contentLength, bool gzip)
        {
            var header = HttpHeaderBuilder.Resonse(this.Status, this.StatusDescription);

            if (this.Charset == null)
            {
                header.Add("Content-Type", this.ContentType);
            }
            else
            {
                var contenType = string.Format("{0}; charset={1}", this.ContentType, this.Charset.WebName);
                header.Add("Content-Type", contenType);
            }

            if (contentLength >= 0)
            {
                header.Add("Content-Length", contentLength);
            }

            if (gzip == true)
            {
                header.Add("Content-Encoding", "gzip");
            }

            header.Add("Date", DateTime.Now.ToUniversalTime().ToString("r"));
            header.Add("Server", "NetworkSocket");

            foreach (var key in this.Headers.AllKeys)
            {
                header.Add(key, this.Headers[key]);
            }
            return(header.ToByteArray());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 生成http请求头
        /// </summary>
        /// <param name="method">请求方法</param>
        /// <param name="path">路径</param>
        public static HttpHeaderBuilder Request(HttpMethod method, string path)
        {
            var header = new HttpHeaderBuilder();

            header.builder.AppendFormat("{0} {1} HTTP/1.1", method, path).Append(CRLF);
            return(header);
        }