this.serverConnection = serverConnection;
}
@Override
public void run() {
final HttpClientRequest request;
try {
String requestURI = exchange.getRequestURI();
String qs = exchange.getQueryString();
if (qs != null && !qs.isEmpty()) {
requestURI += "?" + qs;
}
request = clientConnection.createRequest(exchange.getRequestMethod(), new URI(requestURI));
} catch (URISyntaxException e) {
exchange.setResponseCode(500);
exchange.endExchange();
return;
}
final HeaderMap inboundRequestHeaders = exchange.getRequestHeaders();
final HeaderMap outboundRequestHeaders = request.getRequestHeaders();
copyHeaders(outboundRequestHeaders, inboundRequestHeaders);
final long requestContentLength = exchange.getRequestContentLength();
if (HttpContinue.requiresContinueResponse(exchange)) {
request.setContinueHandler(new HttpContinueNotification() {
@Override
public void handleContinue(final ContinueContext context) {
HttpContinue.sendContinueResponse(exchange, new IoCallback() {
@Override
public void onComplete(final HttpServerExchange exchange, final Sender sender) {
context.done();
}
@Override
public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) {
context.done();
}
});
}
});
}
if (requestContentLength == 0L || exchange.getRequestMethod().equals(Methods.GET)) {
request.writeRequestBody(0L);
} else {
ChannelListeners.initiateTransfer(Long.MAX_VALUE, exchange.getRequestChannel(), request.writeRequestBody(requestContentLength), ChannelListeners.closingChannelListener(), new HTTPTrailerChannelListener(exchange, request), ChannelListeners.closingChannelExceptionHandler(), ChannelListeners.closingChannelExceptionHandler(), exchange.getConnection().getBufferPool());
}
final IoFuture<HttpClientResponse> futureResponse = request.getResponse();
futureResponse.addNotifier(RESPONSE_NOTIFIER, exchange);
}