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 ) ; } }
Return the URL as it was originally received from a possible frontend proxy .