Simplify to use HEAD instead of GET requests

This commit is contained in:
Cole Markham 2015-02-20 13:52:52 -06:00
parent 9fedd6713e
commit ed0165cc81
1 changed files with 5 additions and 16 deletions

View File

@ -13,7 +13,7 @@ import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
@ -82,12 +82,12 @@ public class HttpClientUnshortenLiveTest {
}
final Pair<Integer, String> expandSingleLevelSafe(final String url) throws IOException {
HttpGet request = null;
HttpHead request = null;
HttpEntity httpEntity = null;
InputStream entityContentStream = null;
try {
request = new HttpGet(url);
request = new HttpHead(url);
final HttpResponse httpResponse = client.execute(request);
httpEntity = httpResponse.getEntity();
@ -118,17 +118,12 @@ public class HttpClientUnshortenLiveTest {
}
final String expandSingleLevel(final String url) throws IOException {
HttpGet request = null;
HttpEntity httpEntity = null;
InputStream entityContentStream = null;
HttpHead request = null;
try {
request = new HttpGet(url);
request = new HttpHead(url);
final HttpResponse httpResponse = client.execute(request);
httpEntity = httpResponse.getEntity();
entityContentStream = httpEntity.getContent();
final int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != 301 && statusCode != 302) {
return url;
@ -144,12 +139,6 @@ public class HttpClientUnshortenLiveTest {
if (request != null) {
request.releaseConnection();
}
if (entityContentStream != null) {
entityContentStream.close();
}
if (httpEntity != null) {
EntityUtils.consume(httpEntity);
}
}
}