@Test void testUriHost10() { ByteBuffer buffer = BufferUtils.toBuffer( "GET http: + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); parser.parseNext(buffer); assertNull(bad); assertEquals("http: assertEquals(0, port); }
public boolean parseNext(ByteBuffer buffer) { if (DEBUG) LOG.debug("parseNext s={} {}", state, BufferUtils.toDetailString(buffer)); try { if (state == State.START) { version = null; method = null; methodString = null; endOfContent = EndOfContent.UNKNOWN_CONTENT; header = null; if (quickStart(buffer)) return true; } if (state.ordinal() >= State.START.ordinal() && state.ordinal() < State.HEADER.ordinal()) { if (parseLine(buffer)) return true; } if (state == State.HEADER) { if (parseFields(buffer)) return true; } if (state.ordinal() >= State.CONTENT.ordinal() && state.ordinal() < State.TRAILER.ordinal()) { if (responseStatus > 0 && headResponse) { setState(State.END); return handleContentMessage(); } else { if (parseContent(buffer)) return true; } } if (state == State.TRAILER) { if (parseFields(buffer)) return true; } if (state == State.END) { while (buffer.remaining() > 0 && buffer.get(buffer.position()) <= HttpTokens.SPACE) buffer.get(); } else if (isClose() || isClosed()) { BufferUtils.clear(buffer); } if (eof && !buffer.hasRemaining()) { switch (state) { case CLOSED: break; case START: setState(State.CLOSED); handler.earlyEOF(); break; case END: case CLOSE: setState(State.CLOSED); break; case EOF_CONTENT: case TRAILER: if (fieldState == FieldState.FIELD) { setState(State.CLOSED); return handleContentMessage(); } setState(State.CLOSED); handler.earlyEOF(); break; case CONTENT: case CHUNKED_CONTENT: case CHUNK_SIZE: case CHUNK_PARAMS: case CHUNK: setState(State.CLOSED); handler.earlyEOF(); break; default: if (DEBUG) LOG.debug("{} EOF in {}", this, state); setState(State.CLOSED); handler.badMessage(new BadMessageException(HttpStatus.BAD_REQUEST_400)); break; } } } catch (BadMessageException x) { BufferUtils.clear(buffer); badMessage(x); } catch (Throwable x) { BufferUtils.clear(buffer); badMessage(new BadMessageException(HttpStatus.BAD_REQUEST_400, requestHandler != null ? "Bad Request" : "Bad Response", x)); } return false; }
HttpParser { public boolean parseNext(ByteBuffer buffer) { if (DEBUG) LOG.debug("parseNext s={} {}", state, BufferUtils.toDetailString(buffer)); try { if (state == State.START) { version = null; method = null; methodString = null; endOfContent = EndOfContent.UNKNOWN_CONTENT; header = null; if (quickStart(buffer)) return true; } if (state.ordinal() >= State.START.ordinal() && state.ordinal() < State.HEADER.ordinal()) { if (parseLine(buffer)) return true; } if (state == State.HEADER) { if (parseFields(buffer)) return true; } if (state.ordinal() >= State.CONTENT.ordinal() && state.ordinal() < State.TRAILER.ordinal()) { if (responseStatus > 0 && headResponse) { setState(State.END); return handleContentMessage(); } else { if (parseContent(buffer)) return true; } } if (state == State.TRAILER) { if (parseFields(buffer)) return true; } if (state == State.END) { while (buffer.remaining() > 0 && buffer.get(buffer.position()) <= HttpTokens.SPACE) buffer.get(); } else if (isClose() || isClosed()) { BufferUtils.clear(buffer); } if (eof && !buffer.hasRemaining()) { switch (state) { case CLOSED: break; case START: setState(State.CLOSED); handler.earlyEOF(); break; case END: case CLOSE: setState(State.CLOSED); break; case EOF_CONTENT: case TRAILER: if (fieldState == FieldState.FIELD) { setState(State.CLOSED); return handleContentMessage(); } setState(State.CLOSED); handler.earlyEOF(); break; case CONTENT: case CHUNKED_CONTENT: case CHUNK_SIZE: case CHUNK_PARAMS: case CHUNK: setState(State.CLOSED); handler.earlyEOF(); break; default: if (DEBUG) LOG.debug("{} EOF in {}", this, state); setState(State.CLOSED); handler.badMessage(new BadMessageException(HttpStatus.BAD_REQUEST_400)); break; } } } catch (BadMessageException x) { BufferUtils.clear(buffer); badMessage(x); } catch (Throwable x) { BufferUtils.clear(buffer); badMessage(new BadMessageException(HttpStatus.BAD_REQUEST_400, requestHandler != null ? "Bad Request" : "Bad Response", x)); } return false; } }
HttpParser { public boolean parseNext(ByteBuffer buffer) { if (DEBUG) LOG.debug("parseNext s={} {}", state, BufferUtils.toDetailString(buffer)); try { if (state == State.START) { version = null; method = null; methodString = null; endOfContent = EndOfContent.UNKNOWN_CONTENT; header = null; if (quickStart(buffer)) return true; } if (state.ordinal() >= State.START.ordinal() && state.ordinal() < State.HEADER.ordinal()) { if (parseLine(buffer)) return true; } if (state == State.HEADER) { if (parseFields(buffer)) return true; } if (state.ordinal() >= State.CONTENT.ordinal() && state.ordinal() < State.TRAILER.ordinal()) { if (responseStatus > 0 && headResponse) { setState(State.END); return handleContentMessage(); } else { if (parseContent(buffer)) return true; } } if (state == State.TRAILER) { if (parseFields(buffer)) return true; } if (state == State.END) { while (buffer.remaining() > 0 && buffer.get(buffer.position()) <= HttpTokens.SPACE) buffer.get(); } else if (isClose() || isClosed()) { BufferUtils.clear(buffer); } if (eof && !buffer.hasRemaining()) { switch (state) { case CLOSED: break; case START: setState(State.CLOSED); handler.earlyEOF(); break; case END: case CLOSE: setState(State.CLOSED); break; case EOF_CONTENT: case TRAILER: if (fieldState == FieldState.FIELD) { setState(State.CLOSED); return handleContentMessage(); } setState(State.CLOSED); handler.earlyEOF(); break; case CONTENT: case CHUNKED_CONTENT: case CHUNK_SIZE: case CHUNK_PARAMS: case CHUNK: setState(State.CLOSED); handler.earlyEOF(); break; default: if (DEBUG) LOG.debug("{} EOF in {}", this, state); setState(State.CLOSED); handler.badMessage(new BadMessageException(HttpStatus.BAD_REQUEST_400)); break; } } } catch (BadMessageException x) { BufferUtils.clear(buffer); badMessage(x); } catch (Throwable x) { BufferUtils.clear(buffer); badMessage(new BadMessageException(HttpStatus.BAD_REQUEST_400, requestHandler != null ? "Bad Request" : "Bad Response", x)); } return false; } HttpParser(RequestHandler handler);  HttpParser(ResponseHandler handler);  HttpParser(RequestHandler handler, int maxHeaderBytes);  HttpParser(ResponseHandler handler, int maxHeaderBytes); @Deprecated  HttpParser(RequestHandler handler, int maxHeaderBytes, boolean strict); @Deprecated  HttpParser(ResponseHandler handler, int maxHeaderBytes, boolean strict);  HttpParser(RequestHandler handler, HttpCompliance compliance);  HttpParser(RequestHandler handler, int maxHeaderBytes, HttpCompliance compliance);  HttpParser(ResponseHandler handler, int maxHeaderBytes, HttpCompliance compliance); private  HttpParser(RequestHandler requestHandler, ResponseHandler responseHandler, int maxHeaderBytes, HttpCompliance compliance); }
HttpParser { public boolean parseNext(ByteBuffer buffer) { if (DEBUG) LOG.debug("parseNext s={} {}", state, BufferUtils.toDetailString(buffer)); try { if (state == State.START) { version = null; method = null; methodString = null; endOfContent = EndOfContent.UNKNOWN_CONTENT; header = null; if (quickStart(buffer)) return true; } if (state.ordinal() >= State.START.ordinal() && state.ordinal() < State.HEADER.ordinal()) { if (parseLine(buffer)) return true; } if (state == State.HEADER) { if (parseFields(buffer)) return true; } if (state.ordinal() >= State.CONTENT.ordinal() && state.ordinal() < State.TRAILER.ordinal()) { if (responseStatus > 0 && headResponse) { setState(State.END); return handleContentMessage(); } else { if (parseContent(buffer)) return true; } } if (state == State.TRAILER) { if (parseFields(buffer)) return true; } if (state == State.END) { while (buffer.remaining() > 0 && buffer.get(buffer.position()) <= HttpTokens.SPACE) buffer.get(); } else if (isClose() || isClosed()) { BufferUtils.clear(buffer); } if (eof && !buffer.hasRemaining()) { switch (state) { case CLOSED: break; case START: setState(State.CLOSED); handler.earlyEOF(); break; case END: case CLOSE: setState(State.CLOSED); break; case EOF_CONTENT: case TRAILER: if (fieldState == FieldState.FIELD) { setState(State.CLOSED); return handleContentMessage(); } setState(State.CLOSED); handler.earlyEOF(); break; case CONTENT: case CHUNKED_CONTENT: case CHUNK_SIZE: case CHUNK_PARAMS: case CHUNK: setState(State.CLOSED); handler.earlyEOF(); break; default: if (DEBUG) LOG.debug("{} EOF in {}", this, state); setState(State.CLOSED); handler.badMessage(new BadMessageException(HttpStatus.BAD_REQUEST_400)); break; } } } catch (BadMessageException x) { BufferUtils.clear(buffer); badMessage(x); } catch (Throwable x) { BufferUtils.clear(buffer); badMessage(new BadMessageException(HttpStatus.BAD_REQUEST_400, requestHandler != null ? "Bad Request" : "Bad Response", x)); } return false; } HttpParser(RequestHandler handler);  HttpParser(ResponseHandler handler);  HttpParser(RequestHandler handler, int maxHeaderBytes);  HttpParser(ResponseHandler handler, int maxHeaderBytes); @Deprecated  HttpParser(RequestHandler handler, int maxHeaderBytes, boolean strict); @Deprecated  HttpParser(ResponseHandler handler, int maxHeaderBytes, boolean strict);  HttpParser(RequestHandler handler, HttpCompliance compliance);  HttpParser(RequestHandler handler, int maxHeaderBytes, HttpCompliance compliance);  HttpParser(ResponseHandler handler, int maxHeaderBytes, HttpCompliance compliance); private  HttpParser(RequestHandler requestHandler, ResponseHandler responseHandler, int maxHeaderBytes, HttpCompliance compliance); HttpHandler getHandler(); long getContentLength(); long getContentRead(); void setHeadResponse(boolean head); State getState(); boolean inContentState(); boolean inHeaderState(); boolean isChunking(); boolean isStart(); boolean isClose(); boolean isClosed(); boolean isIdle(); boolean isComplete(); boolean isState(State state); boolean parseNext(ByteBuffer buffer); boolean isAtEOF(); void atEOF(); void close(); void reset(); Trie<HttpField> getFieldCache(); @Override String toString(); }
HttpParser { public boolean parseNext(ByteBuffer buffer) { if (DEBUG) LOG.debug("parseNext s={} {}", state, BufferUtils.toDetailString(buffer)); try { if (state == State.START) { version = null; method = null; methodString = null; endOfContent = EndOfContent.UNKNOWN_CONTENT; header = null; if (quickStart(buffer)) return true; } if (state.ordinal() >= State.START.ordinal() && state.ordinal() < State.HEADER.ordinal()) { if (parseLine(buffer)) return true; } if (state == State.HEADER) { if (parseFields(buffer)) return true; } if (state.ordinal() >= State.CONTENT.ordinal() && state.ordinal() < State.TRAILER.ordinal()) { if (responseStatus > 0 && headResponse) { setState(State.END); return handleContentMessage(); } else { if (parseContent(buffer)) return true; } } if (state == State.TRAILER) { if (parseFields(buffer)) return true; } if (state == State.END) { while (buffer.remaining() > 0 && buffer.get(buffer.position()) <= HttpTokens.SPACE) buffer.get(); } else if (isClose() || isClosed()) { BufferUtils.clear(buffer); } if (eof && !buffer.hasRemaining()) { switch (state) { case CLOSED: break; case START: setState(State.CLOSED); handler.earlyEOF(); break; case END: case CLOSE: setState(State.CLOSED); break; case EOF_CONTENT: case TRAILER: if (fieldState == FieldState.FIELD) { setState(State.CLOSED); return handleContentMessage(); } setState(State.CLOSED); handler.earlyEOF(); break; case CONTENT: case CHUNKED_CONTENT: case CHUNK_SIZE: case CHUNK_PARAMS: case CHUNK: setState(State.CLOSED); handler.earlyEOF(); break; default: if (DEBUG) LOG.debug("{} EOF in {}", this, state); setState(State.CLOSED); handler.badMessage(new BadMessageException(HttpStatus.BAD_REQUEST_400)); break; } } } catch (BadMessageException x) { BufferUtils.clear(buffer); badMessage(x); } catch (Throwable x) { BufferUtils.clear(buffer); badMessage(new BadMessageException(HttpStatus.BAD_REQUEST_400, requestHandler != null ? "Bad Request" : "Bad Response", x)); } return false; } HttpParser(RequestHandler handler);  HttpParser(ResponseHandler handler);  HttpParser(RequestHandler handler, int maxHeaderBytes);  HttpParser(ResponseHandler handler, int maxHeaderBytes); @Deprecated  HttpParser(RequestHandler handler, int maxHeaderBytes, boolean strict); @Deprecated  HttpParser(ResponseHandler handler, int maxHeaderBytes, boolean strict);  HttpParser(RequestHandler handler, HttpCompliance compliance);  HttpParser(RequestHandler handler, int maxHeaderBytes, HttpCompliance compliance);  HttpParser(ResponseHandler handler, int maxHeaderBytes, HttpCompliance compliance); private  HttpParser(RequestHandler requestHandler, ResponseHandler responseHandler, int maxHeaderBytes, HttpCompliance compliance); HttpHandler getHandler(); long getContentLength(); long getContentRead(); void setHeadResponse(boolean head); State getState(); boolean inContentState(); boolean inHeaderState(); boolean isChunking(); boolean isStart(); boolean isClose(); boolean isClosed(); boolean isIdle(); boolean isComplete(); boolean isState(State state); boolean parseNext(ByteBuffer buffer); boolean isAtEOF(); void atEOF(); void close(); void reset(); Trie<HttpField> getFieldCache(); @Override String toString(); static final LazyLogger LOG; @Deprecated
    final static String STRICT; final static int INITIAL_URI_LENGTH; final static Trie<HttpField> CACHE; }