Mercurial Hosting > luan
changeset 1034:563458c4dc93
remove HttpGenerator.reset()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 03 Nov 2016 21:02:59 -0600 |
parents | 4ada7a8c128a |
children | 898774c2cd87 |
files | src/org/eclipse/jetty/http/AbstractGenerator.java src/org/eclipse/jetty/http/HttpGenerator.java src/org/eclipse/jetty/http/HttpParser.java src/org/eclipse/jetty/server/AbstractHttpConnection.java |
diffstat | 4 files changed, 61 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
diff -r 4ada7a8c128a -r 563458c4dc93 src/org/eclipse/jetty/http/AbstractGenerator.java --- a/src/org/eclipse/jetty/http/AbstractGenerator.java Thu Nov 03 04:00:25 2016 -0600 +++ b/src/org/eclipse/jetty/http/AbstractGenerator.java Thu Nov 03 21:02:59 2016 -0600 @@ -108,23 +108,6 @@ return _endp.isOpen(); } - public void reset() - { - _state = STATE_HEADER; - _status = 0; - _version = HttpVersions.HTTP_1_1_ORDINAL; - _reason = null; - _last = false; - _head = false; - _noContent=false; - _persistent = null; - _contentWritten = 0; - _contentLength = HttpTokens.UNKNOWN_CONTENT; - - _content = null; - _method = null; - } - public final void returnBuffers() { if (_buffer!=null && _buffer.length()==0) @@ -144,7 +127,7 @@ throw new IllegalStateException("Flushed"); _last = false; - _persistent=null; + _persistent = null; _contentWritten = 0; _contentLength = HttpTokens.UNKNOWN_CONTENT; _content=null;
diff -r 4ada7a8c128a -r 563458c4dc93 src/org/eclipse/jetty/http/HttpGenerator.java --- a/src/org/eclipse/jetty/http/HttpGenerator.java Thu Nov 03 04:00:25 2016 -0600 +++ b/src/org/eclipse/jetty/http/HttpGenerator.java Thu Nov 03 21:02:59 2016 -0600 @@ -106,9 +106,7 @@ super(buffers,io); } - @Override - public void reset() - { + public void shutdown() { if (_persistent!=null && !_persistent && _endp!=null && !_endp.isOutputShutdown()) { try @@ -120,20 +118,6 @@ LOG.trace("",e); } } - super.reset(); - if (_buffer!=null) - _buffer.clear(); - if (_header!=null) - _header.clear(); - if (_content!=null) - _content=null; - _bypass = false; - _needCRLF = false; - _needEOC = false; - _bufferChunked = false; - _method=null; - _uri=null; - _noContent=false; } /* ------------------------------------------------------------ */ @@ -330,7 +314,7 @@ { if (isRequest()) { - _persistent=true; + _persistent = true; if (_version == HttpVersions.HTTP_0_9_ORDINAL) { @@ -366,7 +350,7 @@ else { if (_persistent==null) - _persistent= (_version > HttpVersions.HTTP_1_0_ORDINAL); + _persistent = (_version > HttpVersions.HTTP_1_0_ORDINAL); // add response line Status status = _status<__status.length?__status[_status]:null; @@ -493,7 +477,7 @@ case HttpHeaderValues.CLOSE_ORDINAL: close=true; if (isResponse()) - _persistent=false; + _persistent = false; keep_alive=false; if (!_persistent && isResponse() && _contentLength == HttpTokens.UNKNOWN_CONTENT) _contentLength = HttpTokens.EOF_CONTENT;
diff -r 4ada7a8c128a -r 563458c4dc93 src/org/eclipse/jetty/http/HttpParser.java --- a/src/org/eclipse/jetty/http/HttpParser.java Thu Nov 03 04:00:25 2016 -0600 +++ b/src/org/eclipse/jetty/http/HttpParser.java Thu Nov 03 21:02:59 2016 -0600 @@ -36,28 +36,26 @@ private static final Logger LOG = LoggerFactory.getLogger(HttpParser.class); // States - private static final int STATE_START=-14; - private static final int STATE_FIELD0=-13; - private static final int STATE_SPACE1=-12; - private static final int STATE_STATUS=-11; - private static final int STATE_URI=-10; - private static final int STATE_SPACE2=-9; - private static final int STATE_END0=-8; - private static final int STATE_END1=-7; - private static final int STATE_FIELD2=-6; - private static final int STATE_HEADER=-5; - private static final int STATE_HEADER_NAME=-4; - private static final int STATE_HEADER_IN_NAME=-3; - private static final int STATE_HEADER_VALUE=-2; - private static final int STATE_HEADER_IN_VALUE=-1; - private static final int STATE_END=0; - private static final int STATE_EOF_CONTENT=1; - private static final int STATE_CONTENT=2; - private static final int STATE_CHUNKED_CONTENT=3; - private static final int STATE_CHUNK_SIZE=4; - private static final int STATE_CHUNK_PARAMS=5; - private static final int STATE_CHUNK=6; - private static final int STATE_SEEKING_EOF=7; + private static final int STATE_START = -14; + private static final int STATE_FIELD0 = -13; + private static final int STATE_SPACE1 = -12; + private static final int STATE_STATUS = -11; + private static final int STATE_URI = -10; + private static final int STATE_SPACE2 = -9; + private static final int STATE_FIELD2 = -6; + private static final int STATE_HEADER = -5; + private static final int STATE_HEADER_NAME = -4; + private static final int STATE_HEADER_IN_NAME = -3; + private static final int STATE_HEADER_VALUE = -2; + private static final int STATE_HEADER_IN_VALUE = -1; + private static final int STATE_END = 0; + private static final int STATE_EOF_CONTENT = 1; + private static final int STATE_CONTENT = 2; + private static final int STATE_CHUNKED_CONTENT = 3; + private static final int STATE_CHUNK_SIZE = 4; + private static final int STATE_CHUNK_PARAMS = 5; + private static final int STATE_CHUNK = 6; + private static final int STATE_SEEKING_EOF = 7; private final EventHandler _handler; private final EndPoint _endp; @@ -132,7 +130,7 @@ { _persistent = persistent; if (!_persistent &&(_state==STATE_END || _state==STATE_START)) - _state=STATE_SEEKING_EOF; + _state = STATE_SEEKING_EOF; } /* ------------------------------------------------------------------------------- */ @@ -203,7 +201,7 @@ progress++; else if (filled < 0 ) { - _persistent=false; + _persistent = false; // do we have content to deliver? if (_state>STATE_END) @@ -306,7 +304,7 @@ _buffer.mark(); if (_responseStatus>=0) { - _state=STATE_STATUS; + _state = STATE_STATUS; _responseStatus=ch-'0'; } else @@ -323,7 +321,7 @@ { // _tok1.update(_buffer.markIndex(), _buffer.getIndex() - 1); _tok1 = _buffer.toString(_buffer.markIndex(), _buffer.getIndex() - 1 - _buffer.markIndex()); - _state=STATE_SPACE2; + _state = STATE_SPACE2; continue; } else if (ch>='0' && ch<='9') @@ -334,7 +332,7 @@ else if (ch < HttpTokens.SPACE && ch>=0) { _eol=ch; - _state=STATE_HEADER; + _state = STATE_HEADER; _tok0 = ""; _tok1 = ""; _multiLineValue=null; @@ -357,8 +355,8 @@ { // HTTP/0.9 _handler.startRequest(_tok0, _buffer.sliceFromMark().toString(), null); - _persistent=false; - _state=STATE_SEEKING_EOF; + _persistent = false; + _state = STATE_SEEKING_EOF; _handler.headerComplete(); _handler.messageComplete(_contentPosition); return 1; @@ -385,8 +383,8 @@ { // HTTP/0.9 _handler.startRequest(_tok0, _tok1, null); - _persistent=false; - _state=STATE_SEEKING_EOF; + _persistent = false; + _state = STATE_SEEKING_EOF; _handler.headerComplete(); _handler.messageComplete(_contentPosition); return 1; @@ -478,11 +476,11 @@ switch(HttpHeaderValues.CACHE.getOrdinal(value)) { case HttpHeaderValues.CLOSE_ORDINAL: - _persistent=false; + _persistent = false; break; case HttpHeaderValues.KEEP_ALIVE_ORDINAL: - _persistent=true; + _persistent = true; break; case -1: // No match, may be multi valued @@ -492,11 +490,11 @@ switch(HttpHeaderValues.CACHE.getOrdinal(v.trim())) { case HttpHeaderValues.CLOSE_ORDINAL: - _persistent=false; + _persistent = false; break; case HttpHeaderValues.KEEP_ALIVE_ORDINAL: - _persistent=true; + _persistent = true; break; } } @@ -555,7 +553,7 @@ case HttpTokens.NO_CONTENT: _handler.headerComplete(); - _state=_persistent||(_responseStatus>=100&&_responseStatus<200)?STATE_END:STATE_SEEKING_EOF; + _state = _persistent||(_responseStatus>=100&&_responseStatus<200)?STATE_END:STATE_SEEKING_EOF; _handler.messageComplete(_contentPosition); return 1; @@ -619,7 +617,7 @@ if (_length == -1) _buffer.mark(); _length=_buffer.getIndex() - _buffer.markIndex(); - _state=STATE_HEADER_IN_NAME; + _state = STATE_HEADER_IN_NAME; } } @@ -685,7 +683,7 @@ if (_length == -1) _buffer.mark(); _length=_buffer.getIndex() - _buffer.markIndex(); - _state=STATE_HEADER_IN_VALUE; + _state = STATE_HEADER_IN_VALUE; } } break; @@ -728,7 +726,7 @@ // Handle HEAD response if (_responseStatus>0 && _headResponse) { - _state=_persistent||(_responseStatus>=100&&_responseStatus<200)?STATE_END:STATE_SEEKING_EOF; + _state = _persistent||(_responseStatus>=100&&_responseStatus<200)?STATE_END:STATE_SEEKING_EOF; _handler.messageComplete(_contentLength); } @@ -769,7 +767,7 @@ long remaining=_contentLength - _contentPosition; if (remaining == 0) { - _state=_persistent?STATE_END:STATE_SEEKING_EOF; + _state = _persistent?STATE_END:STATE_SEEKING_EOF; _handler.messageComplete(_contentPosition); return 1; } @@ -788,7 +786,7 @@ if(_contentPosition == _contentLength) { - _state=_persistent?STATE_END:STATE_SEEKING_EOF; + _state = _persistent?STATE_END:STATE_SEEKING_EOF; _handler.messageComplete(_contentPosition); } // TODO adjust the _buffer to keep unconsumed content @@ -806,7 +804,7 @@ { _chunkLength=0; _chunkPosition=0; - _state=STATE_CHUNK_SIZE; + _state = STATE_CHUNK_SIZE; } break; } @@ -822,12 +820,12 @@ { if (_eol==HttpTokens.CARRIAGE_RETURN && _buffer.hasContent() && _buffer.peek()==HttpTokens.LINE_FEED) _eol=_buffer.get(); - _state=_persistent?STATE_END:STATE_SEEKING_EOF; + _state = _persistent?STATE_END:STATE_SEEKING_EOF; _handler.messageComplete(_contentPosition); return 1; } else - _state=STATE_CHUNK; + _state = STATE_CHUNK; } else if (ch <= HttpTokens.SPACE || ch == HttpTokens.SEMI_COLON) _state=STATE_CHUNK_PARAMS; @@ -852,7 +850,7 @@ { if (_eol==HttpTokens.CARRIAGE_RETURN && _buffer.hasContent() && _buffer.peek()==HttpTokens.LINE_FEED) _eol=_buffer.get(); - _state=_persistent?STATE_END:STATE_SEEKING_EOF; + _state = _persistent?STATE_END:STATE_SEEKING_EOF; _handler.messageComplete(_contentPosition); return 1; } @@ -886,7 +884,7 @@ // Close if there is more data than CRLF if (_buffer.length()>2) { - _state=STATE_END; + _state = STATE_END; _endp.close(); } else @@ -913,8 +911,8 @@ } catch(HttpException e) { - _persistent=false; - _state=STATE_SEEKING_EOF; + _persistent = false; + _state = STATE_SEEKING_EOF; throw e; } }
diff -r 4ada7a8c128a -r 563458c4dc93 src/org/eclipse/jetty/server/AbstractHttpConnection.java --- a/src/org/eclipse/jetty/server/AbstractHttpConnection.java Thu Nov 03 04:00:25 2016 -0600 +++ b/src/org/eclipse/jetty/server/AbstractHttpConnection.java Thu Nov 03 21:02:59 2016 -0600 @@ -98,7 +98,7 @@ public volatile Request _request; private volatile ServletInputStream _in; - protected final HttpGenerator _generator; + protected volatile HttpGenerator _generator; final HttpFields _responseFields = new HttpFields(); protected volatile Response _response; private volatile Output _out; @@ -119,7 +119,6 @@ { super(endpoint); _connector = connector; - _generator = new HttpGenerator(_connector.getResponseBuffers(), endpoint); _server = connector.server; init(); } @@ -129,8 +128,15 @@ _parser = new HttpParser(buffers.getHeader(), buffers.getBuffer(), _endp, new RequestHandler()); } + void initGenerator() { + if( _generator != null ) + _generator.shutdown(); + _generator = new HttpGenerator(_connector.getResponseBuffers(), _endp); + } + private void init() { initParser(); + initGenerator(); _request = new Request(this); _response = new Response(this); } @@ -231,7 +237,6 @@ protected void reset() { _requestFields.clear(); - _generator.reset(); _generator.returnBuffers();// TODO maybe only on unhandle _responseFields.clear(); _uri.clear(); @@ -380,7 +385,7 @@ LOG.warn("header full: " + e); _response.reset(); - _generator.reset(); + initGenerator(); _generator.setResponse(HttpStatus.INTERNAL_SERVER_ERROR_500,null); _generator.completeHeader(_responseFields,HttpGenerator.LAST); _generator.complete(); @@ -407,7 +412,7 @@ LOG.debug("",e); _response.reset(); - _generator.reset(); + initGenerator(); _generator.setResponse(HttpStatus.INTERNAL_SERVER_ERROR_500,null); _generator.completeHeader(_responseFields,HttpGenerator.LAST); _generator.complete();