use built-in constants for HTTP status codes
This commit is contained in:
parent
07971080c4
commit
9522012fe1
app/src
full/java/org/fdroid/fdroid/net/bluetooth
main/java/org/fdroid/fdroid
@ -5,7 +5,7 @@ import android.bluetooth.BluetoothServerSocket;
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.util.Log;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import fi.iki.elonen.NanoHTTPD;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.localrepo.type.BluetoothSwap;
|
||||
import org.fdroid.fdroid.net.bluetooth.httpish.Request;
|
||||
@ -15,13 +15,12 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import fi.iki.elonen.NanoHTTPD;
|
||||
|
||||
/**
|
||||
* Act as a layer on top of LocalHTTPD server, by forwarding requests served
|
||||
* over bluetooth to that server.
|
||||
@ -157,7 +156,7 @@ public class BluetoothServer extends Thread {
|
||||
Response.Builder builder = null;
|
||||
|
||||
try {
|
||||
int statusCode = 404;
|
||||
int statusCode = HttpURLConnection.HTTP_NOT_FOUND;
|
||||
int totalSize = -1;
|
||||
|
||||
if (request.getMethod().equals(Request.Methods.HEAD)) {
|
||||
|
@ -115,7 +115,7 @@ public class HttpDownloader extends Downloader {
|
||||
tmpConn.disconnect();
|
||||
newFileAvailableOnServer = false;
|
||||
switch (statusCode) {
|
||||
case 200:
|
||||
case HttpURLConnection.HTTP_OK:
|
||||
contentLength = tmpConn.getContentLength();
|
||||
if (!TextUtils.isEmpty(etag) && etag.equals(cacheTag)) {
|
||||
Utils.debugLog(TAG, urlString + " is cached, not downloading");
|
||||
@ -123,7 +123,7 @@ public class HttpDownloader extends Downloader {
|
||||
}
|
||||
newFileAvailableOnServer = true;
|
||||
break;
|
||||
case 404:
|
||||
case HttpURLConnection.HTTP_NOT_FOUND:
|
||||
notFound = true;
|
||||
return;
|
||||
default:
|
||||
|
@ -12,6 +12,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -132,7 +133,7 @@ public class Response {
|
||||
public static class Builder {
|
||||
|
||||
private InputStream contentStream;
|
||||
private int statusCode = 200;
|
||||
private int statusCode = HttpURLConnection.HTTP_OK;
|
||||
private int fileSize = -1;
|
||||
private String etag;
|
||||
|
||||
|
@ -571,8 +571,6 @@ public class ManageReposActivity extends AppCompatActivity
|
||||
|
||||
private int statusCode = -1;
|
||||
private static final int REFRESH_DIALOG = Integer.MAX_VALUE;
|
||||
private static final int HTTP_UNAUTHORIZED = 401;
|
||||
private static final int HTTP_OK = 200;
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
@ -630,7 +628,8 @@ public class ManageReposActivity extends AppCompatActivity
|
||||
|
||||
statusCode = connection.getResponseCode();
|
||||
|
||||
return statusCode == HTTP_UNAUTHORIZED || statusCode == HTTP_OK;
|
||||
return statusCode == HttpURLConnection.HTTP_UNAUTHORIZED
|
||||
|| statusCode == HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -644,7 +643,7 @@ public class ManageReposActivity extends AppCompatActivity
|
||||
|
||||
if (addRepoDialog.isShowing()) {
|
||||
|
||||
if (statusCode == HTTP_UNAUTHORIZED) {
|
||||
if (statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
|
||||
|
||||
final View view = getLayoutInflater().inflate(R.layout.login, null);
|
||||
final AlertDialog credentialsDialog = new AlertDialog.Builder(context)
|
||||
|
Loading…
x
Reference in New Issue
Block a user