示例#1
0
  private HttpResponse sendRequest(HttpRequest httpRequest) {
    // if HttpRequest was set to null by a filter don't send request
    if (httpRequest != null) {
      String hostHeader = httpRequest.getFirstHeader("Host");
      if (!Strings.isNullOrEmpty(hostHeader)) {
        String[] hostHeaderParts = hostHeader.split(":");

        boolean isSsl = httpRequest.isSecure() != null && httpRequest.isSecure();
        Integer port = (isSsl ? 443 : 80); // default
        if (hostHeaderParts.length > 1) {
          port = Integer.parseInt(hostHeaderParts[1]); // non-default
        }
        HttpResponse httpResponse =
            filters.applyOnResponseFilters(
                httpRequest,
                httpClient.sendRequest(outboundRequest(hostHeaderParts[0], port, "", httpRequest)));
        if (httpResponse != null) {
          return httpResponse;
        }
      } else {
        logger.error(
            "Host header must be provided for requests being forwarded, the following request does not include the \"Host\" header:"
                + System.getProperty("line.separator")
                + httpRequest);
        throw new IllegalArgumentException(
            "Host header must be provided for requests being forwarded");
      }
    }
    return notFoundResponse();
  }