code: private URI getOriginalUri(HttpServletRequest request) {
      String requestUrl = request.getRequestURL().toString();
      String incomingScheme = URI.create(requestUrl).getScheme();
      String originalScheme = request.getHeader("X-Forwarded-Proto");
      if (originalScheme != null && !incomingScheme.equals(originalScheme)) {
        return URI.create(requestUrl.replaceFirst("^" + incomingScheme, originalScheme));
      } else {
        return URI.create(requestUrl);
      }
    }
docs: Return the URL as it was originally received from a possible frontend proxy.
  
  @param request Incoming request
  @return URL as it was received at the frontend proxy