Mercurial Hosting > luan
comparison src/org/eclipse/jetty/server/Response.java @ 1022:3718afd99988
HttpHeaders uses StringCache
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 01 Nov 2016 01:04:46 -0600 |
parents | 6be43ef1eb96 |
children | 27f3dc761452 |
comparison
equal
deleted
inserted
replaced
1021:e350c11242be | 1022:3718afd99988 |
---|---|
231 writer.writeTo(getOutputStream()); | 231 writer.writeTo(getOutputStream()); |
232 writer.destroy(); | 232 writer.destroy(); |
233 } | 233 } |
234 else if (code!=SC_PARTIAL_CONTENT) | 234 else if (code!=SC_PARTIAL_CONTENT) |
235 { | 235 { |
236 _connection._requestFields.remove(HttpHeaders.CONTENT_TYPE_BUFFER); | 236 _connection._requestFields.remove(HttpHeaders.CONTENT_TYPE); |
237 _connection._requestFields.remove(HttpHeaders.CONTENT_LENGTH_BUFFER); | 237 _connection._requestFields.remove(HttpHeaders.CONTENT_LENGTH); |
238 _characterEncoding = null; | 238 _characterEncoding = null; |
239 _mimeType = null; | 239 _mimeType = null; |
240 _cachedMimeType = null; | 240 _cachedMimeType = null; |
241 } | 241 } |
242 | 242 |
486 _contentType = _mimeType; | 486 _contentType = _mimeType; |
487 else | 487 else |
488 _contentType = null; | 488 _contentType = null; |
489 | 489 |
490 if (_contentType==null) | 490 if (_contentType==null) |
491 _connection._responseFields.remove(HttpHeaders.CONTENT_TYPE_BUFFER); | 491 _connection._responseFields.remove(HttpHeaders.CONTENT_TYPE); |
492 else | 492 else |
493 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 493 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
494 } | 494 } |
495 } | 495 } |
496 else | 496 else |
497 { | 497 { |
498 // No, so just add this one to the mimetype | 498 // No, so just add this one to the mimetype |
507 { | 507 { |
508 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); | 508 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); |
509 if (content_type!=null) | 509 if (content_type!=null) |
510 { | 510 { |
511 _contentType = content_type.toString(); | 511 _contentType = content_type.toString(); |
512 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type); | 512 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
513 } | 513 } |
514 } | 514 } |
515 | 515 |
516 if (_contentType==null) | 516 if (_contentType==null) |
517 { | 517 { |
518 _contentType = _mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | 518 _contentType = _mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); |
519 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 519 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
520 } | 520 } |
521 } | 521 } |
522 else | 522 else |
523 { | 523 { |
524 int i1=_contentType.indexOf("charset=",i0); | 524 int i1=_contentType.indexOf("charset=",i0); |
533 if (i2<0) | 533 if (i2<0) |
534 _contentType=_contentType.substring(0,i8)+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | 534 _contentType=_contentType.substring(0,i8)+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); |
535 else | 535 else |
536 _contentType=_contentType.substring(0,i8)+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ")+_contentType.substring(i2); | 536 _contentType=_contentType.substring(0,i8)+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ")+_contentType.substring(i2); |
537 } | 537 } |
538 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 538 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
539 } | 539 } |
540 } | 540 } |
541 } | 541 } |
542 } | 542 } |
543 } | 543 } |
588 if (_locale==null) | 588 if (_locale==null) |
589 _characterEncoding = null; | 589 _characterEncoding = null; |
590 _mimeType = null; | 590 _mimeType = null; |
591 _cachedMimeType = null; | 591 _cachedMimeType = null; |
592 _contentType=null; | 592 _contentType=null; |
593 _connection._responseFields.remove(HttpHeaders.CONTENT_TYPE_BUFFER); | 593 _connection._responseFields.remove(HttpHeaders.CONTENT_TYPE); |
594 } | 594 } |
595 else | 595 else |
596 { | 596 { |
597 // Look for encoding in contentType | 597 // Look for encoding in contentType |
598 int i0=contentType.indexOf(';'); | 598 int i0=contentType.indexOf(';'); |
622 { | 622 { |
623 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); | 623 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); |
624 if (content_type!=null) | 624 if (content_type!=null) |
625 { | 625 { |
626 _contentType=content_type.toString(); | 626 _contentType=content_type.toString(); |
627 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type); | 627 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
628 } | 628 } |
629 else | 629 else |
630 { | 630 { |
631 _contentType = _mimeType+";charset="+_characterEncoding; | 631 _contentType = _mimeType+";charset="+_characterEncoding; |
632 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 632 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
633 } | 633 } |
634 } | 634 } |
635 else | 635 else |
636 { | 636 { |
637 _contentType = _mimeType+";charset="+_characterEncoding; | 637 _contentType = _mimeType+";charset="+_characterEncoding; |
638 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 638 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
639 } | 639 } |
640 } | 640 } |
641 else if (i2<0) | 641 else if (i2<0) |
642 { | 642 { |
643 _contentType=contentType.substring(0,i1)+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | 643 _contentType=contentType.substring(0,i1)+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); |
644 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 644 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
645 } | 645 } |
646 else | 646 else |
647 { | 647 { |
648 _contentType=contentType.substring(0,i1)+contentType.substring(i2)+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | 648 _contentType=contentType.substring(0,i1)+contentType.substring(i2)+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); |
649 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 649 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
650 } | 650 } |
651 } | 651 } |
652 else if ((i1==i0+1 && i2<0) || (i1==i0+2 && i2<0 && contentType.charAt(i0+1)==' ')) | 652 else if ((i1==i0+1 && i2<0) || (i1==i0+2 && i2<0 && contentType.charAt(i0+1)==' ')) |
653 { | 653 { |
654 // The params are just the char encoding | 654 // The params are just the char encoding |
659 { | 659 { |
660 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); | 660 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); |
661 if (content_type!=null) | 661 if (content_type!=null) |
662 { | 662 { |
663 _contentType=content_type.toString(); | 663 _contentType=content_type.toString(); |
664 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type); | 664 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
665 } | 665 } |
666 else | 666 else |
667 { | 667 { |
668 _contentType=contentType; | 668 _contentType=contentType; |
669 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 669 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
670 } | 670 } |
671 } | 671 } |
672 else | 672 else |
673 { | 673 { |
674 _contentType=contentType; | 674 _contentType=contentType; |
675 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 675 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
676 } | 676 } |
677 } | 677 } |
678 else if (i2>0) | 678 else if (i2>0) |
679 { | 679 { |
680 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8,i2)); | 680 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8,i2)); |
681 _contentType=contentType; | 681 _contentType=contentType; |
682 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 682 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
683 } | 683 } |
684 else | 684 else |
685 { | 685 { |
686 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8)); | 686 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8)); |
687 _contentType=contentType; | 687 _contentType=contentType; |
688 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 688 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
689 } | 689 } |
690 } | 690 } |
691 else // No encoding in the params. | 691 else // No encoding in the params. |
692 { | 692 { |
693 _cachedMimeType = null; | 693 _cachedMimeType = null; |
694 _contentType=_characterEncoding==null?contentType:contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | 694 _contentType=_characterEncoding==null?contentType:contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); |
695 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 695 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
696 } | 696 } |
697 } | 697 } |
698 else // No params at all | 698 else // No params at all |
699 { | 699 { |
700 _mimeType = contentType; | 700 _mimeType = contentType; |
706 { | 706 { |
707 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); | 707 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); |
708 if (content_type!=null) | 708 if (content_type!=null) |
709 { | 709 { |
710 _contentType=content_type.toString(); | 710 _contentType=content_type.toString(); |
711 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,content_type); | 711 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
712 } | 712 } |
713 else | 713 else |
714 { | 714 { |
715 _contentType = _mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | 715 _contentType = _mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); |
716 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 716 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
717 } | 717 } |
718 } | 718 } |
719 else | 719 else |
720 { | 720 { |
721 _contentType=contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); | 721 _contentType=contentType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); |
722 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 722 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
723 } | 723 } |
724 } | 724 } |
725 else if (_cachedMimeType!=null) | 725 else if (_cachedMimeType!=null) |
726 { | 726 { |
727 _contentType = _cachedMimeType.toString(); | 727 _contentType = _cachedMimeType.toString(); |
728 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_cachedMimeType); | 728 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
729 } | 729 } |
730 else | 730 else |
731 { | 731 { |
732 _contentType=contentType; | 732 _contentType=contentType; |
733 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE_BUFFER,_contentType); | 733 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); |
734 } | 734 } |
735 } | 735 } |
736 } | 736 } |
737 } | 737 } |
738 | 738 |
763 _reason = null; | 763 _reason = null; |
764 | 764 |
765 HttpFields response_fields=_connection._responseFields; | 765 HttpFields response_fields=_connection._responseFields; |
766 | 766 |
767 response_fields.clear(); | 767 response_fields.clear(); |
768 String connection=_connection._requestFields.getStringField(HttpHeaders.CONNECTION_BUFFER); | 768 String connection=_connection._requestFields.getStringField(HttpHeaders.CONNECTION); |
769 if (connection!=null) | 769 if (connection!=null) |
770 { | 770 { |
771 String[] values = connection.split(","); | 771 String[] values = connection.split(","); |
772 for (int i=0;values!=null && i<values.length;i++) | 772 for (int i=0;values!=null && i<values.length;i++) |
773 { | 773 { |
776 if (cb != -1) | 776 if (cb != -1) |
777 { | 777 { |
778 switch(cb) | 778 switch(cb) |
779 { | 779 { |
780 case HttpHeaderValues.CLOSE_ORDINAL: | 780 case HttpHeaderValues.CLOSE_ORDINAL: |
781 response_fields.put(HttpHeaders.CONNECTION_BUFFER,HttpHeaderValues.CLOSE); | 781 response_fields.put(HttpHeaders.CONNECTION,HttpHeaderValues.CLOSE); |
782 break; | 782 break; |
783 | 783 |
784 case HttpHeaderValues.KEEP_ALIVE_ORDINAL: | 784 case HttpHeaderValues.KEEP_ALIVE_ORDINAL: |
785 if (HttpVersions.HTTP_1_0.equalsIgnoreCase(_connection.getRequest().getProtocol())) | 785 if (HttpVersions.HTTP_1_0.equalsIgnoreCase(_connection.getRequest().getProtocol())) |
786 response_fields.put(HttpHeaders.CONNECTION_BUFFER,HttpHeaderValues.KEEP_ALIVE); | 786 response_fields.put(HttpHeaders.CONNECTION,HttpHeaderValues.KEEP_ALIVE); |
787 break; | 787 break; |
788 case HttpHeaderValues.TE_ORDINAL: | 788 case HttpHeaderValues.TE_ORDINAL: |
789 response_fields.put(HttpHeaders.CONNECTION_BUFFER,HttpHeaderValues.TE); | 789 response_fields.put(HttpHeaders.CONNECTION,HttpHeaderValues.TE); |
790 break; | 790 break; |
791 } | 791 } |
792 } | 792 } |
793 } | 793 } |
794 } | 794 } |
823 { | 823 { |
824 if (locale == null || isCommitted()) | 824 if (locale == null || isCommitted()) |
825 return; | 825 return; |
826 | 826 |
827 _locale = locale; | 827 _locale = locale; |
828 _connection._responseFields.put(HttpHeaders.CONTENT_LANGUAGE_BUFFER,locale.toString().replace('_','-')); | 828 _connection._responseFields.put(HttpHeaders.CONTENT_LANGUAGE,locale.toString().replace('_','-')); |
829 } | 829 } |
830 | 830 |
831 @Override | 831 @Override |
832 public Locale getLocale() | 832 public Locale getLocale() |
833 { | 833 { |