ForwardedHeaderExtractingRequest(HttpServletRequest request, UrlPathHelper pathHelper) { super(request); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); int port = uriComponents.getPort(); this.scheme = uriComponents.getScheme(); this.secure = "https".equals(this.scheme); this.host = uriComponents.getHost(); this.port = (port == -1 ? (this.secure ? 443 : 80) : port); String baseUrl = this.scheme + "://" + this.host + (port == -1 ? "" : ":" + port); Supplier<HttpServletRequest> delegateRequest = () -> (HttpServletRequest) getRequest(); this.forwardedPrefixExtractor = new ForwardedPrefixExtractor(delegateRequest, pathHelper, baseUrl); }
/** * Constructor with required information. * @param delegateRequest supplier for the current * {@link HttpServletRequestWrapper#getRequest() delegate request} which * may change during a forward (e.g. Tomcat. * @param pathHelper the path helper instance * @param baseUrl the host, scheme, and port based on forwarded headers */ public ForwardedPrefixExtractor( Supplier<HttpServletRequest> delegateRequest, UrlPathHelper pathHelper, String baseUrl) { this.delegate = delegateRequest; this.pathHelper = pathHelper; this.baseUrl = baseUrl; this.actualRequestUri = delegateRequest.get().getRequestURI(); this.forwardedPrefix = initForwardedPrefix(delegateRequest.get()); this.requestUri = initRequestUri(); this.requestUrl = initRequestUrl(); // Keep the order: depends on requestUri }
public StringBuffer getRequestUrl() { recalculatePathsIfNecessary(); return new StringBuffer(this.requestUrl); }
/** * Constructor with required information. * @param delegateRequest supplier for the current * {@link HttpServletRequestWrapper#getRequest() delegate request} which * may change during a forward (e.g. Tomcat. * @param pathHelper the path helper instance * @param baseUrl the host, scheme, and port based on forwarded headers */ public ForwardedPrefixExtractor( Supplier<HttpServletRequest> delegateRequest, UrlPathHelper pathHelper, String baseUrl) { this.delegate = delegateRequest; this.pathHelper = pathHelper; this.baseUrl = baseUrl; this.actualRequestUri = delegateRequest.get().getRequestURI(); this.forwardedPrefix = initForwardedPrefix(delegateRequest.get()); this.requestUri = initRequestUri(); this.requestUrl = initRequestUrl(); // Keep the order: depends on requestUri }
public ForwardedHeaderExtractingRequest(HttpServletRequest request, UrlPathHelper pathHelper) { super(request); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); int port = uriComponents.getPort(); this.scheme = uriComponents.getScheme(); this.secure = "https".equals(scheme); this.host = uriComponents.getHost(); this.port = (port == -1 ? (this.secure ? 443 : 80) : port); String prefix = getForwardedPrefix(request); this.contextPath = (prefix != null ? prefix : request.getContextPath()); this.requestUri = this.contextPath + pathHelper.getPathWithinApplication(request); this.requestUrl = this.scheme + "://" + this.host + (port == -1 ? "" : ":" + port) + this.requestUri; }
@Override public String getContextPath() { return this.forwardedPrefixExtractor.getContextPath(); }
public StringBuffer getRequestUrl() { recalculatePathsIfNecessary(); return new StringBuffer(this.requestUrl); }
public String getRequestUri() { if (this.requestUri == null) { return this.delegate.get().getRequestURI(); } recalculatePathsIfNecessary(); return this.requestUri; }
@Override public String getRequestURI() { return this.forwardedPrefixExtractor.getRequestUri(); }
ForwardedHeaderExtractingRequest(HttpServletRequest request, UrlPathHelper pathHelper) { super(request); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); int port = uriComponents.getPort(); this.scheme = uriComponents.getScheme(); this.secure = "https".equals(this.scheme); this.host = uriComponents.getHost(); this.port = (port == -1 ? (this.secure ? 443 : 80) : port); String baseUrl = this.scheme + "://" + this.host + (port == -1 ? "" : ":" + port); Supplier<HttpServletRequest> delegateRequest = () -> (HttpServletRequest) getRequest(); this.forwardedPrefixExtractor = new ForwardedPrefixExtractor(delegateRequest, pathHelper, baseUrl); }
@Override public StringBuffer getRequestURL() { return this.forwardedPrefixExtractor.getRequestUrl(); } }
private void recalculatePathsIfNecessary() { if (!this.actualRequestUri.equals(this.delegate.get().getRequestURI())) { // Underlying path change (e.g. Servlet FORWARD). this.actualRequestUri = this.delegate.get().getRequestURI(); this.requestUri = initRequestUri(); this.requestUrl = initRequestUrl(); // Keep the order: depends on requestUri } } }
@Override public String getContextPath() { return this.forwardedPrefixExtractor.getContextPath(); }
ForwardedHeaderExtractingRequest(HttpServletRequest request, UrlPathHelper pathHelper) { super(request); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); int port = uriComponents.getPort(); this.scheme = uriComponents.getScheme(); this.secure = "https".equals(this.scheme); this.host = uriComponents.getHost(); this.port = (port == -1 ? (this.secure ? 443 : 80) : port); String baseUrl = this.scheme + "://" + this.host + (port == -1 ? "" : ":" + port); Supplier<HttpServletRequest> delegateRequest = () -> (HttpServletRequest) getRequest(); this.forwardedPrefixExtractor = new ForwardedPrefixExtractor(delegateRequest, pathHelper, baseUrl); }
@Override public StringBuffer getRequestURL() { return this.forwardedPrefixExtractor.getRequestUrl(); } }
@Override public String getRequestURI() { return this.forwardedPrefixExtractor.getRequestUri(); }
public String getRequestUri() { if (this.requestUri == null) { return this.delegate.get().getRequestURI(); } recalculatePathsIfNecessary(); return this.requestUri; }
private void recalculatePathsIfNecessary() { if (!this.actualRequestUri.equals(this.delegate.get().getRequestURI())) { // Underlying path change (e.g. Servlet FORWARD). this.actualRequestUri = this.delegate.get().getRequestURI(); this.requestUri = initRequestUri(); this.requestUrl = initRequestUrl(); // Keep the order: depends on requestUri } } }
/** * Constructor with required information. * @param delegateRequest supplier for the current * {@link HttpServletRequestWrapper#getRequest() delegate request} which * may change during a forward (e.g. Tomcat. * @param pathHelper the path helper instance * @param baseUrl the host, scheme, and port based on forwarded headers */ public ForwardedPrefixExtractor( Supplier<HttpServletRequest> delegateRequest, UrlPathHelper pathHelper, String baseUrl) { this.delegate = delegateRequest; this.pathHelper = pathHelper; this.baseUrl = baseUrl; this.actualRequestUri = delegateRequest.get().getRequestURI(); this.forwardedPrefix = initForwardedPrefix(delegateRequest.get()); this.requestUri = initRequestUri(); this.requestUrl = initRequestUrl(); // Keep the order: depends on requestUri }
@Override public String getContextPath() { return this.forwardedPrefixExtractor.getContextPath(); }