public void setContentType()

in src/main/java/org/apache/sling/engine/impl/SlingHttpServletResponseImpl.java [278:303]


    public void setContentType(final String type) {
        if ( this.requestData.getDispatchingInfo() != null && this.requestData.getDispatchingInfo().isCheckContentTypeOnInclude() ) {
            String contentTypeString = getContentType();
            if (contentTypeString != null) {
                if (type == null) {
                    String message = getMessage(contentTypeString, "null");
                    requestData.getRequestProgressTracker().log("ERROR: " + message);
                    throw new ContentTypeChangeException(message);
                }
                Optional<String> currentMime = Arrays.stream(contentTypeString.split(";")).findFirst();
                Optional<String> setMime = Arrays.stream(type.split(";")).findFirst();
                if (currentMime.isPresent() && setMime.isPresent() && !currentMime.get().equals(setMime.get())) {
                    String message = getMessage(contentTypeString, type);
                    requestData.getRequestProgressTracker().log("ERROR: " + message);
                    throw new ContentTypeChangeException(message);
                }
                if (!this.isProtectHeadersOnInclude()) {
                    getResponse().setContentType(type);
                }
            }
            return;
        }
        if (!this.isProtectHeadersOnInclude()) {
            super.setContentType(type);
        }
    }