### Question:
ApacheProxyAddressStrategy extends IncomingRequestAddressStrategy { @Override public String determineServerBase(ServletContext servletContext, HttpServletRequest request) { String serverBase = super.determineServerBase(servletContext, request); ServletServerHttpRequest requestWrapper = new ServletServerHttpRequest( request); HttpHeaders headers = requestWrapper.getHeaders(); Optional<String> forwardedHost = headers .getValuesAsList(X_FORWARDED_HOST).stream().findFirst(); return forwardedHost .map(s -> forwardedServerBase(serverBase, headers, s)) .orElse(serverBase); } ApacheProxyAddressStrategy(boolean useHttps); @Override String determineServerBase(ServletContext servletContext,
			HttpServletRequest request); static ApacheProxyAddressStrategy forHttp(); static ApacheProxyAddressStrategy forHttps();  }### Answer:
@Test public void testWithoutForwarded() { ApacheProxyAddressStrategy addressStrategy = new ApacheProxyAddressStrategy( true); MockHttpServletRequest request = prepareRequest(); String serverBase = addressStrategy.determineServerBase(null, request); assertEquals("https: }
@Test public void testWithForwardedHostWithoutForwardedProtoHttps() { ApacheProxyAddressStrategy addressStrategy = new ApacheProxyAddressStrategy( true); MockHttpServletRequest request = prepareRequest(); request.addHeader("X-Forwarded-Host", "my.example.host"); String serverBase = addressStrategy.determineServerBase(null, request); assertEquals("https: }
@Test public void testWithForwardedHostWithoutForwardedProtoHttp() { ApacheProxyAddressStrategy addressStrategy = new ApacheProxyAddressStrategy( false); MockHttpServletRequest request = prepareRequest(); request.addHeader("X-Forwarded-Host", "my.example.host"); String serverBase = addressStrategy.determineServerBase(null, request); assertEquals("http: }
@Test public void testWithForwarded() { ApacheProxyAddressStrategy addressStrategy = new ApacheProxyAddressStrategy( true); MockHttpServletRequest request = prepareRequest(); request.addHeader("X-Forwarded-Host", "my.example.host"); request.addHeader("X-Forwarded-Proto", "https"); request.addHeader("X-Forwarded-Prefix", "server-prefix/fhir"); String serverBase = addressStrategy.determineServerBase(null, request); assertEquals("https: }
@Test public void testWithForwardedWithHostPrefixWithSlash() { ApacheProxyAddressStrategy addressStrategy = new ApacheProxyAddressStrategy( true); MockHttpServletRequest request = prepareRequest(); request.addHeader("host", "localhost"); request.addHeader("X-Forwarded-Host", "my.example.host"); request.addHeader("X-Forwarded-Proto", "https"); request.addHeader("X-Forwarded-Prefix", "/server-prefix/fhir"); String serverBase = addressStrategy.determineServerBase(null, request); assertEquals("https: }
@Test public void testWithForwardedWithoutPrefix() { ApacheProxyAddressStrategy addressStrategy = new ApacheProxyAddressStrategy( true); MockHttpServletRequest request = prepareRequest(); request.addHeader("X-Forwarded-Host", "my.example.host"); request.addHeader("X-Forwarded-Proto", "https"); String serverBase = addressStrategy.determineServerBase(null, request); assertEquals("https: }
@Test public void testWithForwardedHostAndPort() { ApacheProxyAddressStrategy addressStrategy = new ApacheProxyAddressStrategy( true); MockHttpServletRequest request = prepareRequest(); request.addHeader("X-Forwarded-Host", "my.example.host"); request.addHeader("X-Forwarded-Port", "345"); String serverBase = addressStrategy.determineServerBase(null, request); assertEquals("https: serverBase); }