Simplify to use HEAD instead of GET requests
This commit is contained in:
parent
9fedd6713e
commit
ed0165cc81
@ -13,7 +13,7 @@ import org.apache.http.Header;
|
|||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpHeaders;
|
import org.apache.http.HttpHeaders;
|
||||||
import org.apache.http.HttpResponse;
|
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.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
@ -82,12 +82,12 @@ public class HttpClientUnshortenLiveTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Pair<Integer, String> expandSingleLevelSafe(final String url) throws IOException {
|
final Pair<Integer, String> expandSingleLevelSafe(final String url) throws IOException {
|
||||||
HttpGet request = null;
|
HttpHead request = null;
|
||||||
HttpEntity httpEntity = null;
|
HttpEntity httpEntity = null;
|
||||||
InputStream entityContentStream = null;
|
InputStream entityContentStream = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
request = new HttpGet(url);
|
request = new HttpHead(url);
|
||||||
final HttpResponse httpResponse = client.execute(request);
|
final HttpResponse httpResponse = client.execute(request);
|
||||||
|
|
||||||
httpEntity = httpResponse.getEntity();
|
httpEntity = httpResponse.getEntity();
|
||||||
@ -118,17 +118,12 @@ public class HttpClientUnshortenLiveTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String expandSingleLevel(final String url) throws IOException {
|
final String expandSingleLevel(final String url) throws IOException {
|
||||||
HttpGet request = null;
|
HttpHead request = null;
|
||||||
HttpEntity httpEntity = null;
|
|
||||||
InputStream entityContentStream = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
request = new HttpGet(url);
|
request = new HttpHead(url);
|
||||||
final HttpResponse httpResponse = client.execute(request);
|
final HttpResponse httpResponse = client.execute(request);
|
||||||
|
|
||||||
httpEntity = httpResponse.getEntity();
|
|
||||||
entityContentStream = httpEntity.getContent();
|
|
||||||
|
|
||||||
final int statusCode = httpResponse.getStatusLine().getStatusCode();
|
final int statusCode = httpResponse.getStatusLine().getStatusCode();
|
||||||
if (statusCode != 301 && statusCode != 302) {
|
if (statusCode != 301 && statusCode != 302) {
|
||||||
return url;
|
return url;
|
||||||
@ -144,12 +139,6 @@ public class HttpClientUnshortenLiveTest {
|
|||||||
if (request != null) {
|
if (request != null) {
|
||||||
request.releaseConnection();
|
request.releaseConnection();
|
||||||
}
|
}
|
||||||
if (entityContentStream != null) {
|
|
||||||
entityContentStream.close();
|
|
||||||
}
|
|
||||||
if (httpEntity != null) {
|
|
||||||
EntityUtils.consume(httpEntity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user