@Test public void shouldBuildCorrectlyForLocalAccessWithHttp() { prepareConfig(false, false, "/"); prepareHeaders("127.0.0.1:5076", null, null, null); prepareServlet("http: UriComponentsBuilder builder = testee.buildLocalBaseUriBuilder(requestMock); assertThat(builder.build().getScheme()).isEqualTo("http"); assertThat(builder.build().getHost()).isEqualTo("127.0.0.1"); assertThat(builder.build().getPort()).isEqualTo(5076); assertThat(builder.build().getPath()).isEqualTo("/"); }
protected UriComponentsBuilder buildLocalBaseUriBuilder(HttpServletRequest request) { String scheme; String host; int port = -1; String path; if (request.isSecure()) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTPS because request is deemed secure"); scheme = "https"; } else if (Boolean.parseBoolean(environment.getProperty("server.ssl.enabled"))) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTPS because header x-forwarded-proto is not set and built-in SSL is enabled"); scheme = "https"; } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTP because header x-forwarded-proto is not set and built-in SSL is disabled"); scheme = "http"; } String hostHeader = request.getHeader("host"); if (hostHeader == null) { host = request.getServerName(); logger.warn("Header host not set. Using {}. Please change your reverse proxy configuration. See https: } else { String[] split = hostHeader.split(":"); host = split[0]; if (split.length > 1) { port = Integer.parseInt(split[1]); logger.debug(LoggingMarkers.URL_CALCULATION, "Using host {} and port {} from host header {}", host, port, hostHeader); } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Using host {} from host header", hostHeader); } } if (port == -1) { port = request.getServerPort(); logger.debug(LoggingMarkers.URL_CALCULATION, "Using port {} ", port); } path = request.getContextPath(); if (!Strings.isNullOrEmpty(path)) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using context path {} as path", path); } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Not using any context path"); } return UriComponentsBuilder.newInstance() .scheme(scheme) .host(host) .port(port) .path(path); }
UrlCalculator { protected UriComponentsBuilder buildLocalBaseUriBuilder(HttpServletRequest request) { String scheme; String host; int port = -1; String path; if (request.isSecure()) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTPS because request is deemed secure"); scheme = "https"; } else if (Boolean.parseBoolean(environment.getProperty("server.ssl.enabled"))) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTPS because header x-forwarded-proto is not set and built-in SSL is enabled"); scheme = "https"; } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTP because header x-forwarded-proto is not set and built-in SSL is disabled"); scheme = "http"; } String hostHeader = request.getHeader("host"); if (hostHeader == null) { host = request.getServerName(); logger.warn("Header host not set. Using {}. Please change your reverse proxy configuration. See https: } else { String[] split = hostHeader.split(":"); host = split[0]; if (split.length > 1) { port = Integer.parseInt(split[1]); logger.debug(LoggingMarkers.URL_CALCULATION, "Using host {} and port {} from host header {}", host, port, hostHeader); } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Using host {} from host header", hostHeader); } } if (port == -1) { port = request.getServerPort(); logger.debug(LoggingMarkers.URL_CALCULATION, "Using port {} ", port); } path = request.getContextPath(); if (!Strings.isNullOrEmpty(path)) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using context path {} as path", path); } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Not using any context path"); } return UriComponentsBuilder.newInstance() .scheme(scheme) .host(host) .port(port) .path(path); } }
UrlCalculator { protected UriComponentsBuilder buildLocalBaseUriBuilder(HttpServletRequest request) { String scheme; String host; int port = -1; String path; if (request.isSecure()) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTPS because request is deemed secure"); scheme = "https"; } else if (Boolean.parseBoolean(environment.getProperty("server.ssl.enabled"))) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTPS because header x-forwarded-proto is not set and built-in SSL is enabled"); scheme = "https"; } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTP because header x-forwarded-proto is not set and built-in SSL is disabled"); scheme = "http"; } String hostHeader = request.getHeader("host"); if (hostHeader == null) { host = request.getServerName(); logger.warn("Header host not set. Using {}. Please change your reverse proxy configuration. See https: } else { String[] split = hostHeader.split(":"); host = split[0]; if (split.length > 1) { port = Integer.parseInt(split[1]); logger.debug(LoggingMarkers.URL_CALCULATION, "Using host {} and port {} from host header {}", host, port, hostHeader); } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Using host {} from host header", hostHeader); } } if (port == -1) { port = request.getServerPort(); logger.debug(LoggingMarkers.URL_CALCULATION, "Using port {} ", port); } path = request.getContextPath(); if (!Strings.isNullOrEmpty(path)) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using context path {} as path", path); } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Not using any context path"); } return UriComponentsBuilder.newInstance() .scheme(scheme) .host(host) .port(port) .path(path); }  }
UrlCalculator { protected UriComponentsBuilder buildLocalBaseUriBuilder(HttpServletRequest request) { String scheme; String host; int port = -1; String path; if (request.isSecure()) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTPS because request is deemed secure"); scheme = "https"; } else if (Boolean.parseBoolean(environment.getProperty("server.ssl.enabled"))) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTPS because header x-forwarded-proto is not set and built-in SSL is enabled"); scheme = "https"; } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTP because header x-forwarded-proto is not set and built-in SSL is disabled"); scheme = "http"; } String hostHeader = request.getHeader("host"); if (hostHeader == null) { host = request.getServerName(); logger.warn("Header host not set. Using {}. Please change your reverse proxy configuration. See https: } else { String[] split = hostHeader.split(":"); host = split[0]; if (split.length > 1) { port = Integer.parseInt(split[1]); logger.debug(LoggingMarkers.URL_CALCULATION, "Using host {} and port {} from host header {}", host, port, hostHeader); } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Using host {} from host header", hostHeader); } } if (port == -1) { port = request.getServerPort(); logger.debug(LoggingMarkers.URL_CALCULATION, "Using port {} ", port); } path = request.getContextPath(); if (!Strings.isNullOrEmpty(path)) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using context path {} as path", path); } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Not using any context path"); } return UriComponentsBuilder.newInstance() .scheme(scheme) .host(host) .port(port) .path(path); }  UriComponentsBuilder getRequestBasedUriBuilder(); @JsonIgnore UriComponentsBuilder getLocalBaseUriBuilder(); }
UrlCalculator { protected UriComponentsBuilder buildLocalBaseUriBuilder(HttpServletRequest request) { String scheme; String host; int port = -1; String path; if (request.isSecure()) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTPS because request is deemed secure"); scheme = "https"; } else if (Boolean.parseBoolean(environment.getProperty("server.ssl.enabled"))) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTPS because header x-forwarded-proto is not set and built-in SSL is enabled"); scheme = "https"; } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Using scheme HTTP because header x-forwarded-proto is not set and built-in SSL is disabled"); scheme = "http"; } String hostHeader = request.getHeader("host"); if (hostHeader == null) { host = request.getServerName(); logger.warn("Header host not set. Using {}. Please change your reverse proxy configuration. See https: } else { String[] split = hostHeader.split(":"); host = split[0]; if (split.length > 1) { port = Integer.parseInt(split[1]); logger.debug(LoggingMarkers.URL_CALCULATION, "Using host {} and port {} from host header {}", host, port, hostHeader); } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Using host {} from host header", hostHeader); } } if (port == -1) { port = request.getServerPort(); logger.debug(LoggingMarkers.URL_CALCULATION, "Using port {} ", port); } path = request.getContextPath(); if (!Strings.isNullOrEmpty(path)) { logger.debug(LoggingMarkers.URL_CALCULATION, "Using context path {} as path", path); } else { logger.debug(LoggingMarkers.URL_CALCULATION, "Not using any context path"); } return UriComponentsBuilder.newInstance() .scheme(scheme) .host(host) .port(port) .path(path); }  UriComponentsBuilder getRequestBasedUriBuilder(); @JsonIgnore UriComponentsBuilder getLocalBaseUriBuilder();  }