if (checkProxyAuthFailure(ctx, httpTxContext)) {
return true;
}
final Request request = httpTxContext.getRequest();
final Uri uri = request.getUri();
boolean secure = Utils.isSecure(uri);
boolean isWebSocket = isWSRequest(httpTxContext.getRequestUri());
// If the request is secure, check to see if an error occurred during
// the handshake. We have to do this here, as the error would occur
// out of the scope of a HttpTxContext so there would be
// no good way to communicate the problem to the caller.
if (secure && checkHandshakeError(ctx, httpTxContext)) {
return true;
}
if (isUpgradeRequest(httpTxContext.getHandler()) && isWebSocket) {
httpTxContext.setWSRequest(true);
convertToUpgradeRequest(httpTxContext);
}
HttpRequestPacket requestPacket = requestCache.poll();
if (requestPacket == null) {
requestPacket = new HttpRequestPacketImpl();
}
final Method method = Method.valueOf(request.getMethod());
requestPacket.setMethod(method);
requestPacket.setProtocol(Protocol.HTTP_1_1);
// Special handling for CONNECT.
if (method == Method.CONNECT) {
final int port = uri.getPort();
requestPacket.setRequestURI(uri.getHost() + ':' + (port == -1 ? 443 : port));
} else if ((secure || isWebSocket) && config.isUseRelativeURIsWithConnectProxies()) {
requestPacket.setRequestURI(getNonEmptyPath(uri));
} else {
requestPacket.setRequestURI(uri.toUrl());
}
final BodyHandler bodyHandler = isPayloadAllowed(method) ?
bodyHandlerFactory.getBodyHandler(request) :
null;
if (bodyHandler != null) {
final long contentLength = request.getContentLength();
if (contentLength >= 0) {
requestPacket.setContentLengthLong(contentLength);
requestPacket.setChunked(false);
} else {
requestPacket.setChunked(true);