HttpURLConnection createConnection()

in common/src/main/java/com/microsoft/alm/helpers/HttpClientImpl.java [66:98]


    HttpURLConnection createConnection(final URI uri, final String method, final Action<HttpURLConnection> interceptor) {
        final URL url;
        try {
            url = uri.toURL();
        } catch (final MalformedURLException e) {
            throw new Error(e);
        }

        final HttpURLConnection connection;
        try {
            connection = (HttpURLConnection) url.openConnection();
        } catch (final IOException e) {
            throw new Error(e);
        }

        try {
            connection.setRequestMethod(method);
        } catch (final ProtocolException e) {
            throw new Error(e);
        }

        for (final Map.Entry<String, String> entry : Headers.entrySet()) {
            final String key = entry.getKey();
            final String value = entry.getValue();
            connection.setRequestProperty(key, value);
        }

        if (interceptor != null) {
            interceptor.call(connection);
        }

        return connection;
    }