public void process()

in httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestUpgrade.java [59:85]


    public void process(
            final HttpRequest request,
            final EntityDetails entity,
            final HttpContext context) throws HttpException, IOException {
        Args.notNull(request, "HTTP request");
        Args.notNull(context, "HTTP context");

        final HttpClientContext clientContext = HttpClientContext.cast(context);
        final RequestConfig requestConfig = clientContext.getRequestConfigOrDefault();
        if (requestConfig.isProtocolUpgradeEnabled()) {
            final ProtocolVersion version = request.getVersion() != null ? request.getVersion() : clientContext.getProtocolVersion();
            if (!request.containsHeader(HttpHeaders.UPGRADE) &&
                    !request.containsHeader(HttpHeaders.CONNECTION) &&
                    version.getMajor() == 1 && version.getMinor() >= 1) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Connection is upgradable: protocol version = {}", version);
                }
                final String method = request.getMethod();
                if ((Method.OPTIONS.isSame(method) || Method.HEAD.isSame(method) || Method.GET.isSame(method)) &&
                        clientContext.getSSLSession() == null) {
                    LOG.debug("Connection is upgradable to TLS: method = {}", method);
                    request.addHeader(HttpHeaders.UPGRADE, "TLS/1.2");
                    request.addHeader(HttpHeaders.CONNECTION, HttpHeaders.UPGRADE);
                }
            }
        }
    }