final protected char next ( final ByteBuffer buffer , boolean allow8859 ) throws BaseExceptions . BadMessage { if ( ! buffer . hasRemaining ( ) ) return HttpTokens . EMPTY_BUFF ; if ( _segmentByteLimit <= _segmentBytePosition ) { shutdownParser ( ) ; throw new BaseExceptions . BadMessage ( "Request length limit exceeded: " + _segmentByteLimit ) ; } final byte b = buffer . get ( ) ; _segmentBytePosition ++ ; // If we ended on a CR, make sure we are if ( _cr ) { if ( b != HttpTokens . LF ) { throw new BadCharacter ( "Invalid sequence: LF didn't follow CR: " + b ) ; } _cr = false ; return ( char ) b ; // must be LF } // Make sure its a valid character if ( b < HttpTokens . SPACE ) { if ( b == HttpTokens . CR ) { // Set the flag to check for _cr and just run again _cr = true ; return next ( buffer , allow8859 ) ; } else if ( b == HttpTokens . TAB || allow8859 && b < 0 ) { return ( char ) ( b & 0xff ) ; } else if ( b == HttpTokens . LF ) { return ( char ) b ; // A backend should accept a bare linefeed. http://tools.ietf.org/html/rfc2616#section-19.3 } else if ( isLenient ( ) ) { return HttpTokens . REPLACEMENT ; } else { shutdownParser ( ) ; throw new BadCharacter ( "Invalid char: '" + ( char ) ( b & 0xff ) + "', 0x" + Integer . toHexString ( b ) ) ; } } // valid ascii char return ( char ) b ; }
Removes CRs but returns LFs