if (rewrittenURI == null) {
onRewriteFailed(request, response);
return;
}
final Request proxyRequest = getHttpClient().newRequest(rewrittenURI)
.method(request.getMethod())
.version(HttpVersion.fromString(request.getProtocol()));
// Copy headers
for (Enumeration<String> headerNames = request.getHeaderNames(); headerNames.hasMoreElements(); ) {
String headerName = headerNames.nextElement();
if (HttpHeader.TRANSFER_ENCODING.is(headerName)) {
hasContent = true;
}
for (Enumeration<String> headerValues = request.getHeaders(headerName); headerValues.hasMoreElements(); ) {
String headerValue = headerValues.nextElement();
if (headerValue != null) {
proxyRequest.header(headerName, headerValue);
}
}
}
// Add proxy headers
addViaHeader(proxyRequest);
addXForwardedHeaders(proxyRequest, request);
final AsyncContext asyncContext = request.startAsync();
// We do not timeout the continuation, but the proxy request
asyncContext.setTimeout(0);
proxyRequest.timeout(
getTimeout(), TimeUnit.MILLISECONDS
);
if (hasContent) {
if (inputQuery != null) {
proxyRequest.content(new BytesContentProvider(jsonMapper.writeValueAsBytes(inputQuery)));
} else {
proxyRequest.content(proxyRequestContent(proxyRequest, request));
}
}
customizeProxyRequest(proxyRequest, request);
if (isQuery) {
proxyRequest.send(newMetricsEmittingProxyResponseListener(request, response, inputQuery, startTime));
} else {
proxyRequest.send(newProxyResponseListener(request, response));
}
}