コード例 #1
0
ファイル: requestHandler.cs プロジェクト: Letractively/topeka
 /// <summary>
 /// Creates a requestHandler object and starts the thread for handling the request
 /// </summary>
 /// <param name="client">The TCPClient connected</param>
 /// <param name="server">The Server Object</param>
 internal requestHandler(TcpClient client, Server server)
 {
     this.server = server;
     this.client = client;
     try{
         if (this.server.isSSL())
         {
             SSLServer sslServer = (SSLServer) this.server;
             SslStream sslStream = new SslStream(client.GetStream(), false);
             sslStream.AuthenticateAsServer(sslServer.getCertificate(), false, SslProtocols.Tls, true);
             sslStream.ReadTimeout = 15000;
             sslStream.WriteTimeout = 15000;
             this.stream = sslStream;
         }
         else this.stream = client.GetStream();
         ThreadPool.QueueUserWorkItem(startHandling);
     }
     catch (Exception e)
     {
         this.server.handleVerbosity(e);
     }
 }
コード例 #2
0
ファイル: Request.cs プロジェクト: Letractively/topeka
        /// <summary>
        /// Construct a Request object that contains the information received from the client
        /// </summary>
        /// <param name="stream">The stream associated to the TCPClient</param>
        /// <param name="server">The server that handled the request</param>
        internal Request(Stream stream, Server server)
        {
            this.server = server;
            this.m_ClientIP = "";

            // Receive max 16k from the client
            Byte[] receiveBuffer = new Byte[16384];
            int i = stream.Read(receiveBuffer, 0 , receiveBuffer.Length);

            // Convert the data received to UTF8
            this.sBuffer = Encoding.UTF8.GetString(receiveBuffer);

            this.m_Cookies = new ArrayList();
            this.m_Ranges = new ArrayList();
            this.parameters = new Hashtable();

            Tokenizer toki = new Tokenizer(sBuffer, "\r\n");
            Tokenizer fullRequest = new Tokenizer(toki.nextToken(), " ");
            m_Method = fullRequest.nextToken();
            m_Path = fullRequest.nextToken();
            Tokenizer path = new Tokenizer(m_Path.Substring(1), "?");
            Page = path.nextToken();
            parseParameters(path.nextToken());

            m_HTTPVersion = fullRequest.nextToken();

            while (toki.hasMoreTokens())
            {
                string temp = toki.nextToken();
                if (temp != null)
                {
                    if (temp.IndexOf("Accept:") == 0) m_Accept = substract(temp);
                    else if (temp.IndexOf("Accept-Language:") == 0) m_AcceptLanguage = substract(temp);
                    else if (temp.IndexOf("Accept-Encoding:") == 0) m_AcceptEncoding = substract(temp);
                    else if (temp.IndexOf("User-Agent:") == 0) m_UserAgent = substract(temp);
                    else if (temp.IndexOf("Host:") == 0) m_Host = substract(temp);
                    else if (temp.IndexOf("Connection:") == 0) m_Connection = substract(temp);
                    else if (temp.IndexOf("Authorization:") == 0) m_Authorization = substract(temp);
                    else if (temp.IndexOf("Cookie:") == 0)
                    {
                        string cookiesTemp = substract(temp);
                        Tokenizer cookiesToki = new Tokenizer(cookiesTemp, "; ");
                        while (cookiesToki.hasMoreTokens())
                        {
                            string cookieTemp = cookiesToki.nextToken();
                            Tokenizer inCookie = new Tokenizer(cookieTemp, "=");
                            this.m_Cookies.Add(new Cookie(inCookie.nextToken(), inCookie.nextToken()));
                        }
                    }
                    else if (temp.IndexOf("Range:") == 0)
                    {
                        string rangesTemp = substract(temp);
                        Tokenizer rangeValues = new Tokenizer(rangesTemp, "=");
                        string rangeType = rangeValues.nextToken();
                        Tokenizer differentRanges = new Tokenizer(rangeValues.nextToken(), ",");
                        while (differentRanges.hasMoreTokens())
                        {

                            string range = differentRanges.nextToken();
                            this.m_Ranges.Add(new Range(range));
                        }
                    }
                    else if (temp == "")
                    {
                        if (Method == "POST")
                        {
                            parseParameters(toki.nextToken());
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: Servlet.cs プロジェクト: Letractively/topeka
 internal static ResourceAssembly findResourceStream(Server server, string resource)
 {
     ResourceAssembly toReturn = null;
     foreach (ResourceAssembly resource_assembly in server.resources)
     {
         if (resource_assembly.assembly.GetManifestResourceStream(resource_assembly.assembly_namespace + "." + resource) != null) return resource_assembly;
     }
     return toReturn;
 }