示例#1
0
        internal void Send(HttpConnection connection, string protocol, string version)
        {
            ServerContext = connection.Server;

            byte[] data = null;
            if (Code < 200 || Code == 204 || Code == 304)
            {
                Headers.Remove("Content-Type");
                Headers["Content-Length"] = "0";
            }
            else
            {
                data = GetData();
                Headers["Content-Length"] = (data != null) ? data.Length.ToString() : "0";
            }

            if (Code >= 500)
                Headers["Connection"] = "close";

            var hdrBuffer = new StringBuilder();
            hdrBuffer.AppendFormat("{0}/{1} {2} {3}\r\n", protocol, version, Code, Reason);
            foreach (string hdr in Headers)
                foreach (var value in Headers.GetValues(hdr))
                    hdrBuffer.AppendFormat("{0}: {1}\r\n", hdr, value);

            hdrBuffer.Append("\r\n");

            connection.Send(Encoding.ASCII, hdrBuffer.ToString());
            connection.Send(data);
        }
        public HttpRequestHeader(HttpConnection connection, Socket socket)
        {
            if (connection == null)
                throw new ArgumentNullException("connection");
            if (socket == null)
                throw new ArgumentNullException("socket");

            this.connection = connection;
            this.socket = socket;
            this.buffer = new StringBuilder(1024);
            this.portion = new byte[1024];
        }
示例#3
0
 internal void Send(HttpConnection connection)
 {
     Send(connection, Protocol, Version);
 }