@Test public void testInvalidHeaderParsing() throws Exception { final CharArrayBuffer buffer = new CharArrayBuffer(16); buffer.clear(); buffer.append(""); try { this.parser.parseHeader(buffer); Assert.fail("ParseException should have been thrown"); } catch (final ParseException e) { } buffer.clear(); buffer.append("blah"); try { this.parser.parseHeader(buffer); Assert.fail("ParseException should have been thrown"); } catch (final ParseException e) { } buffer.clear(); buffer.append(":"); try { this.parser.parseHeader(buffer); Assert.fail("ParseException should have been thrown"); } catch (final ParseException e) { } buffer.clear(); buffer.append(" :"); try { this.parser.parseHeader(buffer); Assert.fail("ParseException should have been thrown"); } catch (final ParseException e) { } buffer.clear(); buffer.append(": blah"); try { this.parser.parseHeader(buffer); Assert.fail("ParseException should have been thrown"); } catch (final ParseException e) { } buffer.clear(); buffer.append(" : blah"); try { this.parser.parseHeader(buffer); Assert.fail("ParseException should have been thrown"); } catch (final ParseException e) { } buffer.clear(); buffer.append("header : blah"); try { this.parser.parseHeader(buffer); Assert.fail("ParseException should have been thrown"); } catch (final ParseException e) { } }
@Override public Header parseHeader(final CharArrayBuffer buffer) throws ParseException { Args.notNull(buffer, "Char array buffer"); final ParserCursor cursor = new ParserCursor(0, buffer.length()); this.tokenizer.skipWhiteSpace(buffer, cursor); final String name = this.tokenizer.parseToken(buffer, cursor, COLON); if (cursor.getPos() == cursor.getLowerBound() || cursor.getPos() == cursor.getUpperBound() || buffer.charAt(cursor.getPos()) != ':' || TextUtils.isEmpty(name) || Tokenizer.isWhitespace(buffer.charAt(cursor.getPos() - 1))) { throw new ParseException("Invalid header", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } final String value = buffer.substringTrimmed(cursor.getPos() + 1, cursor.getUpperBound()); return new BasicHeader(name, value); }
BasicLineParser implements LineParser { @Override public Header parseHeader(final CharArrayBuffer buffer) throws ParseException { Args.notNull(buffer, "Char array buffer"); final ParserCursor cursor = new ParserCursor(0, buffer.length()); this.tokenizer.skipWhiteSpace(buffer, cursor); final String name = this.tokenizer.parseToken(buffer, cursor, COLON); if (cursor.getPos() == cursor.getLowerBound() || cursor.getPos() == cursor.getUpperBound() || buffer.charAt(cursor.getPos()) != ':' || TextUtils.isEmpty(name) || Tokenizer.isWhitespace(buffer.charAt(cursor.getPos() - 1))) { throw new ParseException("Invalid header", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } final String value = buffer.substringTrimmed(cursor.getPos() + 1, cursor.getUpperBound()); return new BasicHeader(name, value); } }
BasicLineParser implements LineParser { @Override public Header parseHeader(final CharArrayBuffer buffer) throws ParseException { Args.notNull(buffer, "Char array buffer"); final ParserCursor cursor = new ParserCursor(0, buffer.length()); this.tokenizer.skipWhiteSpace(buffer, cursor); final String name = this.tokenizer.parseToken(buffer, cursor, COLON); if (cursor.getPos() == cursor.getLowerBound() || cursor.getPos() == cursor.getUpperBound() || buffer.charAt(cursor.getPos()) != ':' || TextUtils.isEmpty(name) || Tokenizer.isWhitespace(buffer.charAt(cursor.getPos() - 1))) { throw new ParseException("Invalid header", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } final String value = buffer.substringTrimmed(cursor.getPos() + 1, cursor.getUpperBound()); return new BasicHeader(name, value); } BasicLineParser(final ProtocolVersion proto);  BasicLineParser(); }
BasicLineParser implements LineParser { @Override public Header parseHeader(final CharArrayBuffer buffer) throws ParseException { Args.notNull(buffer, "Char array buffer"); final ParserCursor cursor = new ParserCursor(0, buffer.length()); this.tokenizer.skipWhiteSpace(buffer, cursor); final String name = this.tokenizer.parseToken(buffer, cursor, COLON); if (cursor.getPos() == cursor.getLowerBound() || cursor.getPos() == cursor.getUpperBound() || buffer.charAt(cursor.getPos()) != ':' || TextUtils.isEmpty(name) || Tokenizer.isWhitespace(buffer.charAt(cursor.getPos() - 1))) { throw new ParseException("Invalid header", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } final String value = buffer.substringTrimmed(cursor.getPos() + 1, cursor.getUpperBound()); return new BasicHeader(name, value); } BasicLineParser(final ProtocolVersion proto);  BasicLineParser(); @Override RequestLine parseRequestLine(final CharArrayBuffer buffer); @Override StatusLine parseStatusLine(final CharArrayBuffer buffer); @Override Header parseHeader(final CharArrayBuffer buffer); }
BasicLineParser implements LineParser { @Override public Header parseHeader(final CharArrayBuffer buffer) throws ParseException { Args.notNull(buffer, "Char array buffer"); final ParserCursor cursor = new ParserCursor(0, buffer.length()); this.tokenizer.skipWhiteSpace(buffer, cursor); final String name = this.tokenizer.parseToken(buffer, cursor, COLON); if (cursor.getPos() == cursor.getLowerBound() || cursor.getPos() == cursor.getUpperBound() || buffer.charAt(cursor.getPos()) != ':' || TextUtils.isEmpty(name) || Tokenizer.isWhitespace(buffer.charAt(cursor.getPos() - 1))) { throw new ParseException("Invalid header", buffer, cursor.getLowerBound(), cursor.getUpperBound(), cursor.getPos()); } final String value = buffer.substringTrimmed(cursor.getPos() + 1, cursor.getUpperBound()); return new BasicHeader(name, value); } BasicLineParser(final ProtocolVersion proto);  BasicLineParser(); @Override RequestLine parseRequestLine(final CharArrayBuffer buffer); @Override StatusLine parseStatusLine(final CharArrayBuffer buffer); @Override Header parseHeader(final CharArrayBuffer buffer); final static BasicLineParser INSTANCE; }