Example #1
0
        public void TestCase()
        {
            string requestLine = "GET ";

            for (int i = 0; i < 2048; i++)
            {
                requestLine += "a";
            }

            requestLine += "HTTP/1.1\r\n\r\n";

            byte[] byteArray = Encoding.UTF8.GetBytes(requestLine);
            //byte[] byteArray = Encoding.ASCII.GetBytes(contents);
            MemoryStream    stream   = new MemoryStream(byteArray);
            ValidateRequest validate = new ValidateRequest();

            Assert.IsFalse(validate.IsValid(stream));

            requestLine = "GET URL HTTP/1.1\r\n";               // this is valid

            for (int i = 0; i < 100 * 1024; i++)
            {
                requestLine += "a:";                 //adding a lot of giberish for the 'headers'
            }

            byteArray = Encoding.UTF8.GetBytes(requestLine);
            stream    = new MemoryStream(byteArray);
            validate  = new ValidateRequest();
            Assert.IsFalse(validate.IsValid(stream));



            WebServer server = new WebServer();

            WebServer.Start(4422, 0);
            WebService service = new DemoService();

            server.AddService(service);

            while (true)
            {
            }


            WebServer.Stop();
        }
Example #2
0
        private WebRequest BuildRequest(TcpClient client)
        {
            NetworkStream stream = client.GetStream();

            if (validate.IsValid(stream))
            {
                // This is the start of the body that we have already read into our buff.
                Stream memoryStream = new MemoryStream(validate.Buf, validate.Index, validate.BytesInBuf - validate.Index);

                // since the network stream cannot seek, we can just give it the stream and all
                // reads will start from where we left off. (the part of
                string value;
                if (validate.Headers.TryGetValue("content-length", out value))
                {
                    int contentLength;

                    if (!int.TryParse(value, out contentLength))
                    {
                        // we have the header, but it is not a valid int
                        throw new ArgumentOutOfRangeException("Invalid Content-Length header value");
                    }

                    // Here, we have the header, and a valid int, pass it to the concateStream
                    ConcatStream catStream = new ConcatStream(memoryStream, stream, contentLength);
                    return(new WebRequest(stream, catStream, validate.HttpVersion, validate.URI, validate.Method));
                }
                else
                {
                    // Here, we did not find the header, do not give it a length.
                    ConcatStream catStream = new ConcatStream(memoryStream, stream);
                    return(new WebRequest(stream, catStream, validate.HttpVersion, validate.URI, validate.Method));
                }



                //isValidHTTP = true;
                //string formatedString = string.Format (responseTemplate, "11398813", DateTime.Now, _uri);
                //stream.Write (Encoding.ASCII.GetBytes (formatedString), 0, formatedString.Length);
            }


            //listener.Stop ();

            return(null);
        }