in log4j-core/src/main/java/org/apache/logging/log4j/core/net/UrlConnectionFactory.java [62:119]
public static <T extends URLConnection> T createConnection(
final URL url,
final long lastModifiedMillis,
final SslConfiguration sslConfiguration,
final AuthorizationProvider authorizationProvider)
throws IOException {
final PropertiesUtil props = PropertiesUtil.getProperties();
final List<String> allowed = Arrays.asList(Strings.splitList(
toRootLowerCase(props.getStringProperty(ALLOWED_PROTOCOLS, DEFAULT_ALLOWED_PROTOCOLS))));
if (allowed.size() == 1 && NO_PROTOCOLS.equals(allowed.get(0))) {
throw new ProtocolException("No external protocols have been enabled");
}
final String protocol = url.getProtocol();
if (protocol == null) {
throw new ProtocolException("No protocol was specified on " + url.toString());
}
if (!allowed.contains(protocol)) {
throw new ProtocolException("Protocol " + protocol + " has not been enabled as an allowed protocol");
}
URLConnection urlConnection;
if (url.getProtocol().equals(HTTP) || url.getProtocol().equals(HTTPS)) {
final HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
if (authorizationProvider != null) {
authorizationProvider.addAuthorization(httpURLConnection);
}
httpURLConnection.setAllowUserInteraction(false);
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestMethod("GET");
if (connectTimeoutMillis > 0) {
httpURLConnection.setConnectTimeout(connectTimeoutMillis);
}
if (readTimeoutMillis > 0) {
httpURLConnection.setReadTimeout(readTimeoutMillis);
}
final String[] fileParts = url.getFile().split("\\.");
final String type = fileParts[fileParts.length - 1].trim();
final String contentType = isXml(type) ? XML : isJson(type) ? JSON : isProperties(type) ? PROPERTIES : TEXT;
httpURLConnection.setRequestProperty("Content-Type", contentType);
if (lastModifiedMillis > 0) {
httpURLConnection.setIfModifiedSince(lastModifiedMillis);
}
if (url.getProtocol().equals(HTTPS) && sslConfiguration != null) {
((HttpsURLConnection) httpURLConnection)
.setSSLSocketFactory(sslConfiguration.getSslContext().getSocketFactory());
if (!sslConfiguration.isVerifyHostName()) {
((HttpsURLConnection) httpURLConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
}
}
urlConnection = httpURLConnection;
} else if (url.getProtocol().equals(JAR)) {
urlConnection = url.openConnection();
urlConnection.setUseCaches(false);
} else {
urlConnection = url.openConnection();
}
return (T) urlConnection;
}