private static String getXForwardedForHeader(RestRequest request) {
   if (!ConfigurationHelper.isNullOrEmpty(request.header("X-Forwarded-For"))) {
     String[] parts = request.header("X-Forwarded-For").split(",");
     if (!ConfigurationHelper.isNullOrEmpty(parts[0])) {
       return parts[0];
     }
   }
   return null;
 }
  public ACLRequest(RestRequest request, RestChannel channel) {
    this(
        request.uri(),
        getAddress(channel),
        request.header("X-Api-Key"),
        request.header("Auth"),
        request.content().length(),
        request.method(),
        getXForwardedForHeader(request));

    ESLogger logger = ESLoggerFactory.getLogger(ACLRequest.class.getName());
    logger.debug("Headers:\n");
    for (Map.Entry<String, String> header : request.headers()) {
      logger.debug(header.getKey() + "=" + header.getValue());
    }
  }
 protected AbstractRestChannel(RestRequest request, boolean detailedErrorsEnabled) {
   this.request = request;
   this.detailedErrorsEnabled = detailedErrorsEnabled;
   this.format = request.param("format", request.header("Accept"));
   this.filterPath = request.param("filter_path", null);
   this.pretty = request.paramAsBoolean("pretty", false);
   this.human = request.paramAsBoolean("human", false);
 }
 public static RestResponse buildResponse(Table table, RestRequest request, RestChannel channel)
     throws Exception {
   XContentType xContentType =
       XContentType.fromRestContentType(request.param("format", request.header("Content-Type")));
   if (xContentType != null) {
     return buildXContentBuilder(table, request, channel);
   }
   return buildTextPlainResponse(table, request, channel);
 }
 public static RestResponse buildResponse(Table table, RestChannel channel) throws Exception {
   RestRequest request = channel.request();
   XContentType xContentType =
       XContentType.fromMediaTypeOrFormat(request.param("format", request.header("Accept")));
   if (xContentType != null) {
     return buildXContentBuilder(table, channel);
   }
   return buildTextPlainResponse(table, channel);
 }
 private static void copyHeadersAndContext(
     ActionRequest actionRequest, RestRequest restRequest, Set<String> headers) {
   for (String usefulHeader : headers) {
     String headerValue = restRequest.header(usefulHeader);
     if (headerValue != null) {
       actionRequest.putHeader(usefulHeader, headerValue);
     }
   }
   actionRequest.copyContextFrom(restRequest);
 }
 @Override
 public void handleRequest(RestRequest request, RestChannel channel, Client client) {
   if ("password".equals(request.header("Secret"))) {
     RestResponse response = new BytesRestResponse(RestStatus.OK, "Access granted");
     response.addHeader("Secret", "granted");
     channel.sendResponse(response);
   } else {
     RestResponse response = new BytesRestResponse(RestStatus.UNAUTHORIZED, "Access denied");
     response.addHeader("Secret", "required");
     channel.sendResponse(response);
   }
 }