public void GetBufferTest()
        {
            List<KeyValuePair<string, string>> headerList = new List<KeyValuePair<string, string>>();
            headerList.Add(new KeyValuePair<string, string>("Content-Length", "10"));
            headerList.Add(new KeyValuePair<string, string>("Age", "0"));
            HttpHeaders headers = new HttpHeaders(headerList);

            var objectUnderTest = new HttpResponseHeaderEventArgs("1.1", headers, 200, "OK");

            byte[] headerBytes = objectUnderTest.GetBuffer();

            string expectedHeader = "HTTP/1.1 200 OK\r\nContent-Length: 10\r\nAge: 0\r\n\r\n";
            var expectedBytes = Encoding.UTF8.GetBytes(expectedHeader);

            Assert.That(headerBytes, Is.EqualTo(expectedBytes));
        }
Esempio n. 2
0
        private void _dispatcher_ReadResponseHeaderComplete( object sender, HttpResponseHeaderEventArgs e )
        {
            ServiceLog.Logger.Verbose(
                () =>
                string.Format( "{0} ClientSession -- read HTTP response header complete\r\n{1}",
                               Id,
                               Encoding.UTF8.GetString( HttpResponse.CreateResponse( e ).GetBuffer() ) ) );

            if ( _clientConnection != null )
            {
                //_sendingDataToClientLock.Reset();
                _clientConnection.BeginSend( e.GetBuffer(), HandleSendToClient );
            }
        }
Esempio n. 3
0
        private void ParserReadResponseHeaderComplete( object sender, HttpResponseHeaderEventArgs e )
        {
            _lastResponse = HttpResponse.CreateResponse( e );

            // Always unsubscribe. This could be left over from the last request.
            _parser.PartialDataAvailable -= ParserPartialDataAvailable;
            _parser.BodyAvailable -= ParserBodyAvailable;

            if ( _responseFilter != null )
            {

                byte[] filterResponse = _responseFilter.ApplyResponseHeaderFilters( _lastResponse, out _callbacks );

                if ( _callbacks != null )
                {
                    // Get the full body before sending the response
                    _parser.BodyAvailable += ParserBodyAvailable;
                }

                else if ( filterResponse == null )
                {
                    // Send the received header, unmodified, and re-subscribe to publish raw data coming from the server
                    _parser.PartialDataAvailable += ParserPartialDataAvailable;
                    OnDataAvailable( e.GetBuffer() );
                }

                else
                {
                    // Send the modified response since we have enough information to know to filter the response.
                    OnDataAvailable( filterResponse );
                    Close();
                }
            }

            else
            {
                // Send the received header, unmodified, and re-subscribe to publish raw data coming from the server
                _parser.PartialDataAvailable += ParserPartialDataAvailable;
                OnDataAvailable(e.GetBuffer());
            }
        }