/*
 * Copyright (c) 2012-present NAVER Corp.
 *
 * This file is part of The nGrinder software distribution. Refer to
 * the file LICENSE which is part of The nGrinder distribution for
 * licensing details. The nGrinder distribution is available on the
 * Internet at https://naver.github.io/ngrinder
 *
 * Licensed 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.ngrinder.http;

import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.Message;
import org.apache.hc.core5.http.ProtocolVersion;

import java.nio.charset.Charset;
import java.util.function.Function;

public class HTTPResponse {

	private static final byte[] EMPTY_BODY = new byte[0];

	private final Message<HttpResponse, byte[]> message;
	private String bodyText = "";

	HTTPResponse(Message<HttpResponse, byte[]> message) {
		this.message = message;
	}

	public byte[] getBodyBytes() {
		return message.getBody() == null ? EMPTY_BODY : message.getBody();
	}

	public String getBodyText() {
		return getBodyText(Charset.defaultCharset());
	}

	public String getBodyText(Charset charset) {
		if (bodyText.isEmpty()) {
			bodyText = new String(getBodyBytes(), charset);
		}
		return bodyText;
	}

	public <T> T getBody(Function<String, T> converter) {
		return converter.apply(getBodyText());
	}

	public int getStatusCode() {
		return message.getHead().getCode();
	}

	public ProtocolVersion getVersion() {
		return message.getHead().getVersion();
	}

	public static HTTPResponse of(Message<HttpResponse, byte[]> message) {
		return new HTTPResponse(message);
	}
}

@@ -879,16 +879,56 @@
 .http;%0A%0A
+import org.apache.hc.core5.http.Header;%0A
 import o
@@ -1089,16 +1089,64 @@
 harset;%0A
+import java.util.Arrays;%0Aimport java.util.List;%0A
 import j
@@ -2018,32 +2018,332 @@
 tVersion();%0A%09%7D%0A%0A
+%09public Header getHeader(String name) %7B%0A%09%09return message.getHead().getFirstHeader(name);%0A%09%7D%0A%0A%09public List%3CHeader%3E getHeaders() %7B%0A%09%09return Arrays.asList(message.getHead().getHeaders());%0A%09%7D%0A%0A%09public List%3CHeader%3E getHeaders(String name) %7B%0A%09%09return Arrays.asList(message.getHead().getHeaders(name));%0A%09%7D%0A%0A
 %09public static H
@@ -2437,10 +2437,11 @@
 ge);%0A%09%7D%0A
+%0A
 %7D%0A

Add a way to access to response header