public void SendFragmentedHttpMessage() { var client = new Client.Client(); var notifyHandler = new NotifyReceivedMessageHandler(); notifyHandler.ReceivedMessage += (o, m) => { this.receivedMessage = m.MessageBytes; }; client.SetServerAddress("127.0.0.1") .SetPort(800) .AddHandler(notifyHandler) .WithSsl(false) .Connect(); var request = new HttpRequest(); request.Method = HttpMessage.HttpMethods.Post; request.BodyString = "Brought a message to you my guy!"; request.RequestURI = "/echo"; request.Headers[HttpMessage.EntityHeaders.ContentLength] = request.BodyString.Length.ToString(); var message = request.GetPackedRequest(); client.QueueMessage(message.Take(message.Length - request.BodyString.Length).ToArray()); Thread.Sleep(1000); client.QueueMessage(message.Skip(message.Length - request.BodyString.Length).Take(10).ToArray()); Thread.Sleep(1000); client.QueueMessage(message.Skip(message.Length - request.BodyString.Length + 10).Take(request.BodyString.Length - 10).ToArray()); var sw = new Stopwatch(); sw.Start(); while (this.receivedMessage == null) { if (sw.ElapsedMilliseconds > 15000) { throw new Exception("Response not received!"); } } var response = HttpResponse.FromBytes(this.receivedMessage); //Trim the null bytes from encryption/decryption response.BodyString = response.BodyString.Trim('\0'); Assert.AreEqual(response.StatusCode, HttpMessage.StatusCodes.OK); Assert.AreEqual(response.BodyString, "Brought a message to you my guy!"); }
public void SendFragmentedHttpMessageExceedingSizeShouldExpire() { var client = new Client.Client(); var notifyHandler = new NotifyReceivedMessageHandler(); notifyHandler.ReceivedMessage += (o, m) => { this.receivedMessage = m.MessageBytes; }; client.SetServerAddress("127.0.0.1") .SetPort(800) .AddHandler(notifyHandler) .WithSsl(false) .Connect(); var request = new HttpRequest(); request.Method = HttpMessage.HttpMethods.Post; request.BodyString = "Brought a message to you my guy!"; request.RequestURI = "/echo"; request.Headers[HttpMessage.EntityHeaders.ContentLength] = request.BodyString.Length.ToString(); request.Body = new byte[255000]; Array.Fill <byte>(request.Body, 50); var message = request.GetPackedRequest(); client.QueueMessage(message.Take(message.Length - request.BodyString.Length).ToArray()); Thread.Sleep(5); client.QueueMessage(message.Skip(message.Length - request.BodyString.Length).Take(10).ToArray()); Thread.Sleep(5); client.QueueMessage(message.Skip(message.Length - request.BodyString.Length + 10).Take(request.BodyString.Length - 10).ToArray()); var sw = new Stopwatch(); sw.Start(); while (this.receivedMessage == null) { if (sw.ElapsedMilliseconds > 15000) { Assert.Fail("Should receive that message has exceeded size!"); } } var response = HttpResponse.FromBytes(this.receivedMessage); Assert.AreNotEqual(response.StatusCode, HttpMessage.StatusCodes.OK); }