public HttpURLConnection initHttpConnection()

in src/main/java/com/aliyun/credentials/http/CompatibleUrlConnClient.java [122:158]


    public HttpURLConnection initHttpConnection(URL url, HttpRequest request) {
        try {
            HttpURLConnection httpConn = null;

            if ("https".equalsIgnoreCase(url.getProtocol())) {
                SSLSocketFactory sslSocketFactory = createSSLSocketFactory(false);
                HttpsURLConnection httpsConn = (HttpsURLConnection) url.openConnection();
                httpsConn.setSSLSocketFactory(sslSocketFactory);
                HostnameVerifier hostnameVerifier = createHostnameVerifier(false);
                httpsConn.setHostnameVerifier(hostnameVerifier);
                httpConn = httpsConn;
            }

            if (httpConn == null) {
                httpConn = (HttpURLConnection) url.openConnection();
            }

            httpConn.setRequestMethod(request.getSysMethod().toString());
            httpConn.setInstanceFollowRedirects(false);
            httpConn.setDoOutput(true);
            httpConn.setDoInput(true);
            httpConn.setUseCaches(false);
            setConnectionTimeout(httpConn, request);
            httpConn.setRequestProperty(ACCEPT_ENCODING, "identity");
            httpConn.setRequestProperty(USER_AGENT, DEFAULT_USER_AGENT);
            Map<String, String> mappedHeaders = request.getSysHeaders();
            for (Entry<String, String> entry : mappedHeaders.entrySet()) {
                httpConn.setRequestProperty(entry.getKey(), entry.getValue());
            }
            if (request.getHttpContent() != null) {
                httpConn.setRequestProperty(CONTENT_TYPE, request.getSysHeaders().get(CONTENT_TYPE));
            }
            return httpConn;
        } catch (Exception e) {
            throw new CredentialException(e.getMessage(), e);
        }
    }