protected static HttpURLConnection openConnection(final URL url, final String requestMethod, final Map<String, String> headers)
        throws IOException {
        val connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestMethod(requestMethod);
        connection.setConnectTimeout(connectTimeout);
        connection.setReadTimeout(readTimeout);
        if (headers != null) {
            for (val entry : headers.entrySet()) {
                connection.setRequestProperty(entry.getKey(), entry.getValue());
            }
        }
        return connection;
    }
<p>openConnection.</p>

@param url a {@link URL} object
@param requestMethod a {@link String} object
@param headers a {@link Map} object
@return a {@link HttpURLConnection} object
@throws IOException if any.
pac4j-core/src/main/java/org/pac4j/core/util/HttpUtils.java