Send() private method

private Send ( Encoding encoding, string data ) : void
encoding System.Text.Encoding
data string
return void
示例#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);
        }
示例#2
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);
        }