Mercurial Hosting > luan
diff src/org/eclipse/jetty/http/HttpGenerator.java @ 983:23ec25435b8c
simplify AbstractGenerator
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 16 Oct 2016 22:58:41 -0600 |
parents | dbecd7faa1f5 |
children | 83cc6e05a58f |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/http/HttpGenerator.java Sun Oct 16 21:40:27 2016 -0600 +++ b/src/org/eclipse/jetty/http/HttpGenerator.java Sun Oct 16 22:58:41 2016 -0600 @@ -47,7 +47,6 @@ // Build cache of response lines for status private static class Status { - Buffer _reason; Buffer _schemeCode; Buffer _responseLine; } @@ -75,21 +74,11 @@ bytes[versionLength+6+reason.length()]=HttpTokens.LINE_FEED; __status[i] = new Status(); - __status[i]._reason=new ByteArrayBuffer(bytes,versionLength+5,bytes.length-versionLength-7,Buffer.IMMUTABLE); __status[i]._schemeCode=new ByteArrayBuffer(bytes,0,versionLength+5,Buffer.IMMUTABLE); __status[i]._responseLine=new ByteArrayBuffer(bytes,0,bytes.length,Buffer.IMMUTABLE); } } - /* ------------------------------------------------------------------------------- */ - public static Buffer getReasonBuffer(int code) - { - Status status = code<__status.length?__status[code]:null; - if (status!=null) - return status._reason; - return null; - } - // common _content private static final byte[] LAST_CHUNK = @@ -106,25 +95,17 @@ private static final int CHUNK_SPACE = 12; // data - protected boolean _bypass = false; // True if _content buffer can be written directly to endp and bypass the content buffer + private boolean _bypass = false; // True if _content buffer can be written directly to endp and bypass the content buffer private boolean _needCRLF = false; private boolean _needEOC = false; private boolean _bufferChunked = false; - /* ------------------------------------------------------------------------------- */ - /** - * Constructor. - * - * @param buffers buffer pool - * @param io the end point to use - */ public HttpGenerator(Buffers buffers, EndPoint io) { super(buffers,io); } - /* ------------------------------------------------------------------------------- */ @Override public void reset() { @@ -149,7 +130,7 @@ _bypass = false; _needCRLF = false; _needEOC = false; - _bufferChunked=false; + _bufferChunked = false; _method=null; _uri=null; _noContent=false; @@ -262,7 +243,6 @@ * @return the available space in the buffer. * @throws IOException */ - @Override public int prepareUncheckedAddContent() throws IOException { if (_noContent) @@ -293,7 +273,6 @@ return _buffer.space()-(_contentLength == HttpTokens.CHUNKED_CONTENT?CHUNK_SPACE:0); } - /* ------------------------------------------------------------ */ @Override public boolean isBufferFull() { @@ -301,7 +280,6 @@ return super.isBufferFull() || _bufferChunked || _bypass || (_contentLength == HttpTokens.CHUNKED_CONTENT && _buffer != null && _buffer.space() < CHUNK_SPACE); } - /* ------------------------------------------------------------ */ public void send1xx(int code) throws IOException { if (_state != STATE_HEADER) @@ -309,7 +287,7 @@ if (code<100||code>199) throw new IllegalArgumentException("!1xx"); - Status status=__status[code]; + Status status = __status[code]; if (status==null) throw new IllegalArgumentException(code+"?"); @@ -339,21 +317,17 @@ } } - /* ------------------------------------------------------------ */ @Override - public boolean isRequest() + boolean isRequest() { return _method!=null; } - /* ------------------------------------------------------------ */ - @Override - public boolean isResponse() + private boolean isResponse() { return _method==null; } - /* ------------------------------------------------------------ */ @Override public void completeHeader(HttpFields fields, boolean allContentAdded) throws IOException { @@ -474,16 +448,6 @@ } } - // Add headers - if (_status>=200 && _date!=null) - { - _header.put(HttpHeaders.DATE_BUFFER); - _header.put((byte)':'); - _header.put((byte)' '); - _header.put(_date); - _header.put(CRLF); - } - // key field values HttpFields.Field content_length = null; HttpFields.Field transfer_encoding = null; @@ -791,7 +755,6 @@ flushBuffer(); } - /* ------------------------------------------------------------ */ @Override public int flushBuffer() throws IOException { @@ -908,7 +871,6 @@ } } - /* ------------------------------------------------------------ */ private int flushMask() { return ((_header != null && _header.length() > 0)?4:0) @@ -916,7 +878,6 @@ | ((_bypass && _content != null && _content.length() > 0)?1:0); } - /* ------------------------------------------------------------ */ private void prepareBuffers() { // if we are not flushing an existing chunk @@ -955,7 +916,7 @@ _header.put(HttpTokens.CRLF); // Need a CRLF after the content - _needCRLF=true; + _needCRLF = true; } else if (_buffer!=null) { @@ -1055,20 +1016,6 @@ } - public int getBytesBuffered() - { - return(_header==null?0:_header.length())+ - (_buffer==null?0:_buffer.length())+ - (_content==null?0:_content.length()); - } - - public boolean isEmpty() - { - return (_header==null||_header.length()==0) && - (_buffer==null||_buffer.length()==0) && - (_content==null||_content.length()==0); - } - @Override public String toString() {