private boolean sendAsGrizzlyRequest(
final RequestInfoHolder requestInfoHolder,
final FilterChainContext ctx) throws IOException {
HttpTxContext httpTxContext = requestInfoHolder.getHttpTxContext();
if (httpTxContext == null) {
httpTxContext = HttpTxContext.create(requestInfoHolder);
}
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);
}
}
if (httpTxContext.isWSRequest()) {
try {
final URI wsURI = httpTxContext.getWsRequestURI().toJavaNetURI();
httpTxContext.setProtocolHandler(Version.RFC6455.createHandler(true));
httpTxContext.setHandshake(httpTxContext.getProtocolHandler().createHandShake(wsURI));
requestPacket = (HttpRequestPacket) httpTxContext.getHandshake().composeHeaders().getHttpHeader();
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid WS URI: " + httpTxContext.getWsRequestURI());
}
}
requestPacket.setSecure(secure);
addQueryString(request, requestPacket);
addHostHeader(request, uri, requestPacket);
addGeneralHeaders(request, requestPacket);
addCookies(request, requestPacket);
addAuthorizationHeader(request, requestPacket);
initTransferCompletionHandler(request, httpTxContext.getHandler());
final HttpRequestPacket requestPacketLocal = requestPacket;
FilterChainContext sendingCtx = ctx;
if (secure) {