HTTP response header event arguments
Inheritance: HttpHeaderEventArgs
        public void PersistentConnectionTestHttp11()
        {
            List<KeyValuePair<string, string>> headerList = new List<KeyValuePair<string, string>>();
            headerList.Add(new KeyValuePair<string, string>("Age", "0"));
            HttpHeaders headers = new HttpHeaders(headerList);

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

            Assert.That(args.IsPersistent, Is.True, "Default is true with HTTP 1.1");
            Assert.That(args.HasBody, Is.False);
        }
        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));
        }
Exemplo n.º 3
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 );
            }
        }
Exemplo n.º 4
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());
            }
        }
Exemplo n.º 5
0
        private void HandleServerParserReadResponseHeaderComplete( object sender, HttpResponseHeaderEventArgs e )
        {
            Contract.Requires( e != null );

            ServiceLog.Logger.Verbose( "{0} SessionContext::HandleServerParserReadResponseHeaderComplete", Id );

            try
            {
                RecentResponseHeader = HttpResponse.CreateResponse( e );
                State.ResponseHeaderAvailable( RecentResponseHeader, this );
            }
            catch ( Exception ex )
            {
                ServiceLog.Logger.Exception(
                    string.Format( "{0} Unhandled exception when handling response header", Id ), ex );
                Reset();
            }
        }
Exemplo n.º 6
0
 public static HttpResponse CreateResponse( HttpResponseHeaderEventArgs args )
 {
     Contract.Requires(args != null);
     return new HttpResponse(args);
 }
Exemplo n.º 7
0
 public HttpResponse( HttpResponseHeaderEventArgs args )
 {
     Contract.Requires(args!=null);
     _args = args;
 }