public async Task TestRequestParser_SimpleGet() { var sb = new StringBuilder(); sb.AppendLine("GET /test.html HTTP/1.1"); sb.AppendLine("Host: testdomain.local"); sb.AppendLine(); using (var output = test.SetStream(sb.ToString())) { await new HttpRequestParser().ProgressTask(test.Task).ConfigureAwait(false); Assert.AreEqual(HttpProtocolMethod.Get, test.Request.ProtocolMethod); Assert.AreEqual("/test.html", test.Request.Location.DocumentPath); Assert.AreEqual(HttpProtocolDefinition.HttpVersion1_1, test.Request.HttpProtocol); Assert.AreEqual("testdomain.local", test.GetRequestHeader("Host")); } }
public async Task TestSending() { test.Response.HttpProtocol = HttpProtocolDefinition.HttpVersion1_1; test.Response.StatusCode = HttpStateCode.OK; test.Response.FieldContentType = MimeType.TextPlain; test.Request.Cookie.AddedCookies.Add("test", new HttpCookie.Cookie("test", "value")); test.Task.Document.DataSources.Add( new HttpStringDataSource("foobarbaz\r\n")); using (var response = test.SetStream()) using (var r = new StreamReader(response)) { await new HttpSender().ProgressTask(test.Task).ConfigureAwait(false); response.Position = 0; Assert.AreEqual("HTTP/1.1 200 OK", r.ReadLine()); Assert.AreEqual("Content-Type: text/plain", r.ReadLine()); Assert.AreEqual("Set-Cookie: test=value;Path=", r.ReadLine()); Assert.AreEqual("", r.ReadLine()); Assert.AreEqual("foobarbaz", r.ReadLine()); } }