comparison src/org/eclipse/jetty/http/HttpGenerator.java @ 1069:7dd6ec499000

fix use of HttpGenerator._content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 10 Nov 2016 00:42:51 -0700
parents 9d357b9e4bcb
children a44fc6b53757
comparison
equal deleted inserted replaced
1068:9d357b9e4bcb 1069:7dd6ec499000
138 return; 138 return;
139 } 139 }
140 _last = last; 140 _last = last;
141 141
142 // Handle any unfinished business? 142 // Handle any unfinished business?
143 if (_content!=null && _content.remaining()>0 || _bufferChunked) 143 if (_content!=null && _content.hasRemaining() || _bufferChunked)
144 { 144 {
145 if (_endp.isOutputShutdown()) 145 if (_endp.isOutputShutdown())
146 throw new EofException(); 146 throw new EofException();
147 flushBuffer(); 147 flushBuffer();
148 if (_content != null && _content.remaining()>0) 148 if (_content != null && _content.hasRemaining())
149 { 149 {
150 if (_bufferChunked) 150 if (_bufferChunked)
151 { 151 {
152 JBuffer nc = _buffers.getBuffer(_content.remaining()+CHUNK_SPACE+content.remaining()); 152 JBuffer nc = _buffers.getBuffer(_content.remaining()+CHUNK_SPACE+content.remaining());
153 nc.putQ(_content); 153 nc.putQ(_content);
176 if (_head) 176 if (_head)
177 { 177 {
178 // content.clear(); 178 // content.clear();
179 _content = null; 179 _content = null;
180 } 180 }
181 else if ((_buffer==null || _buffer.remaining()==0) && _content.remaining() > 0 && (_last || isCommitted() && _content.remaining()>1024)) 181 else if ((_buffer==null || _buffer.remaining()==0) && _content.hasRemaining() && (_last || isCommitted() && _content.remaining()>1024))
182 { 182 {
183 _bypass = true; 183 _bypass = true;
184 } 184 }
185 else if (!_bufferChunked) 185 else if (!_bufferChunked)
186 { 186 {
187 //System.out.println("qqqqqqqqqqqqqqqqqqq c");
187 // Copy _content to buffer; 188 // Copy _content to buffer;
188 int len = _buffer.put(_content); 189 int len = _buffer.put(_content);
189 _content.skip(len); 190 _content.skip(len);
190 if (_content.remaining() == 0) 191 if (!_content.hasRemaining())
191 _content = null; 192 _content = null;
192 } 193 }
193 } 194 }
194 195
195 /* ------------------------------------------------------------ */ 196 /* ------------------------------------------------------------ */
207 if (_last || _state==STATE_END) 208 if (_last || _state==STATE_END)
208 // return -1; 209 // return -1;
209 throw new RuntimeException("_last"); 210 throw new RuntimeException("_last");
210 211
211 // Handle any unfinished business? 212 // Handle any unfinished business?
212 if (_content != null && _content.remaining()>0 || _bufferChunked) 213 if (_content != null && _content.hasRemaining() || _bufferChunked)
213 { 214 {
214 flushBuffer(); 215 flushBuffer();
215 if (_content != null && _content.remaining()>0 || _bufferChunked) 216 if (_content != null && _content.hasRemaining() || _bufferChunked)
216 throw new IllegalStateException("FULL"); 217 throw new IllegalStateException("FULL");
217 } 218 }
218 219
219 _contentWritten -= _buffer.remaining(); 220 _contentWritten -= _buffer.remaining();
220 /* 221 /*
330 } 331 }
331 332
332 if (_status<200 && _status>=100 ) 333 if (_status<200 && _status>=100 )
333 { 334 {
334 _noContent = true; 335 _noContent = true;
335 _content=null; 336 _content = null;
336 if (_buffer!=null) 337 if (_buffer!=null)
337 _buffer.clearJ(); 338 _buffer.clearJ();
338 // end the header. 339 // end the header.
339 340
340 if (_status!=101 ) 341 if (_status!=101 )
345 } 346 }
346 } 347 }
347 else if (_status==204 || _status==304) 348 else if (_status==204 || _status==304)
348 { 349 {
349 _noContent = true; 350 _noContent = true;
350 _content=null; 351 _content = null;
351 if (_buffer!=null) 352 if (_buffer!=null)
352 _buffer.clearJ(); 353 _buffer.clearJ();
353 } 354 }
354 } 355 }
355 356
708 // Special case handling for small left over buffer from 709 // Special case handling for small left over buffer from
709 // an addContent that caused a buffer flush. 710 // an addContent that caused a buffer flush.
710 if (_content != null && _content.remaining() < _buffer.space() && _state != STATE_FLUSHING) 711 if (_content != null && _content.remaining() < _buffer.space() && _state != STATE_FLUSHING)
711 { 712 {
712 _buffer.put(_content); 713 _buffer.put(_content);
713 _content.clearJ(); 714 _content = null;
714 _content=null;
715 } 715 }
716 } 716 }
717 } 717 }
718 718
719 // Are we completely finished for now? 719 // Are we completely finished for now?
720 if (!_needCRLF && !_needEOC && (_content==null || _content.remaining()==0)) 720 if (!_needCRLF && !_needEOC && (_content==null || !_content.hasRemaining()))
721 { 721 {
722 if (_state == STATE_FLUSHING) 722 if (_state == STATE_FLUSHING)
723 _state = STATE_END; 723 _state = STATE_END;
724 724
725 if (_state==STATE_END && _persistent != null && !_persistent && _status!=100) 725 if (_state==STATE_END && _persistent != null && !_persistent && _status!=100)
751 751
752 private int flushMask() 752 private int flushMask()
753 { 753 {
754 return ((_header.position() > 0)?4:0) 754 return ((_header.position() > 0)?4:0)
755 | ((_buffer != null && _buffer.remaining() > 0)?2:0) 755 | ((_buffer != null && _buffer.remaining() > 0)?2:0)
756 | ((_bypass && _content != null && _content.remaining() > 0)?1:0); 756 | ((_bypass && _content != null && _content.hasRemaining())?1:0);
757 } 757 }
758 758
759 private void prepareBuffers() 759 private void prepareBuffers()
760 { 760 {
761 // if we are not flushing an existing chunk 761 // if we are not flushing an existing chunk
762 if (!_bufferChunked) 762 if (!_bufferChunked)
763 { 763 {
764 // Refill buffer if possible 764 // Refill buffer if possible
765 if (!_bypass && _content != null && _content.remaining() > 0 && _buffer != null && _buffer.space() > 0) 765 if (!_bypass && _content != null && _content.hasRemaining() && _buffer != null && _buffer.space() > 0)
766 { 766 {
767 int len = _buffer.put(_content); 767 int len = _buffer.put(_content);
768 _content.skip(len); 768 _content.skip(len);
769 if (_content.remaining() == 0) 769 if (!_content.hasRemaining())
770 _content = null; 770 _content = null;
771 } 771 }
772 772
773 // Chunk buffer if need be 773 // Chunk buffer if need be
774 if (_contentLength == HttpTokens.CHUNKED_CONTENT) 774 if (_contentLength == HttpTokens.CHUNKED_CONTENT)
817 _needCRLF = true; 817 _needCRLF = true;
818 } 818 }
819 } 819 }
820 820
821 // If we need EOC and everything written 821 // If we need EOC and everything written
822 if (_needEOC && (_content == null || _content.remaining() == 0)) 822 if (_needEOC && (_content == null || !_content.hasRemaining()))
823 { 823 {
824 if (_needCRLF) 824 if (_needCRLF)
825 { 825 {
826 if (_buffer == null && _header.remaining() >= HttpTokens.CRLF.length) 826 if (_buffer == null && _header.remaining() >= HttpTokens.CRLF.length)
827 { 827 {
858 } 858 }
859 } 859 }
860 } 860 }
861 } 861 }
862 862
863 if (_content != null && _content.remaining() == 0) 863 if (_content != null && !_content.hasRemaining())
864 _content = null; 864 _content = null;
865 865
866 } 866 }
867 867
868 @Override 868 @Override
869 public String toString() 869 public String toString()
870 { 870 {
871 JBuffer header = _header; 871 JBuffer header = _header;
872 JBuffer buffer=_buffer; 872 JBuffer buffer=_buffer;
873 JBuffer content=_content; 873 JBuffer content = _content;
874 return String.format("%s{s=%d,h=%d,b=%d,c=%d}", 874 return String.format("%s{s=%d,h=%d,b=%d,c=%d}",
875 getClass().getSimpleName(), 875 getClass().getSimpleName(),
876 _state, 876 _state,
877 header == null ? -1 : header.position(), 877 header == null ? -1 : header.position(),
878 buffer == null ? -1 : buffer.remaining(), 878 buffer == null ? -1 : buffer.remaining(),