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