test_class.declarator: filter = new ProxyFilter()
test_class.modifier: private final
test_class.original_string: private final ProxyFilter filter = new ProxyFilter();
test_class.type: ProxyFilter
test_class.var_name: filter
test_class.declarator: context
test_class.modifier: private @Mock
test_class.original_string: private @Mock ContainerRequestContext context;
test_class.type: ContainerRequestContext
test_class.var_name: context
test_class.declarator: uriInfo
test_class.modifier: private @Mock
test_class.original_string: private @Mock UriInfo uriInfo;
test_class.type: UriInfo
test_class.var_name: uriInfo
test_class.file: bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/internal/filter/ProxyFilterTest.java
test_class.identifier: ProxyFilterTest
test_case.body: @Test
      public void onlyHostTest() throws Exception {
          String baseURI = "http://localhost/rest";
          String requestURI = "http://localhost/rest/test";
          setupContextURIs(baseURI, requestURI);
  
          setupContextHeaders(null, "eclipse.org:8081");
  
          filter.filter(context);
  
          URI newBaseURI = new URI("http://eclipse.org:8081/rest");
          URI newRequestURI = new URI("http://eclipse.org:8081/rest/test");
          verify(context).setRequestUri(eq(newBaseURI), eq(newRequestURI));
      }
test_case.class_method_signature: ProxyFilterTest.onlyHostTest()
test_case.full_signature: @Test public void onlyHostTest()
test_case.identifier: onlyHostTest
test_case.invocations: setupContextURIs setupContextHeaders filter setRequestUri verify eq eq
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void onlyHostTest()
focal_class.declarator: PROTO_PROXY_HEADER = "x-forwarded-proto"
focal_class.modifier: static final
focal_class.original_string: static final String PROTO_PROXY_HEADER = "x-forwarded-proto";
focal_class.type: String
focal_class.var_name: PROTO_PROXY_HEADER
focal_class.declarator: HOST_PROXY_HEADER = "x-forwarded-host"
focal_class.modifier: static final
focal_class.original_string: static final String HOST_PROXY_HEADER = "x-forwarded-host";
focal_class.type: String
focal_class.var_name: HOST_PROXY_HEADER
focal_class.declarator: logger = LoggerFactory.getLogger(ProxyFilter.class)
focal_class.modifier: private final transient
focal_class.original_string: private final transient Logger logger = LoggerFactory.getLogger(ProxyFilter.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.file: bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/ProxyFilter.java
focal_class.identifier: ProxyFilter
focal_class.interfaces: implements ContainerRequestFilter
focal_class.class_method_signature: ProxyFilter.filter(ContainerRequestContext ctx)
focal_class.full_signature: @Override public void filter(ContainerRequestContext ctx)
focal_class.identifier: filter
focal_class.modifiers: @Override public
focal_class.parameters: (ContainerRequestContext ctx)
focal_class.return: void
focal_class.signature: void filter(ContainerRequestContext ctx)
focal_class.class_method_signature: ProxyFilter.getValue(MultivaluedMap<String, String> headers, String header)
focal_class.full_signature: private String getValue(MultivaluedMap<String, String> headers, String header)
focal_class.identifier: getValue
focal_class.modifiers: private
focal_class.parameters: (MultivaluedMap<String, String> headers, String header)
focal_class.return: String
focal_class.signature: String getValue(MultivaluedMap<String, String> headers, String header)
focal_method.body: @Override
      public void filter(ContainerRequestContext ctx) throws IOException {
          String host = getValue(ctx.getHeaders(), HOST_PROXY_HEADER);
          String scheme = getValue(ctx.getHeaders(), PROTO_PROXY_HEADER);
  
          // if our request does not have neither headers end right here
          if (scheme == null && host == null) {
              return;
          }
  
          UriInfo uriInfo = ctx.getUriInfo();
          URI requestUri = uriInfo.getRequestUri();
  
          UriBuilder baseBuilder = uriInfo.getBaseUriBuilder();
          UriBuilder requestBuilder = uriInfo.getRequestUriBuilder();
  
          // if only one of our headers is missing replace it with default value
          if (scheme == null) {
              scheme = requestUri.getScheme();
          }
  
          if (host == null) {
              host = requestUri.getHost();
  
              int port = requestUri.getPort();
              if (port != -1) {
                  host += (":" + port);
              }
          }
  
          // create a new URI from the current scheme + host in order to validate
          // it
          String uriString = scheme + "://" + host;
  
          URI newBaseUri = null;
          try {
              newBaseUri = new URI(uriString);
          } catch (URISyntaxException e) {
              logger.error("Invalid X-Forwarded-Proto + X-Forwarded-Host header combination: {}", uriString, e);
              return;
          }
  
          // URI is valid replace base and request builder parts with ones
          // obtained from the given headers
          host = newBaseUri.getHost();
          if (host != null) {
              baseBuilder.host(host);
              requestBuilder.host(host);
          }
  
          int port = newBaseUri.getPort();
          baseBuilder.port(port);
          requestBuilder.port(port);
  
          scheme = newBaseUri.getScheme();
          if (scheme != null) {
              baseBuilder.scheme(scheme);
              requestBuilder.scheme(scheme);
          }
  
          ctx.setRequestUri(baseBuilder.build(), requestBuilder.build());
      }
focal_method.class_method_signature: ProxyFilter.filter(ContainerRequestContext ctx)
focal_method.full_signature: @Override public void filter(ContainerRequestContext ctx)
focal_method.identifier: filter
focal_method.invocations: getValue getHeaders getValue getHeaders getUriInfo getRequestUri getBaseUriBuilder getRequestUriBuilder getScheme getHost getPort error getHost host host getPort port port getScheme scheme scheme setRequestUri build build
focal_method.modifiers: @Override public
focal_method.parameters: (ContainerRequestContext ctx)
focal_method.return: void
focal_method.signature: void filter(ContainerRequestContext ctx)