throw new ClosedChannelException();
}
// stream ended but HTTP header isn't complete?
else if ( !HttpHeaderParser.isComplete( headerBuf ) )
{
throw new ParseException( "Received HTTP Header missing finalizing line terminators (\\r\\n\\r\\n)!",
readControl );
}
if ( logger.isLoggable( Level.FINEST ) )
{
logger.log( Level.FINEST, "HTTP Header read: complete=" + HttpHeaderParser.isComplete( headerBuf )
+ ", readControl=" + readControl + ", bytes read: " + headerBuf.position() );
}
headerBuf.flip();
if ( logger.isLoggable( Level.FINE ) )
{
logger.log( Level.FINE, IOUtil.decodeToString( headerBuf ) );
headerBuf.position( 0 );
}
// instantiate an appropiate HTTP header parser depending on whether the data are a HTTP request or a response
if ( isRequest )
{
httpHeaderParser = new HttpResponseParser( headerBuf );
}
else
{
httpHeaderParser = new HttpRequestParser( headerBuf );
}
// validate the data
if ( !httpHeaderParser.isValid() )
{
headerBuf.rewind();
throw new ParseException( httpHeaderParser.getClass().getName() + ": Invalid HTTP header detected!!!\n"
+ IOUtil.decodeToString( headerBuf ), 0 );
}
return httpHeaderParser;
}