in src/main/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClient.java [257:283]
public SimpleHttpResponse getHttpGetStatus(String url) throws MalformedURLException, IOException {
log.debug("getHttpGetStatus: {}", url);
final HttpURLConnection c = setHttpTimeouts((HttpURLConnection)new URL(url).openConnection());
setConnectionCredentials(c);
c.setUseCaches(false);
c.setDoOutput(true);
c.setDoInput(true);
c.setInstanceFollowRedirects(false);
boolean gotStatus = false;
int status = 0;
try {
status = c.getResponseCode();
gotStatus = true;
//4xx: client error, 5xx: server error. See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.
boolean isError = status >= 400;
//In HTTP error cases, HttpURLConnection only gives you the input stream via #getErrorStream().
InputStream is = isError ? c.getErrorStream() : c.getInputStream();
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer, StandardCharsets.UTF_8);
log.debug("Got response {} for {}", status, url);
return new SimpleHttpResponse(status, writer.toString());
} finally {
// If we didn't get a status, do not attempt
// to get input streams as this would retry connecting
cleanup(c, gotStatus);
}
}