TryReadLine() static private méthode

static private TryReadLine ( byte buffer, int &start, int end, int &lineStart, int &lineEnd ) : bool
buffer byte
start int
end int
lineStart int
lineEnd int
Résultat bool
Exemple #1
0
        public void TestParseHeader()
        {
            var request = new MemoryStream(8192);
            var buffer  = request.GetBuffer();
            var start   = 0;

            request.WriteAscii("Host : localhost:8080\r\n");
            Assert.IsTrue(RequestParser.TryReadLine(buffer, ref start, (int)request.Length, out int lineStart, out int lineEnd));
            RequestParser.ParseHeader(buffer, lineStart, lineEnd, out string name, out string value);
            Assert.AreEqual("Host", name);
            Assert.AreEqual("localhost:8080", value);
        }
Exemple #2
0
        public void TestParseRequestLine2()
        {
            var request = new MemoryStream(8192);
            var buffer  = request.GetBuffer();
            var start   = 0;

            request.WriteAscii("POST /accounts? HTTP/1.1\r\n");
            Assert.IsTrue(RequestParser.TryReadLine(buffer, ref start, (int)request.Length, out int lineStart, out int lineEnd));
            RequestParser.ParseRequestLine(buffer, lineStart, lineEnd, out Method method, out string path, out string query, out string version);
            Assert.AreEqual(Method.POST, method);
            Assert.AreEqual("/accounts", path);
            Assert.AreEqual("?", query);
            Assert.AreEqual("HTTP/1.1", version);
        }
Exemple #3
0
        public void TestMixedNewLines()
        {
            var request = new MemoryStream(8192);
            var buffer  = request.GetBuffer();
            var start   = 0;

            request.WriteAscii("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0\n");
            request.WriteAscii("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\n");
            request.WriteAscii("Accept-language: en-US;q=0.7,en;q=0.3\n");
            request.WriteAscii("Connection: close\r\n");

            Assert.IsTrue(RequestParser.TryReadLine(buffer, ref start, (int)request.Length, out int lineStart, out int lineEnd));
            var line = Encoding.ASCII.GetString(buffer, lineStart, lineEnd);

            Assert.AreEqual("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0", line);
        }
Exemple #4
0
        public void TestTryReadLine()
        {
            var request = new MemoryStream(8192);
            var buffer  = request.GetBuffer();
            var start   = 0;

            Assert.IsFalse(RequestParser.TryReadLine(buffer, ref start, (int)request.Length, out int lineStart, out int lineEnd));

            request.WriteAscii("\r\n");
            Assert.IsTrue(RequestParser.TryReadLine(buffer, ref start, (int)request.Length, out lineStart, out lineEnd));

            request.WriteAscii("GET /");
            Assert.IsFalse(RequestParser.TryReadLine(buffer, ref start, (int)request.Length, out lineStart, out lineEnd));

            request.WriteAscii(" HTTP/1.1\r\nUser-Agent: ");
            Assert.IsTrue(RequestParser.TryReadLine(buffer, ref start, (int)request.Length, out lineStart, out lineEnd));

            Assert.AreEqual(Encoding.ASCII.GetString(buffer, lineStart, lineEnd - lineStart), "GET / HTTP/1.1");
        }