MCPcopy Create free account
hub / github.com/apache/tomcat / setContentType

Method setContentType

java/org/apache/catalina/connector/Response.java:639–689  ·  view source on GitHub ↗
(String type)

Source from the content-addressed store, hash-verified

637
638
639 @Override
640 public void setContentType(String type) {
641
642 if (isCommitted()) {
643 return;
644 }
645
646 // Ignore any call from an included servlet
647 if (included) {
648 return;
649 }
650
651 if (type == null) {
652 getCoyoteResponse().setContentType(null);
653 getCoyoteResponse().setCharsetHolder(CharsetHolder.EMPTY);
654 isCharacterEncodingSet = false;
655 return;
656 }
657
658 String[] m = MEDIA_TYPE_CACHE.parse(type);
659 if (m == null) {
660 // Invalid - Assume no charset and just pass through whatever
661 // the user provided.
662 getCoyoteResponse().setContentTypeNoCharset(type);
663 return;
664 }
665
666
667 if (m[1] == null) {
668 // No charset and we know value is valid as cache lookup was
669 // successful
670 // Pass-through user provided value in case user-agent is buggy and
671 // requires specific format
672 getCoyoteResponse().setContentTypeNoCharset(type);
673 } else {
674 // There is a charset so have to rebuild content-type without it
675 getCoyoteResponse().setContentTypeNoCharset(m[0]);
676
677 // Ignore charset if getWriter() has already been called
678 if (!usingWriter) {
679 getCoyoteResponse().setCharsetHolder(CharsetHolder.getInstance(m[1]));
680 try {
681 getCoyoteResponse().getCharsetHolder().validate();
682 } catch (UnsupportedEncodingException e) {
683 log.warn(sm.getString("coyoteResponse.encoding.invalid", m[1]), e);
684 }
685
686 isCharacterEncodingSet = true;
687 }
688 }
689 }
690
691
692 @Override

Callers 1

checkSpecialHeaderMethod · 0.95

Calls 11

isCommittedMethod · 0.95
getCoyoteResponseMethod · 0.95
getInstanceMethod · 0.95
setContentTypeMethod · 0.65
validateMethod · 0.65
warnMethod · 0.65
getStringMethod · 0.65
setCharsetHolderMethod · 0.45
parseMethod · 0.45
getCharsetHolderMethod · 0.45

Tested by

no test coverage detected