Mercurial Hosting > luan
comparison src/org/eclipse/jetty/http/HttpGenerator.java @ 1074:6b7ff30bb990
rename putQ() to put()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 10 Nov 2016 02:37:15 -0700 |
parents | b4ba8a4d5a16 |
children | ebb0f1343ef6 |
comparison
equal
deleted
inserted
replaced
1073:6e511ea557b4 | 1074:6b7ff30bb990 |
---|---|
148 if (_content != null && _content.hasRemaining()) | 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.put(_content); |
154 nc.putQ(HttpTokens.CRLF); | 154 nc.put(HttpTokens.CRLF); |
155 BufferUtil.putHexInt(nc, content.remaining()); | 155 BufferUtil.putHexInt(nc, content.remaining()); |
156 nc.putQ(HttpTokens.CRLF); | 156 nc.put(HttpTokens.CRLF); |
157 nc.putQ(content); | 157 nc.put(content); |
158 nc.flip(); | 158 nc.flip(); |
159 content = nc; | 159 content = nc; |
160 } | 160 } |
161 else | 161 else |
162 { | 162 { |
163 JBuffer nc = _buffers.getBuffer(_content.remaining()+content.remaining()); | 163 JBuffer nc = _buffers.getBuffer(_content.remaining()+content.remaining()); |
164 nc.putQ(_content); | 164 nc.put(_content); |
165 nc.putQ(content); | 165 nc.put(content); |
166 nc.flip(); | 166 nc.flip(); |
167 content = nc; | 167 content = nc; |
168 } | 168 } |
169 } | 169 } |
170 } | 170 } |
184 } | 184 } |
185 else if (!_bufferChunked) | 185 else if (!_bufferChunked) |
186 { | 186 { |
187 //System.out.println("qqqqqqqqqqqqqqqqqqq c"); | 187 //System.out.println("qqqqqqqqqqqqqqqqqqq c"); |
188 // Copy _content to buffer; | 188 // Copy _content to buffer; |
189 _buffer.putQ(_content); | 189 _buffer.put(_content); |
190 if (!_content.hasRemaining()) | 190 if (!_content.hasRemaining()) |
191 _content = null; | 191 _content = null; |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
234 throw new IllegalArgumentException("!1xx"); | 234 throw new IllegalArgumentException("!1xx"); |
235 Status status = __status[code]; | 235 Status status = __status[code]; |
236 if (status==null) | 236 if (status==null) |
237 throw new IllegalArgumentException(code+"?"); | 237 throw new IllegalArgumentException(code+"?"); |
238 | 238 |
239 _header.putQ(status._responseLine); | 239 _header.put(status._responseLine); |
240 _header.putQ(HttpTokens.CRLF); | 240 _header.put(HttpTokens.CRLF); |
241 | 241 |
242 try | 242 try |
243 { | 243 { |
244 // nasty semi busy flush! | 244 // nasty semi busy flush! |
245 _header.flip(); | 245 _header.flip(); |
292 // add response line | 292 // add response line |
293 Status status = _status<__status.length?__status[_status]:null; | 293 Status status = _status<__status.length?__status[_status]:null; |
294 | 294 |
295 if (status==null) | 295 if (status==null) |
296 { | 296 { |
297 _header.putQ(HttpVersions.HTTP_1_1_BYTES); | 297 _header.put(HttpVersions.HTTP_1_1_BYTES); |
298 _header.putQ((byte) ' '); | 298 _header.put((byte) ' '); |
299 _header.putQ((byte) ('0' + _status / 100)); | 299 _header.put((byte) ('0' + _status / 100)); |
300 _header.putQ((byte) ('0' + (_status % 100) / 10)); | 300 _header.put((byte) ('0' + (_status % 100) / 10)); |
301 _header.putQ((byte) ('0' + (_status % 10))); | 301 _header.put((byte) ('0' + (_status % 10))); |
302 _header.putQ((byte) ' '); | 302 _header.put((byte) ' '); |
303 if (_reason==null) | 303 if (_reason==null) |
304 { | 304 { |
305 _header.putQ((byte) ('0' + _status / 100)); | 305 _header.put((byte) ('0' + _status / 100)); |
306 _header.putQ((byte) ('0' + (_status % 100) / 10)); | 306 _header.put((byte) ('0' + (_status % 100) / 10)); |
307 _header.putQ((byte) ('0' + (_status % 10))); | 307 _header.put((byte) ('0' + (_status % 10))); |
308 } | 308 } |
309 else | 309 else |
310 _header.putQ(_reason); | 310 _header.put(_reason); |
311 _header.putQ(HttpTokens.CRLF); | 311 _header.put(HttpTokens.CRLF); |
312 } | 312 } |
313 else | 313 else |
314 { | 314 { |
315 if (_reason==null) | 315 if (_reason==null) |
316 _header.putQ(status._responseLine); | 316 _header.put(status._responseLine); |
317 else | 317 else |
318 { | 318 { |
319 _header.putQ(status._schemeCode); | 319 _header.put(status._schemeCode); |
320 _header.putQ(_reason); | 320 _header.put(_reason); |
321 _header.putQ(HttpTokens.CRLF); | 321 _header.put(HttpTokens.CRLF); |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 if (_status<200 && _status>=100 ) | 325 if (_status<200 && _status>=100 ) |
326 { | 326 { |
329 _buffer.clear(); | 329 _buffer.clear(); |
330 // end the header. | 330 // end the header. |
331 | 331 |
332 if (_status!=101 ) | 332 if (_status!=101 ) |
333 { | 333 { |
334 _header.putQ(HttpTokens.CRLF); | 334 _header.put(HttpTokens.CRLF); |
335 _state = STATE_CONTENT; | 335 _state = STATE_CONTENT; |
336 return; | 336 return; |
337 } | 337 } |
338 } | 338 } |
339 else if (_status==204 || _status==304) | 339 else if (_status==204 || _status==304) |
512 // we have seen all the _content there is | 512 // we have seen all the _content there is |
513 _contentLength = _contentWritten; | 513 _contentLength = _contentWritten; |
514 if (content_length == null && !_noContent) | 514 if (content_length == null && !_noContent) |
515 { | 515 { |
516 // known length but not actually set. | 516 // known length but not actually set. |
517 _header.putQ(HttpHeaders.CONTENT_LENGTH_BYTES); | 517 _header.put(HttpHeaders.CONTENT_LENGTH_BYTES); |
518 _header.putQ(HttpTokens.COLON); | 518 _header.put(HttpTokens.COLON); |
519 _header.putQ((byte) ' '); | 519 _header.put((byte) ' '); |
520 BufferUtil.putDecLong(_header, _contentLength); | 520 BufferUtil.putDecLong(_header, _contentLength); |
521 _header.putQ(HttpTokens.CRLF); | 521 _header.put(HttpTokens.CRLF); |
522 } | 522 } |
523 } | 523 } |
524 else | 524 else |
525 { | 525 { |
526 // No idea, so we must assume that a body is coming | 526 // No idea, so we must assume that a body is coming |
528 } | 528 } |
529 break; | 529 break; |
530 | 530 |
531 case HttpTokens.NO_CONTENT: | 531 case HttpTokens.NO_CONTENT: |
532 if (content_length == null && _status >= 200 && _status != 204 && _status != 304) | 532 if (content_length == null && _status >= 200 && _status != 204 && _status != 304) |
533 _header.putQ(CONTENT_LENGTH_0); | 533 _header.put(CONTENT_LENGTH_0); |
534 break; | 534 break; |
535 | 535 |
536 case HttpTokens.EOF_CONTENT: | 536 case HttpTokens.EOF_CONTENT: |
537 _persistent = false; | 537 _persistent = false; |
538 break; | 538 break; |
556 transfer_encoding.putTo(_header); | 556 transfer_encoding.putTo(_header); |
557 else | 557 else |
558 throw new IllegalArgumentException("BAD TE"); | 558 throw new IllegalArgumentException("BAD TE"); |
559 } | 559 } |
560 else | 560 else |
561 _header.putQ(TRANSFER_ENCODING_CHUNKED); | 561 _header.put(TRANSFER_ENCODING_CHUNKED); |
562 } | 562 } |
563 | 563 |
564 // Handle connection if need be | 564 // Handle connection if need be |
565 if (_contentLength==HttpTokens.EOF_CONTENT) | 565 if (_contentLength==HttpTokens.EOF_CONTENT) |
566 { | 566 { |
568 _persistent=false; | 568 _persistent=false; |
569 } | 569 } |
570 | 570 |
571 if (!_persistent && (close || _version > HttpVersions.HTTP_1_0_ORDINAL)) | 571 if (!_persistent && (close || _version > HttpVersions.HTTP_1_0_ORDINAL)) |
572 { | 572 { |
573 _header.putQ(CONNECTION_CLOSE); | 573 _header.put(CONNECTION_CLOSE); |
574 if (connection!=null) | 574 if (connection!=null) |
575 { | 575 { |
576 _header.position(_header.position()-2); | 576 _header.position(_header.position()-2); |
577 _header.putQ((byte)','); | 577 _header.put((byte)','); |
578 _header.putQ(connection.toString().getBytes()); | 578 _header.put(connection.toString().getBytes()); |
579 _header.putQ(CRLF); | 579 _header.put(CRLF); |
580 } | 580 } |
581 } | 581 } |
582 else if (keep_alive) | 582 else if (keep_alive) |
583 { | 583 { |
584 _header.putQ(CONNECTION_KEEP_ALIVE); | 584 _header.put(CONNECTION_KEEP_ALIVE); |
585 if (connection!=null) | 585 if (connection!=null) |
586 { | 586 { |
587 _header.position(_header.position()-2); | 587 _header.position(_header.position()-2); |
588 _header.putQ((byte)','); | 588 _header.put((byte)','); |
589 _header.putQ(connection.toString().getBytes()); | 589 _header.put(connection.toString().getBytes()); |
590 _header.putQ(CRLF); | 590 _header.put(CRLF); |
591 } | 591 } |
592 } | 592 } |
593 else if (connection!=null) | 593 else if (connection!=null) |
594 { | 594 { |
595 _header.putQ(CONNECTION_); | 595 _header.put(CONNECTION_); |
596 _header.putQ(connection.toString().getBytes()); | 596 _header.put(connection.toString().getBytes()); |
597 _header.putQ(CRLF); | 597 _header.put(CRLF); |
598 } | 598 } |
599 | 599 |
600 if (!has_server && _status>199) | 600 if (!has_server && _status>199) |
601 _header.putQ(SERVER); | 601 _header.put(SERVER); |
602 | 602 |
603 // end the header. | 603 // end the header. |
604 _header.putQ(HttpTokens.CRLF); | 604 _header.put(HttpTokens.CRLF); |
605 _state = STATE_CONTENT; | 605 _state = STATE_CONTENT; |
606 | 606 |
607 } | 607 } |
608 catch(ArrayIndexOutOfBoundsException e) | 608 catch(ArrayIndexOutOfBoundsException e) |
609 { | 609 { |
702 { | 702 { |
703 // Special case handling for small left over buffer from | 703 // Special case handling for small left over buffer from |
704 // an addContent that caused a buffer flush. | 704 // an addContent that caused a buffer flush. |
705 if (_content != null && _content.remaining() < _buffer.remaining() && _state != STATE_FLUSHING) | 705 if (_content != null && _content.remaining() < _buffer.remaining() && _state != STATE_FLUSHING) |
706 { | 706 { |
707 _buffer.putQ(_content); | 707 _buffer.put(_content); |
708 _content = null; | 708 _content = null; |
709 } | 709 } |
710 } | 710 } |
711 | 711 |
712 // Are we completely finished for now? | 712 // Are we completely finished for now? |
755 if (!_bufferChunked) | 755 if (!_bufferChunked) |
756 { | 756 { |
757 // Refill buffer if possible | 757 // Refill buffer if possible |
758 if (!_bypass && _content != null && _content.hasRemaining() && _buffer.hasRemaining()) | 758 if (!_bypass && _content != null && _content.hasRemaining() && _buffer.hasRemaining()) |
759 { | 759 { |
760 _buffer.putQ(_content); | 760 _buffer.put(_content); |
761 if (!_content.hasRemaining()) | 761 if (!_content.hasRemaining()) |
762 _content = null; | 762 _content = null; |
763 } | 763 } |
764 | 764 |
765 // Chunk buffer if need be | 765 // Chunk buffer if need be |
773 | 773 |
774 // if we need CRLF add this to header | 774 // if we need CRLF add this to header |
775 if (_needCRLF) | 775 if (_needCRLF) |
776 { | 776 { |
777 if (_header.position() > 0) throw new IllegalStateException("EOC"); | 777 if (_header.position() > 0) throw new IllegalStateException("EOC"); |
778 _header.putQ(HttpTokens.CRLF); | 778 _header.put(HttpTokens.CRLF); |
779 _needCRLF = false; | 779 _needCRLF = false; |
780 } | 780 } |
781 // Add the chunk size to the header | 781 // Add the chunk size to the header |
782 BufferUtil.putHexInt(_header, size); | 782 BufferUtil.putHexInt(_header, size); |
783 _header.putQ(HttpTokens.CRLF); | 783 _header.put(HttpTokens.CRLF); |
784 | 784 |
785 // Need a CRLF after the content | 785 // Need a CRLF after the content |
786 _needCRLF = true; | 786 _needCRLF = true; |
787 } | 787 } |
788 else | 788 else |
794 _bufferChunked = true; | 794 _bufferChunked = true; |
795 | 795 |
796 if (_needCRLF) | 796 if (_needCRLF) |
797 { | 797 { |
798 if (_header.position() > 0) throw new IllegalStateException("EOC"); | 798 if (_header.position() > 0) throw new IllegalStateException("EOC"); |
799 _header.putQ(HttpTokens.CRLF); | 799 _header.put(HttpTokens.CRLF); |
800 _needCRLF = false; | 800 _needCRLF = false; |
801 } | 801 } |
802 BufferUtil.putHexInt(_header, size); | 802 BufferUtil.putHexInt(_header, size); |
803 _header.putQ(HttpTokens.CRLF); | 803 _header.put(HttpTokens.CRLF); |
804 | 804 |
805 // Add end chunk trailer. | 805 // Add end chunk trailer. |
806 if (_buffer.remaining() >= 2) | 806 if (_buffer.remaining() >= 2) |
807 _buffer.putQ(HttpTokens.CRLF); | 807 _buffer.put(HttpTokens.CRLF); |
808 else | 808 else |
809 _needCRLF = true; | 809 _needCRLF = true; |
810 } | 810 } |
811 } | 811 } |
812 | 812 |
813 // If we need EOC and everything written | 813 // If we need EOC and everything written |
814 if (_needEOC && (_content == null || !_content.hasRemaining())) | 814 if (_needEOC && (_content == null || !_content.hasRemaining())) |
815 { | 815 { |
816 if (_needCRLF && _buffer.remaining() >= HttpTokens.CRLF.length) { | 816 if (_needCRLF && _buffer.remaining() >= HttpTokens.CRLF.length) { |
817 _buffer.putQ(HttpTokens.CRLF); | 817 _buffer.put(HttpTokens.CRLF); |
818 _needCRLF = false; | 818 _needCRLF = false; |
819 } | 819 } |
820 | 820 |
821 if (!_needCRLF && _needEOC && _buffer.remaining() >= LAST_CHUNK.length) { | 821 if (!_needCRLF && _needEOC && _buffer.remaining() >= LAST_CHUNK.length) { |
822 if (!_head) | 822 if (!_head) |
823 { | 823 { |
824 _buffer.putQ(LAST_CHUNK); | 824 _buffer.put(LAST_CHUNK); |
825 _bufferChunked = true; | 825 _bufferChunked = true; |
826 } | 826 } |
827 _needEOC = false; | 827 _needEOC = false; |
828 } | 828 } |
829 } | 829 } |
1008 _reason = BufferUtil.newBuffer(len); | 1008 _reason = BufferUtil.newBuffer(len); |
1009 for (int i=0;i<len;i++) | 1009 for (int i=0;i<len;i++) |
1010 { | 1010 { |
1011 char ch = reason.charAt(i); | 1011 char ch = reason.charAt(i); |
1012 if (ch!='\r'&&ch!='\n') | 1012 if (ch!='\r'&&ch!='\n') |
1013 _reason.putQ((byte)ch); | 1013 _reason.put((byte)ch); |
1014 else | 1014 else |
1015 _reason.putQ((byte)' '); | 1015 _reason.put((byte)' '); |
1016 } | 1016 } |
1017 _reason.flip(); | 1017 _reason.flip(); |
1018 } | 1018 } |
1019 } | 1019 } |
1020 | 1020 |