/// <summary>
 /// Returns a Cookies instance populated by parsing the specified string.  The string should be the value of the "Cookie" header that was received from the remote client.  If the string is null or empty, an empty cookies collection is returned.
 /// </summary>
 /// <param name="str">The value of the "Cookie" header sent by the remote client.</param>
 /// <returns></returns>
 public static Cookies FromString(string str)
 {
     Cookies cookies = new Cookies();
     if (str == null)
         return cookies;
     str = Uri.UnescapeDataString(str);
     string[] parts = str.Split(';');
     for (int i = 0; i < parts.Length; i++)
     {
         int idxEquals = parts[i].IndexOf('=');
         if (idxEquals < 1)
             continue;
         string name = parts[i].Substring(0, idxEquals).Trim();
         string value = parts[i].Substring(idxEquals + 1).Trim();
         cookies.Add(name, value);
     }
     return cookies;
 }
 /// <summary>
 /// Processes the request.
 /// </summary>
 internal void process(object objParameter)
 {
     Stream tcpStream = null;
     try
     {
         tcpStream = tcpClient.GetStream();
         if (this.secure_https)
         {
             try
             {
                 tcpStream = new System.Net.Security.SslStream(tcpStream, false, null, null);
                 ((System.Net.Security.SslStream)tcpStream).AuthenticateAsServer(ssl_certificate);
             }
             catch (Exception ex)
             {
                 SimpleHttpLogger.LogVerbose(ex);
                 return;
             }
         }
         inputStream = new BufferedStream(tcpStream);
         rawOutputStream = tcpStream;
         outputStream = new StreamWriter(rawOutputStream);
         try
         {
             parseRequest();
             readHeaders();
             RawQueryString = ParseQueryStringArguments(this.request_url.Query, preserveKeyCharacterCase: true);
             QueryString = ParseQueryStringArguments(this.request_url.Query);
             requestCookies = Cookies.FromString(GetHeaderValue("Cookie", ""));
             try
             {
                 if (http_method.Equals("GET"))
                     handleGETRequest();
                 else if (http_method.Equals("POST"))
                     handlePOSTRequest();
             }
             catch (Exception e)
             {
                 if (!isOrdinaryDisconnectException(e))
                     SimpleHttpLogger.Log(e);
                 writeFailure("500 Internal Server Error");
             }
         }
         catch (Exception e)
         {
             if (!isOrdinaryDisconnectException(e))
                 SimpleHttpLogger.LogVerbose(e);
             this.writeFailure("400 Bad Request", "The request cannot be fulfilled due to bad syntax.");
         }
         outputStream.Flush();
         rawOutputStream.Flush();
         inputStream = null; outputStream = null; rawOutputStream = null;
     }
     catch (Exception ex)
     {
         if (!isOrdinaryDisconnectException(ex))
             SimpleHttpLogger.LogVerbose(ex);
     }
     finally
     {
         try
         {
             if (tcpClient != null)
                 tcpClient.Close();
         }
         catch (Exception ex) { SimpleHttpLogger.LogVerbose(ex); }
         try
         {
             if (tcpStream != null)
                 tcpStream.Close();
         }
         catch (Exception ex) { SimpleHttpLogger.LogVerbose(ex); }
     }
 }