MakeResponseHeaders() private method

private MakeResponseHeaders ( int statusCode, String moreHeaders, int contentLength, bool keepAlive ) : System
statusCode int
moreHeaders String
contentLength int
keepAlive bool
return System
示例#1
0
        internal void WriteHeaders(int statusCode, string extraHeaders)
        {
            string s = Connection.MakeResponseHeaders(statusCode, extraHeaders, -1, false);

            try
            {
                this._socket.Send(Encoding.UTF8.GetBytes(s));
            }
            catch (SocketException)
            {
            }
        }
示例#2
0
        internal void WriteEntireResponseFromFile(string fileName, bool keepAlive)
        {
            if (!File.Exists(fileName))
            {
                this.WriteErrorAndClose(404);
                return;
            }
            string text = Connection.MakeContentTypeHeader(fileName);

            if (text == null)
            {
                this.WriteErrorAndClose(403);
                return;
            }
            bool       flag       = false;
            FileStream fileStream = null;

            try
            {
                fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                int    num    = (int)fileStream.Length;
                byte[] buffer = new byte[num];
                int    num2   = fileStream.Read(buffer, 0, num);
                string s      = Connection.MakeResponseHeaders(200, text, num2, keepAlive);
                this._socket.Send(Encoding.UTF8.GetBytes(s));
                this._socket.Send(buffer, 0, num2, SocketFlags.None);
                flag = true;
            }
            catch (SocketException)
            {
            }
            finally
            {
                if (!keepAlive || !flag)
                {
                    this.Close();
                }
                if (fileStream != null)
                {
                    fileStream.Close();
                }
            }
        }
示例#3
0
 internal void WriteEntireResponseFromString(int statusCode, string extraHeaders, string body, bool keepAlive)
 {
     try
     {
         int    contentLength = (body != null) ? Encoding.UTF8.GetByteCount(body) : 0;
         string str           = Connection.MakeResponseHeaders(statusCode, extraHeaders, contentLength, keepAlive);
         this._socket.Send(Encoding.UTF8.GetBytes(str + body));
     }
     catch (SocketException)
     {
     }
     finally
     {
         if (!keepAlive)
         {
             this.Close();
         }
     }
 }