comparison src/org/eclipse/jetty/server/Response.java @ 1023:27f3dc761452

MimeTypes uses StringCache
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 01 Nov 2016 03:44:46 -0600
parents 3718afd99988
children
comparison
equal deleted inserted replaced
1022:3718afd99988 1023:27f3dc761452
40 import org.eclipse.jetty.http.HttpHeaders; 40 import org.eclipse.jetty.http.HttpHeaders;
41 import org.eclipse.jetty.http.HttpStatus; 41 import org.eclipse.jetty.http.HttpStatus;
42 import org.eclipse.jetty.http.HttpURI; 42 import org.eclipse.jetty.http.HttpURI;
43 import org.eclipse.jetty.http.HttpVersions; 43 import org.eclipse.jetty.http.HttpVersions;
44 import org.eclipse.jetty.http.MimeTypes; 44 import org.eclipse.jetty.http.MimeTypes;
45 import org.eclipse.jetty.io.BufferCache.CachedBuffer;
46 import org.eclipse.jetty.server.handler.ContextHandler; 45 import org.eclipse.jetty.server.handler.ContextHandler;
47 import org.eclipse.jetty.util.ByteArrayISO8859Writer; 46 import org.eclipse.jetty.util.ByteArrayISO8859Writer;
48 import org.eclipse.jetty.util.QuotedStringTokenizer; 47 import org.eclipse.jetty.util.QuotedStringTokenizer;
49 import org.eclipse.jetty.util.StringUtil; 48 import org.eclipse.jetty.util.StringUtil;
50 import org.eclipse.jetty.util.URIUtil; 49 import org.eclipse.jetty.util.URIUtil;
82 private final AbstractHttpConnection _connection; 81 private final AbstractHttpConnection _connection;
83 private int _status = SC_OK; 82 private int _status = SC_OK;
84 private String _reason; 83 private String _reason;
85 private Locale _locale; 84 private Locale _locale;
86 private String _mimeType; 85 private String _mimeType;
87 private CachedBuffer _cachedMimeType; 86 private String _cachedMimeType;
88 private String _characterEncoding; 87 private String _characterEncoding;
89 private boolean _explicitEncoding; 88 private boolean _explicitEncoding;
90 private String _contentType; 89 private String _contentType;
91 private volatile int _outputState; 90 private volatile int _outputState;
92 private PrintWriter _writer; 91 private PrintWriter _writer;
479 // Clear any encoding. 478 // Clear any encoding.
480 if (_characterEncoding!=null) 479 if (_characterEncoding!=null)
481 { 480 {
482 _characterEncoding=null; 481 _characterEncoding=null;
483 if (_cachedMimeType!=null) 482 if (_cachedMimeType!=null)
484 _contentType = _cachedMimeType.toString(); 483 _contentType = _cachedMimeType;
485 else if (_mimeType!=null) 484 else if (_mimeType!=null)
486 _contentType = _mimeType; 485 _contentType = _mimeType;
487 else 486 else
488 _contentType = null; 487 _contentType = null;
489 488
503 if (i0<0) 502 if (i0<0)
504 { 503 {
505 _contentType=null; 504 _contentType=null;
506 if(_cachedMimeType!=null) 505 if(_cachedMimeType!=null)
507 { 506 {
508 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); 507 String content_type = MimeTypes.getAssociate(_cachedMimeType,_characterEncoding);
509 if (content_type!=null) 508 if (content_type!=null)
510 { 509 {
511 _contentType = content_type.toString(); 510 _contentType = content_type;
512 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); 511 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType);
513 } 512 }
514 } 513 }
515 514
516 if (_contentType==null) 515 if (_contentType==null)
618 // strip the charset and ignore; 617 // strip the charset and ignore;
619 if ((i1==i0+1 && i2<0) || (i1==i0+2 && i2<0 && contentType.charAt(i0+1)==' ')) 618 if ((i1==i0+1 && i2<0) || (i1==i0+2 && i2<0 && contentType.charAt(i0+1)==' '))
620 { 619 {
621 if (_cachedMimeType!=null) 620 if (_cachedMimeType!=null)
622 { 621 {
623 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); 622 String content_type = MimeTypes.getAssociate(_cachedMimeType,_characterEncoding);
624 if (content_type!=null) 623 if (content_type!=null)
625 { 624 {
626 _contentType=content_type.toString(); 625 _contentType=content_type;
627 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); 626 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType);
628 } 627 }
629 else 628 else
630 { 629 {
631 _contentType = _mimeType+";charset="+_characterEncoding; 630 _contentType = _mimeType+";charset="+_characterEncoding;
655 _cachedMimeType = MimeTypes.CACHE.get(_mimeType); 654 _cachedMimeType = MimeTypes.CACHE.get(_mimeType);
656 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8)); 655 _characterEncoding = QuotedStringTokenizer.unquote(contentType.substring(i8));
657 656
658 if (_cachedMimeType!=null) 657 if (_cachedMimeType!=null)
659 { 658 {
660 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); 659 String content_type = MimeTypes.getAssociate(_cachedMimeType,_characterEncoding);
661 if (content_type!=null) 660 if (content_type!=null)
662 { 661 {
663 _contentType=content_type.toString(); 662 _contentType=content_type;
664 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); 663 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType);
665 } 664 }
666 else 665 else
667 { 666 {
668 _contentType=contentType; 667 _contentType=contentType;
702 701
703 if (_characterEncoding!=null) 702 if (_characterEncoding!=null)
704 { 703 {
705 if (_cachedMimeType!=null) 704 if (_cachedMimeType!=null)
706 { 705 {
707 CachedBuffer content_type = _cachedMimeType.getAssociate(_characterEncoding); 706 String content_type = MimeTypes.getAssociate(_cachedMimeType,_characterEncoding);
708 if (content_type!=null) 707 if (content_type!=null)
709 { 708 {
710 _contentType=content_type.toString(); 709 _contentType=content_type;
711 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType); 710 _connection._responseFields.put(HttpHeaders.CONTENT_TYPE,_contentType);
712 } 711 }
713 else 712 else
714 { 713 {
715 _contentType = _mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= "); 714 _contentType = _mimeType+";charset="+QuotedStringTokenizer.quoteIfNeeded(_characterEncoding,";= ");