private static HttpClient buildHttpClient(URI savedRequest, ServletContext servletContext,
            HttpServletRequest originalRequest) {
        CookieManager cookieManager = new CookieManager();
        var session = SecurityUtils.getSubject().getSession();
        var sessionCookieName = getSessionCookieName(servletContext, getSecurityManager());
        var sessionCookie = new HttpCookie(sessionCookieName, session.getId().toString());
        sessionCookie.setPath(servletContext.getContextPath());
        sessionCookie.setVersion(0);
        cookieManager.getCookieStore().add(savedRequest, sessionCookie);
        log.debug("Setting Cookie {}", sessionCookieName);
        for (Cookie origCookie : originalRequest.getCookies()) {
            if (!origCookie.getName().equals(sessionCookieName)) {
                try {
                    log.debug("Setting Cookie {}", origCookie.getName());
                    HttpCookie cookie = new HttpCookie(origCookie.getName(), origCookie.getValue());
                    cookie.setPath(servletContext.getContextPath());
                    cookie.setVersion(0);
                    cookieManager.getCookieStore().add(savedRequest, cookie);
                } catch (IllegalArgumentException e) {
                    log.warn("Form Resubmit: Ignoring invalid cookie [{} - {}]",
                            origCookie.getName(), origCookie.getValue(), e);
                }
            }
        }
        return HttpClient.newBuilder().cookieHandler(cookieManager).build();
    }
flash cookie is preserved here

@param request
@param response
@param path
@param paramValues
support/jakarta-ee/src/main/java/org/apache/shiro/ee/filters/FormResubmitSupport.java