6
6
7
7
import android .os .Build ;
8
8
9
+ import org .apache .http .protocol .HTTP ;
9
10
import org .mozilla .mozstumbler .client .ClientPrefs ;
10
11
import org .mozilla .mozstumbler .service .AppGlobals ;
11
12
import org .mozilla .mozstumbler .service .core .logging .Log ;
@@ -130,6 +131,12 @@ public File getUrlAsFile(URL url, File file) throws IOException {
130
131
131
132
public IResponse get (String urlString , Map <String , String > headers ) {
132
133
134
+ String HTTP_METHOD = "GET" ;
135
+
136
+ return getHttpResponse (urlString , headers , HTTP_METHOD );
137
+ }
138
+
139
+ private IResponse getHttpResponse (String urlString , Map <String , String > headers , String HTTP_METHOD ) {
133
140
URL url = null ;
134
141
HttpURLConnection httpURLConnection = null ;
135
142
@@ -146,15 +153,18 @@ public IResponse get(String urlString, Map<String, String> headers) {
146
153
147
154
try {
148
155
httpURLConnection = (HttpURLConnection ) url .openConnection ();
156
+ if (HTTP_METHOD .toUpperCase ().equals ("HEAD" )) {
157
+ httpURLConnection .setInstanceFollowRedirects (false );
158
+ }
149
159
httpURLConnection .setConnectTimeout (5000 ); // set timeout to 5 seconds
150
- httpURLConnection .setRequestMethod ("GET" );
160
+
161
+ httpURLConnection .setRequestMethod (HTTP_METHOD );
151
162
httpURLConnection .setRequestProperty (USER_AGENT_HEADER , userAgent );
152
163
} catch (IOException e ) {
153
164
Log .e (LOG_TAG , "Couldn't open a connection: " , e );
154
165
return null ;
155
166
}
156
167
157
-
158
168
// Workaround for a bug in Android mHttpURLConnection. When the library
159
169
// reuses a stale connection, the connection may fail with an EOFException
160
170
// http://stackoverflow.com/questions/15411213/android-httpsurlconnection-eofexception/17791819#17791819
@@ -180,6 +190,12 @@ public IResponse get(String urlString, Map<String, String> headers) {
180
190
return null ;
181
191
}
182
192
193
+ @ Override
194
+ public IResponse head (String urlString , Map <String , String > headers ) {
195
+ String HTTP_METHOD = "HEAD" ;
196
+ return getHttpResponse (urlString , headers , HTTP_METHOD );
197
+ }
198
+
183
199
@ Override
184
200
public IResponse post (String urlString , byte [] data , Map <String , String > headers , boolean precompressed ) {
185
201
0 commit comments