Example #1
0
            public TransactionContext(bool expectContinue, bool ignoreResponseBody, bool shouldKeepAlive)
            {
                RequestBody = new DataSubject(ConnectRequestBody);
                Segment     = new ResponseSegment();

                this.expectContinue     = expectContinue;
                this.ignoreResponseBody = ignoreResponseBody;
                this.shouldKeepAlive    = shouldKeepAlive;
            }
Example #2
0
        public void OnRequest(HttpRequestHead request, bool shouldKeepAlive)
        {
            var responseDelegate = responseDelegateFactory.Create(request, shouldKeepAlive, CloseConnection);

            DataSubject subject = null;
            bool        requestBodyConnected = false;

            Debug.WriteLine("[{0}] {1} {2} shouldKeepAlive = {3}",
                            DateTime.Now, request.Method, request.Uri, shouldKeepAlive);

            if (request.HasBody())
            {
                subject = new DataSubject(() =>
                {
                    if (requestBodyConnected)
                    {
                        throw new InvalidOperationException("Request body was already connected.");
                    }

                    requestBodyConnected = true;

                    if (request.IsContinueExpected())
                    {
                        responseDelegate.WriteContinue();
                    }

                    return(new Disposable(() =>
                    {
                        // XXX what to do?
                        // ideally we stop reading from the socket.
                        // equivalent to a parse error
                    }));
                });
            }

            requestBody = subject;

            if (remoteAddress != null)
            {
                if (request.Headers.ContainsKey("X-Forwarded-For"))
                {
                    request.Headers["X-Forwarded-For"] += "," + remoteAddress.ToString();
                }
                else
                {
                    request.Headers["X-Forwarded-For"] = remoteAddress.ToString();
                }
            }

            requestDelegate.OnRequest(request, subject, responseDelegate);
            observer.OnNext(responseDelegate);
        }
        public void OnRequest(HttpRequestHead request, bool shouldKeepAlive)
        {
            var responseDelegate = responseDelegateFactory.Create(request, shouldKeepAlive, CloseConnection);

            DataSubject subject = null;
            bool requestBodyConnected = false;

            Debug.WriteLine("[{0}] {1} {2} shouldKeepAlive = {3}",
                DateTime.Now, request.Method, request.Uri, shouldKeepAlive);

            if (request.HasBody())
            {
                subject = new DataSubject(() =>
                {
                    if (requestBodyConnected) 
                        throw new InvalidOperationException("Request body was already connected.");

                    requestBodyConnected = true;

                    if (request.IsContinueExpected())
                        responseDelegate.WriteContinue();

                    return new Disposable(() =>
                    {
                        // XXX what to do?
                        // ideally we stop reading from the socket. 
                        // equivalent to a parse error
                    });
                });
            }

            requestBody = subject;

            if (remoteAddress != null)
            {
                if (request.Headers.ContainsKey("X-Forwarded-For"))
                {
                    request.Headers["X-Forwarded-For"] += "," + remoteAddress.ToString();
                }
                else
                {
                    request.Headers["X-Forwarded-For"] = remoteAddress.ToString();
                }
            }

            requestDelegate.OnRequest(request, subject, responseDelegate);
            observer.OnNext(responseDelegate);
        }
            public TransactionContext(bool expectContinue, bool ignoreResponseBody, bool shouldKeepAlive)
            {
                RequestBody = new DataSubject(ConnectRequestBody);
                Segment = new ResponseSegment();

                this.expectContinue = expectContinue;
                this.ignoreResponseBody = ignoreResponseBody;
                this.shouldKeepAlive = shouldKeepAlive;
            }