(String type)
| 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 |
no test coverage detected