/*
 * Licensed to Elasticsearch under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.elasticsearch.client;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.RequestLine;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;

import java.io.Closeable;
import java.io.IOException;
import java.util.Objects;

/**
 * Holds an elasticsearch response. It wraps the {@link CloseableHttpResponse} response and associates it with
 * its corresponding {@link RequestLine} and {@link HttpHost}
 */
public class ElasticsearchResponse implements Closeable {

    private final RequestLine requestLine;
    private final HttpHost host;
    private final CloseableHttpResponse response;

    ElasticsearchResponse(RequestLine requestLine, HttpHost host, CloseableHttpResponse response) {
        Objects.requireNonNull(requestLine, "requestLine cannot be null");
        Objects.requireNonNull(host, "node cannot be null");
        Objects.requireNonNull(response, "response cannot be null");
        this.requestLine = requestLine;
        this.host = host;
        this.response = response;
    }

    /**
     * Returns the request line that generated this response
     */
    public RequestLine getRequestLine() {
        return requestLine;
    }

    /**
     * Returns the node that returned this response
     */
    public HttpHost getHost() {
        return host;
    }

    /**
     * Returns the status line of the current response
     */
    public StatusLine getStatusLine() {
        return response.getStatusLine();
    }

    /**
     * Returns all the response headers
     */
    public Header[] getHeaders() {
        return response.getAllHeaders();
    }

    /**
     * Returns the response body available, null otherwise
     * @see HttpEntity
     */
    public HttpEntity getEntity() {
        return response.getEntity();
    }

    @Override
    public String toString() {
        return "ElasticsearchResponse{" +
                "requestLine=" + requestLine +
                ", host=" + host +
                ", response=" + response.getStatusLine() +
                '}';
    }

    @Override
    public void close() throws IOException {
        this.response.close();
    }
}

@@ -2482,32 +2482,520 @@
 aders();%0A    %7D%0A%0A
+    /**%0A     * Returns the value of the first header with a specified name of this message.%0A     * If there is more than one matching header in the message the first element is returned.%0A     * If there is no matching header in the message %3Ccode%3Enull%3C/code%3E is returned.%0A     */%0A    public String getFirstHeader(String name) %7B%0A        Header header = response.getFirstHeader(name);%0A        if (header == null) %7B%0A            return null;%0A        %7D%0A        return header.getValue();%0A    %7D%0A%0A
     /**%0A     * R

add getFirstHeader method to ElasticsearchResponse