final Headers headers = new NettyHeadersBackedHeaders(response.headers());
String contentType = headers.get(HttpHeaderConstants.CONTENT_TYPE.toString());
ByteBuf responseBuffer = initBufferReleaseOnExecutionClose(response.content(), execution);
final ByteBufBackedTypedData typedData = new ByteBufBackedTypedData(responseBuffer, DefaultMediaType.get(contentType));
final Status status = new DefaultStatus(response.getStatus());
int maxRedirects = requestSpecBacking.getMaxRedirects();
String locationValue = headers.get("Location");
URI locationUrl = null;
if (locationValue != null) {
locationUrl = new URI(locationValue);
}
//Check for redirect and location header if it is follow redirect if we have request forwarding left
if (shouldRedirect(status) && maxRedirects > 0 && locationUrl != null) {
Action<? super RequestSpec> redirectRequestConfig = Action.join(requestConfigurer, s -> {
if (status.getCode() == 301 || status.getCode() == 302) {
s.method("GET");
}
s.redirects(maxRedirects - 1);
});
RequestAction requestAction = new RequestAction(redirectRequestConfig, locationUrl, execution, eventLoopGroup, byteBufAllocator, maxContentLengthBytes);