@Override
    public void setResponseWriter(ResponseWriter writer) {

        boolean alreadyWrapped = false;

        ResponseWriter wrappedWriter = writer;
        while (wrappedWriter != null) {
            if (wrappedWriter instanceof ResponseWriterWrapper) {
                if (wrappedWriter instanceof MoveScriptsToBottomResponseWriter
                        || wrappedWriter instanceof CspResponseWriter) {
                    alreadyWrapped = true;
                    break;
                }
                wrappedWriter = ((ResponseWriterWrapper) wrappedWriter).getWrapped();
            }
            else {
                break;
            }
        }

        if (!alreadyWrapped) {
            if (csp && !getPartialViewContext().isAjaxRequest()) {
                writer = new CspResponseWriter(writer, cspState);
            }

            if (moveScriptsToBottom && !getPartialViewContext().isAjaxRequest()) {
                writer = new MoveScriptsToBottomResponseWriter(writer, moveScriptsToBottomState);
            }
        }

        getWrapped().setResponseWriter(writer);
    }
Custom {@link FacesContextWrapper} to init and release our {@link PrimeRequestContext}.
primefaces/src/main/java/org/primefaces/context/PrimeFacesContext.java