Commits

Juha Kuitunen  committed 100a9fc

removed duplicate code for authorization

  • Participants
  • Parent commits fd10b59

Comments (0)

Files changed (1)

File src/com/saibotd/bitbeaker/MyActivity.java

 			HttpsURLConnection urlConnection = (HttpsURLConnection) url
 					.openConnection();
 			urlConnection.setUseCaches(true);
-			if (!bitbeaker.getUsername().equals("")) {
-				String loginString = bitbeaker.getUsername() + ":"
-						+ bitbeaker.getPassword();
-				urlConnection.setRequestProperty(
-						"Authorization",
-						"Basic "
-								+ Base64.encodeToString(loginString.getBytes(),
-										Base64.DEFAULT).trim());
-				Log.d("AUTH", "True");
-			}
+			authorize(urlConnection);
 			if (postParams != null) {
 				urlConnection.setDoOutput(true);
 				OutputStreamWriter out = new OutputStreamWriter(
 				URL url = new URL(parameters[0]);
 				HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
 				connection.setUseCaches(true);
-
-				if (!bitbeaker.getUsername().equals("")) {
-					String loginString = bitbeaker.getUsername() + ":"
-							+ bitbeaker.getPassword();
-					connection.setRequestProperty(
-							"Authorization",
-							"Basic "
-									+ Base64.encodeToString(loginString.getBytes(),
-											Base64.DEFAULT).trim());
-					Log.d("AUTH", "True");
-				}
+				authorize(connection);
 
 				b = BitmapFactory.decodeStream(connection.getInputStream());
 				//b = ImageThreadLoader.readBitmapFromNetwork(new URL(parameters[0]));
 		}
 	}
 
+	/**
+	 * Add authorization header to connection
+	 */
+	private void authorize(HttpsURLConnection conn) {
+		
+		if (!bitbeaker.getUsername().equals("")) {
+			String loginString = bitbeaker.getUsername() + ":"
+					+ bitbeaker.getPassword();
+			conn.setRequestProperty(
+					"Authorization",
+					"Basic "
+							+ Base64.encodeToString(loginString.getBytes(),
+									Base64.DEFAULT).trim());
+			Log.d("AUTH", "True");
+		}
+	}
+
 }