public void Adds_x_forwarded_for_if_none()
        {
            var requestHead = default(HttpRequestHead);

            var txDel = new HttpServerTransactionDelegate(IPAddress.Parse("8.8.8.8"),
                new MockResponseFactory(), new MockRequestDelegate()
                {
                    OnRequestAction = (head, body, response) => {
                        requestHead = head;
                    }
                });

            txDel.Subscribe(new MockObserver<IDataProducer>());
            txDel.OnRequest(new HttpRequestHead()
            {
                Headers = new Dictionary<string, string>()
            }, false);

            Assert.That(requestHead.Headers["X-Forwarded-For"], Is.EqualTo("8.8.8.8"));
        }
        public void Append_x_forwarded_for_if_any()
        {
            var requestHead = default(HttpRequestHead);

            var txDel = new HttpServerTransactionDelegate(IPAddress.Parse("8.8.8.8"),
                new MockResponseFactory(), new MockRequestDelegate()
                {
                    OnRequestAction = (head, body, response) =>
                    {
                        requestHead = head;
                    }
                });

            txDel.Subscribe(new MockObserver<IDataProducer>());
            txDel.OnRequest(new HttpRequestHead()
            {
                Headers = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
                    { { "x-ForWarDED-FOr", "4.4.4.4" } }
            }, false);

            Assert.That(requestHead.Headers["x-Forwarded-For"], Is.EqualTo("4.4.4.4,8.8.8.8"));
        }
        public HttpServerTransactionDelegate CreateTransaction()
        {
            responseDelegate = new MockResponseDelegate();
            var tx = new HttpServerTransactionDelegate(
                new MockResponseFactory()
                {
                    OnCreate = (head, shouldKeepAlive, end) =>
                    {
                        closeConnectionAction = end;
                        ShouldKeepAlive = shouldKeepAlive;
                        return responseDelegate;
                    }
                },
                new MockRequestDelegate()
                {
                    OnRequestAction = (head, body, response) =>
                    {
                        Assert.That(response, Is.SameAs(responseDelegate));

                        requestBody = body;

                        if (callbacks.OnRequest != null)
                            callbacks.OnRequest();
                    }
                });

            messageObserver = new MockObserver<IDataProducer>();
            messageObserverDisposable = tx.Subscribe(messageObserver);

            return tx;
        }
Ejemplo n.º 4
0
 public ISocketDelegate OnConnection(IServer server, ISocket socket)
 {
     var txDel = new HttpServerTransactionDelegate(responseFactory);
     txDel.Subscribe(new OutputSegmentQueue(socket));
     return new HttpServerSocketDelegate(txDel);
 }