Mercurial Hosting > luan
changeset 1033:4ada7a8c128a
remove HttpParser._buffers
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 03 Nov 2016 04:00:25 -0600 |
parents | eca26899c4bc |
children | 563458c4dc93 |
files | src/org/eclipse/jetty/http/HttpParser.java src/org/eclipse/jetty/server/AbstractHttpConnection.java src/org/eclipse/jetty/server/AsyncHttpConnection.java src/org/eclipse/jetty/server/BlockingHttpConnection.java |
diffstat | 4 files changed, 24 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/http/HttpParser.java Thu Nov 03 03:19:50 2016 -0600 +++ b/src/org/eclipse/jetty/http/HttpParser.java Thu Nov 03 04:00:25 2016 -0600 @@ -60,31 +60,31 @@ private static final int STATE_SEEKING_EOF=7; private final EventHandler _handler; - private final Buffers _buffers; // source of buffers private final EndPoint _endp; - private Buffer _header; // Buffer for header data (and small _content) - private Buffer _body; // Buffer for large content + public final Buffer _header; // Buffer for header data (and small _content) + private final Buffer _body; // Buffer for large content private Buffer _buffer; // The current buffer in use (either _header or _content) private String _cached; - private String _tok0; // Saved token: header name, request method or response version - private String _tok1; // Saved token: header value, request URI or response code + private String _tok0 = ""; // Saved token: header name, request method or response version + private String _tok1 = ""; // Saved token: header value, request URI or response code private String _multiLineValue; private int _responseStatus; // If >0 then we are parsing a response private boolean _persistent; - protected final View _contentView = new View(); // View of the content in the buffer for {@link Input} - protected int _state = STATE_START; - protected byte _eol; - protected int _length; - protected long _contentLength; - protected long _contentPosition; - protected int _chunkLength; - protected int _chunkPosition; + private final View _contentView = new View(); // View of the content in the buffer for {@link Input} + private int _state = STATE_START; + private byte _eol; + private int _length; + private long _contentLength; + private long _contentPosition; + private int _chunkLength; + private int _chunkPosition; private boolean _headResponse; - public HttpParser(Buffers buffers, EndPoint endp, EventHandler handler) + public HttpParser(Buffer headerBuffer,Buffer bodyBuffer, EndPoint endp, EventHandler handler) { - _buffers = buffers; + _header = headerBuffer; + _body = bodyBuffer; _endp = endp; _handler = handler; } @@ -171,7 +171,7 @@ return 0; if (_buffer==null) - _buffer = getHeaderBuffer(); + _buffer = _header; if (_state == STATE_CONTENT && _contentPosition == _contentLength) @@ -289,10 +289,7 @@ case STATE_FIELD0: if (ch == HttpTokens.SPACE) { -//System.out.println("qqqqqqqqqqqqqqqq a "+_tok0); -// _tok0.update(_buffer.markIndex(), _buffer.getIndex() - 1); _tok0 = _buffer.toString(_buffer.markIndex(), _buffer.getIndex() - 1 - _buffer.markIndex()); -//System.out.println("qqqqqqqqqqqqqqqq b "+_tok0); _responseStatus = !HttpVersions.CACHE.contains(_tok0)?-1:0; _state=STATE_SPACE1; continue; @@ -338,9 +335,7 @@ { _eol=ch; _state=STATE_HEADER; -// _tok0.setPutIndex(_tok0.getIndex()); _tok0 = ""; -// _tok1.setPutIndex(_tok1.getIndex()); _tok1 = ""; _multiLineValue=null; continue; @@ -382,9 +377,7 @@ { _eol=ch; _state=STATE_HEADER; -// _tok0.setPutIndex(_tok0.getIndex()); _tok0 = ""; -// _tok1.setPutIndex(_tok1.getIndex()); _tok1 = ""; _multiLineValue=null; } @@ -413,9 +406,7 @@ _eol=ch; _persistent = HttpVersions.CACHE.getOrdinal(version) >= HttpVersions.HTTP_1_1_ORDINAL; _state=STATE_HEADER; -// _tok0.setPutIndex(_tok0.getIndex()); _tok0 = ""; -// _tok1.setPutIndex(_tok1.getIndex()); _tok1 = ""; _multiLineValue=null; continue; @@ -516,9 +507,7 @@ } _handler.parsedHeader(header, value); -// _tok0.setPutIndex(_tok0.getIndex()); _tok0 = ""; -// _tok1.setPutIndex(_tok1.getIndex()); _tok1 = ""; _multiLineValue=null; } @@ -609,20 +598,14 @@ case HttpTokens.CARRIAGE_RETURN: case HttpTokens.LINE_FEED: if (_length > 0) { -//System.out.println("qqqqqqqqqqqqqqqq c "+_tok0); -// _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length); _tok0 = _buffer.toString(_buffer.markIndex(), _length); -//System.out.println("qqqqqqqqqqqqqqqq d "+_tok0); } _eol=ch; _state=STATE_HEADER; break; case HttpTokens.COLON: if (_length > 0 && _cached==null) { -//System.out.println("qqqqqqqqqqqqqqqq e "+_tok0); -// _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length); _tok0 = _buffer.toString(_buffer.markIndex(), _length); -//System.out.println("qqqqqqqqqqqqqqqq f "+_tok0); } _length=-1; _state=STATE_HEADER_VALUE; @@ -648,20 +631,14 @@ case HttpTokens.CARRIAGE_RETURN: case HttpTokens.LINE_FEED: if (_length > 0) { -//System.out.println("qqqqqqqqqqqqqqqq g "+_tok0); -// _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length); _tok0 = _buffer.toString(_buffer.markIndex(),_length); -//System.out.println("qqqqqqqqqqqqqqqq h "+_tok0); } _eol=ch; _state=STATE_HEADER; break; case HttpTokens.COLON: if (_length > 0 && _cached==null) { -//System.out.println("qqqqqqqqqqqqqqqq i "+_tok0); -// _tok0.update(_buffer.markIndex(), _buffer.markIndex() + _length); _tok0 = _buffer.toString(_buffer.markIndex(),_length); -//System.out.println("qqqqqqqqqqqqqqqq j "+_tok0); } _length=-1; _state=STATE_HEADER_VALUE; @@ -950,21 +927,19 @@ { // Do we have a buffer? if (_buffer==null) - _buffer=getHeaderBuffer(); + _buffer = _header; // Is there unconsumed content in body buffer - if (_state>STATE_END && _buffer==_header && _header!=null && !_header.hasContent() && _body!=null && _body.hasContent()) + if (_state>STATE_END && _buffer==_header && !_header.hasContent() && _body.hasContent()) { - _buffer=_body; + _buffer = _body; return _buffer.length(); } // Shall we switch to a body buffer? - if (_buffer==_header && _state>STATE_END && _header.length()==0 && ((_contentLength-_contentPosition)>_header.capacity()) && (_body!=null||_buffers!=null)) + if (_buffer==_header && _state>STATE_END && _header.length()==0 && ((_contentLength-_contentPosition)>_header.capacity())) { - if (_body==null) - _body=_buffers.getBuffer(); - _buffer=_body; + _buffer = _body; } // Shall we compact the body? @@ -995,23 +970,6 @@ return _endp.fill(_buffer); } - public void returnBuffers() - { - if (_body!=null && !_body.hasContent() && _body.markIndex()==-1 && _buffers!=null) - { - if (_buffer==_body) - _buffer=_header; - _body=null; - } - - if (_header!=null && !_header.hasContent() && _header.markIndex()==-1 && _buffers!=null) - { - if (_buffer==_header) - _buffer=null; - _header=null; - } - } - @Override public String toString() { @@ -1022,21 +980,6 @@ _contentLength); } - public Buffer getHeaderBuffer() - { - if (_header == null) - { - _header = _buffers.getHeader(); -//System.out.println("qqqqqqqqqqqqqqqq k "+_tok0); -// _tok0.update(_header); - _tok0 = ""; -//System.out.println("qqqqqqqqqqqqqqqq l "+_tok0); -// _tok1.update(_header); - _tok1 = ""; - } - return _header; - } - public Buffer blockForContent(long maxIdleTime) throws IOException { if (_contentView.length()>0)
--- a/src/org/eclipse/jetty/server/AbstractHttpConnection.java Thu Nov 03 03:19:50 2016 -0600 +++ b/src/org/eclipse/jetty/server/AbstractHttpConnection.java Thu Nov 03 04:00:25 2016 -0600 @@ -125,7 +125,8 @@ } void initParser() { - _parser = new HttpParser(_connector.getRequestBuffers(), _endp, new RequestHandler()); + Buffers buffers = _connector.getRequestBuffers(); + _parser = new HttpParser(buffers.getHeader(), buffers.getBuffer(), _endp, new RequestHandler()); } private void init() { @@ -167,7 +168,7 @@ if (_expect100Continue) { // is content missing? - if (_parser.getHeaderBuffer()==null || _parser.getHeaderBuffer().length()<2) + if (_parser._header.length()<2) { if (_generator.isCommitted()) throw new IllegalStateException("Committed before 100 Continues");
--- a/src/org/eclipse/jetty/server/AsyncHttpConnection.java Thu Nov 03 03:19:50 2016 -0600 +++ b/src/org/eclipse/jetty/server/AsyncHttpConnection.java Thu Nov 03 04:00:25 2016 -0600 @@ -130,7 +130,6 @@ finally { // return buffers - _parser.returnBuffers(); _generator.returnBuffers(); // Safety net to catch spinning