aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/network
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-04-13 21:19:32 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-04-13 21:21:00 +0200
commit135d0a034c1fe780e2de56b591c3c2ed36169439 (patch)
treee87e3ae24ce5c413bb615491f31e9a9a60fed36b /main/src/cgeo/geocaching/network
parent8914bda79b172f21b5979769e0002a7f5f910db5 (diff)
parentb2354d78eed1b392620be489a6aadfd3f99a6da3 (diff)
downloadcgeo-135d0a034c1fe780e2de56b591c3c2ed36169439.zip
cgeo-135d0a034c1fe780e2de56b591c3c2ed36169439.tar.gz
cgeo-135d0a034c1fe780e2de56b591c3c2ed36169439.tar.bz2
Merge branch 'common-network-code' into upstream
Conflicts: main/src/cgeo/geocaching/CacheDetailActivity.java
Diffstat (limited to 'main/src/cgeo/geocaching/network')
-rw-r--r--main/src/cgeo/geocaching/network/HtmlImage.java2
-rw-r--r--main/src/cgeo/geocaching/network/Login.java12
-rw-r--r--main/src/cgeo/geocaching/network/Network.java72
3 files changed, 58 insertions, 28 deletions
diff --git a/main/src/cgeo/geocaching/network/HtmlImage.java b/main/src/cgeo/geocaching/network/HtmlImage.java
index cd89a06..fbcbaaf 100644
--- a/main/src/cgeo/geocaching/network/HtmlImage.java
+++ b/main/src/cgeo/geocaching/network/HtmlImage.java
@@ -80,7 +80,7 @@ public class HtmlImage implements Html.ImageGetter {
if (absoluteURL != null) {
try {
final File file = LocalStorage.getStorageFile(geocode, url, true, true);
- final HttpResponse httpResponse = Network.request(absoluteURL, null, false, file);
+ final HttpResponse httpResponse = Network.request(absoluteURL, null, file);
if (httpResponse != null) {
final int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == 200) {
diff --git a/main/src/cgeo/geocaching/network/Login.java b/main/src/cgeo/geocaching/network/Login.java
index 200daaf..3eca55d 100644
--- a/main/src/cgeo/geocaching/network/Login.java
+++ b/main/src/cgeo/geocaching/network/Login.java
@@ -69,7 +69,7 @@ public abstract class Login {
if (cgBase.res != null) {
Login.setActualStatus(cgBase.res.getString(R.string.init_login_popup_working));
}
- HttpResponse loginResponse = Network.request("https://www.geocaching.com/login/default.aspx", null, false, false, false);
+ HttpResponse loginResponse = Network.request("https://www.geocaching.com/login/default.aspx");
String loginData = Network.getResponseData(loginResponse);
if (loginResponse != null && loginResponse.getStatusLine().getStatusCode() == 503 && BaseUtils.matches(loginData, GCConstants.PATTERN_MAINTENANCE)) {
return StatusCode.MAINTENANCE;
@@ -131,7 +131,7 @@ public abstract class Login {
}
public static StatusCode logout() {
- HttpResponse logoutResponse = Network.request("https://www.geocaching.com/login/default.aspx?RESET=Y&redir=http%3a%2f%2fwww.geocaching.com%2fdefault.aspx%3f", null, false, false, false);
+ HttpResponse logoutResponse = Network.request("https://www.geocaching.com/login/default.aspx?RESET=Y&redir=http%3a%2f%2fwww.geocaching.com%2fdefault.aspx%3f");
String logoutData = Network.getResponseData(logoutResponse);
if (logoutResponse != null && logoutResponse.getStatusLine().getStatusCode() == 503 && BaseUtils.matches(logoutData, GCConstants.PATTERN_MAINTENANCE)) {
return StatusCode.MAINTENANCE;
@@ -218,9 +218,9 @@ public abstract class Login {
if (previousPage != null && previousPage.indexOf(ENGLISH) >= 0) {
Log.i("Geocaching.com language already set to English");
// get find count
- getLoginStatus(Network.getResponseData(Network.request("http://www.geocaching.com/email/", null, false)));
+ getLoginStatus(Network.getResponseData(Network.request("http://www.geocaching.com/email/")));
} else {
- final String page = Network.getResponseData(Network.request("http://www.geocaching.com/default.aspx", null, false));
+ final String page = Network.getResponseData(Network.request("http://www.geocaching.com/default.aspx"));
getLoginStatus(page);
if (page == null) {
Log.e("Failed to read viewstates to set geocaching.com language");
@@ -238,7 +238,7 @@ public abstract class Login {
public static BitmapDrawable downloadAvatarAndGetMemberStatus(final Context context) {
try {
- final String profile = BaseUtils.replaceWhitespace(Network.getResponseData(Network.request("http://www.geocaching.com/my/", null, false)));
+ final String profile = BaseUtils.replaceWhitespace(Network.getResponseData(Network.request("http://www.geocaching.com/my/")));
Settings.setMemberStatus(BaseUtils.getMatch(profile, GCConstants.PATTERN_MEMBER_STATUS, true, null));
@@ -262,7 +262,7 @@ public abstract class Login {
*/
public static void detectGcCustomDate() {
- final String result = Network.getResponseData(Network.request("http://www.geocaching.com/account/ManagePreferences.aspx", null, false, false, false));
+ final String result = Network.getResponseData(Network.request("http://www.geocaching.com/account/ManagePreferences.aspx"));
if (null == result) {
Log.w("cgeoBase.detectGcCustomDate: result is null");
diff --git a/main/src/cgeo/geocaching/network/Network.java b/main/src/cgeo/geocaching/network/Network.java
index 008f887..1629def 100644
--- a/main/src/cgeo/geocaching/network/Network.java
+++ b/main/src/cgeo/geocaching/network/Network.java
@@ -191,61 +191,91 @@ public abstract class Network {
* GET HTTP request
*
* @param uri
+ * the URI to request
* @param params
- * @param xContentType
+ * the parameters to add the the GET request
* @param my
* @param addF
* @return
*/
- public static HttpResponse request(final String uri, final Parameters params, boolean xContentType, boolean my, boolean addF) {
- return Network.request(uri, cgBase.addFToParams(params, my, addF), xContentType);
+ public static HttpResponse request(final String uri, final Parameters params, boolean my, boolean addF) {
+ return Network.request(uri, cgBase.addFToParams(params, my, addF));
}
/**
* GET HTTP request
*
* @param uri
+ * the URI to request
* @param params
- * @param xContentType
- * @param cacheFile
- * the name of the file storing the cached resource, or null not to use one
- * @return
+ * the parameters to add the the GET request
+ * @param headers
+ * the headers to add to the GET request
+ * @return the HTTP response
*/
- public static HttpResponse request(final String uri, final Parameters params, final boolean xContentType, final File cacheFile) {
+ public static HttpResponse request(final String uri, final Parameters params, final Parameters headers) {
final String fullUri = params == null ? uri : Uri.parse(uri).buildUpon().encodedQuery(params.toString()).build().toString();
final HttpRequestBase request = new HttpGet(fullUri);
request.setHeader("X-Requested-With", "XMLHttpRequest");
-
- if (xContentType) {
- request.setHeader("Content-Type", "application/x-www-form-urlencoded");
+ if (headers != null) {
+ for (final NameValuePair header : headers) {
+ request.setHeader(header.getName(), header.getValue());
+ }
}
+ return Network.request(request);
+ }
+
+ /**
+ * GET HTTP request
+ *
+ * @param uri
+ * the URI to request
+ * @param params
+ * the parameters to add the the GET request
+ * @param cacheFile
+ * the name of the file storing the cached resource, or null not to use one
+ * @return the HTTP response
+ */
+ public static HttpResponse request(final String uri, final Parameters params, final File cacheFile) {
if (cacheFile != null && cacheFile.exists()) {
final String etag = LocalStorage.getSavedHeader(cacheFile, "etag");
if (etag != null) {
- request.setHeader("If-None-Match", etag);
+ return request(uri, params, new Parameters("If-None-Match", etag));
} else {
final String lastModified = LocalStorage.getSavedHeader(cacheFile, "last-modified");
if (lastModified != null) {
- request.setHeader("If-Modified-Since", lastModified);
+ return request(uri, params, new Parameters("If-Modified-Since", lastModified));
}
}
}
- return Network.request(request);
+ return request(uri, params, (Parameters) null);
}
/**
* GET HTTP request
*
* @param uri
+ * the URI to request
* @param params
- * @param xContentType
- * @return
+ * the parameters to add the the GET request
+ * @return the HTTP response
+ */
+ public static HttpResponse request(final String uri, final Parameters params) {
+ return request(uri, params, (Parameters) null);
+ }
+
+ /**
+ * GET HTTP request
+ *
+ * @param uri
+ * the URI to request
+ * @return the HTTP response
*/
- public static HttpResponse request(final String uri, final Parameters params, final boolean xContentType) {
- return request(uri, params, xContentType, null);
+ public static HttpResponse request(final String uri) {
+ return request(uri, null, (Parameters) null);
}
public static HttpResponse request(final HttpRequestBase request) {
@@ -368,13 +398,13 @@ public abstract class Network {
* @param addF
* @return
*/
- public static String requestLogged(final String uri, final Parameters params, boolean xContentType, boolean my, boolean addF) {
- HttpResponse response = request(uri, params, xContentType, my, addF);
+ public static String requestLogged(final String uri, final Parameters params, boolean my, boolean addF) {
+ HttpResponse response = request(uri, params, my, addF);
String data = getResponseData(response);
if (!Login.getLoginStatus(data)) {
if (Login.login() == StatusCode.NO_ERROR) {
- response = request(uri, params, xContentType, my, addF);
+ response = request(uri, params, my, addF);
data = getResponseData(response);
} else {
Log.i("Working as guest.");