Make fields in WebAddress private, add getters/setters

Change-Id: Iceaf3d648289344e53c37273f7324a79676fbef7
This commit is contained in:
Bjorn Bringert
2010-10-12 16:24:55 +01:00
parent 7db7c5d60c
commit eb8be973c7
7 changed files with 66 additions and 27 deletions

View File

@@ -39,13 +39,11 @@ import java.util.regex.Pattern;
*/
public class WebAddress {
private final static String LOGTAG = "http";
public String mScheme;
public String mHost;
public int mPort;
public String mPath;
public String mAuthInfo;
private String mScheme;
private String mHost;
private int mPort;
private String mPath;
private String mAuthInfo;
static final int MATCH_GROUP_SCHEME = 1;
static final int MATCH_GROUP_AUTHORITY = 2;
@@ -122,6 +120,7 @@ public class WebAddress {
if (mScheme.equals("")) mScheme = "http";
}
@Override
public String toString() {
String port = "";
if ((mPort != 443 && mScheme.equals("https")) ||
@@ -135,4 +134,44 @@ public class WebAddress {
return mScheme + "://" + authInfo + mHost + port + mPath;
}
public void setScheme(String scheme) {
mScheme = scheme;
}
public String getScheme() {
return mScheme;
}
public void setHost(String host) {
mHost = host;
}
public String getHost() {
return mHost;
}
public void setPort(int port) {
mPort = port;
}
public int getPort() {
return mPort;
}
public void setPath(String path) {
mPath = path;
}
public String getPath() {
return mPath;
}
public void setAuthInfo(String authInfo) {
mAuthInfo = authInfo;
}
public String getAuthInfo() {
return mAuthInfo;
}
}

View File

@@ -327,10 +327,10 @@ public class RequestQueue implements RequestFeeder {
/* Create and queue request */
Request req;
HttpHost httpHost = new HttpHost(uri.mHost, uri.mPort, uri.mScheme);
HttpHost httpHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
// set up request
req = new Request(method, httpHost, mProxyHost, uri.mPath, bodyProvider,
req = new Request(method, httpHost, mProxyHost, uri.getPath(), bodyProvider,
bodyLength, eventHandler, headers);
queueRequest(req, false);
@@ -375,9 +375,9 @@ public class RequestQueue implements RequestFeeder {
HttpLog.v("RequestQueue.dispatchSynchronousRequest " + uri);
}
HttpHost host = new HttpHost(uri.mHost, uri.mPort, uri.mScheme);
HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
Request req = new Request(method, host, mProxyHost, uri.mPath,
Request req = new Request(method, host, mProxyHost, uri.getPath(),
bodyProvider, bodyLength, eventHandler, headers);
// Open a new connection that uses our special RequestFeeder

View File

@@ -478,7 +478,7 @@ class BrowserFrame extends Handler {
.getCurrentItem();
if (item != null) {
WebAddress uri = new WebAddress(item.getUrl());
String schemePlusHost = uri.mScheme + uri.mHost;
String schemePlusHost = uri.getScheme() + uri.getHost();
String[] up =
mDatabase.getUsernamePassword(schemePlusHost);
if (up != null && up[0] != null) {
@@ -811,7 +811,7 @@ class BrowserFrame extends Handler {
}
WebAddress uri = new WebAddress(mCallbackProxy
.getBackForwardList().getCurrentItem().getUrl());
String schemePlusHost = uri.mScheme + uri.mHost;
String schemePlusHost = uri.getScheme() + uri.getHost();
String[] ret = getUsernamePassword();
// Has the user entered a username/password pair and is
// there some POST data

View File

@@ -359,7 +359,7 @@ public final class CookieManager {
// negative means far future
if (cookie.expires < 0 || cookie.expires > now) {
// secure cookies can't be overwritten by non-HTTPS url
if (!cookieEntry.secure || HTTPS.equals(uri.mScheme)) {
if (!cookieEntry.secure || HTTPS.equals(uri.getScheme())) {
cookieEntry.value = cookie.value;
cookieEntry.expires = cookie.expires;
cookieEntry.secure = cookie.secure;
@@ -444,7 +444,7 @@ public final class CookieManager {
}
long now = System.currentTimeMillis();
boolean secure = HTTPS.equals(uri.mScheme);
boolean secure = HTTPS.equals(uri.getScheme());
Iterator<Cookie> iter = cookieList.iterator();
SortedSet<Cookie> cookieSet = new TreeSet<Cookie>(COMPARATOR);
@@ -692,7 +692,7 @@ public final class CookieManager {
* ended with "/"
*/
private String[] getHostAndPath(WebAddress uri) {
if (uri.mHost != null && uri.mPath != null) {
if (uri.getHost() != null && uri.getPath() != null) {
/*
* The domain (i.e. host) portion of the cookie is supposed to be
@@ -703,12 +703,12 @@ public final class CookieManager {
* See: http://www.ieft.org/rfc/rfc2965.txt (Section 3.3.3)
*/
String[] ret = new String[2];
ret[0] = uri.mHost.toLowerCase();
ret[1] = uri.mPath;
ret[0] = uri.getHost().toLowerCase();
ret[1] = uri.getPath();
int index = ret[0].indexOf(PERIOD);
if (index == -1) {
if (uri.mScheme.equalsIgnoreCase("file")) {
if (uri.getScheme().equalsIgnoreCase("file")) {
// There is a potential bug where a local file path matches
// another file in the local web server directory. Still
// "localhost" is the best pseudo domain name.

View File

@@ -682,7 +682,7 @@ class LoadListener extends Handler implements EventHandler {
if (!mAuthFailed && mUsername != null && mPassword != null) {
String host = mAuthHeader.isProxy() ?
Network.getInstance(mContext).getProxyHostname() :
mUri.mHost;
mUri.getHost();
HttpAuthHandlerImpl.onReceivedCredentials(this, host,
mAuthHeader.getRealm(), mUsername, mPassword);
makeAuthResponse(mUsername, mPassword);
@@ -952,7 +952,7 @@ class LoadListener extends Handler implements EventHandler {
*/
String host() {
if (mUri != null) {
return mUri.mHost;
return mUri.getHost();
}
return null;

View File

@@ -74,9 +74,9 @@ public final class URLUtil {
}
// Check host
if (webAddress.mHost.indexOf('.') == -1) {
if (webAddress.getHost().indexOf('.') == -1) {
// no dot: user probably entered a bare domain. try .com
webAddress.mHost = "www." + webAddress.mHost + ".com";
webAddress.setHost("www." + webAddress.getHost() + ".com");
}
return webAddress.toString();
}

View File

@@ -26,15 +26,15 @@ public class WebAddressTest extends TestCase {
@SmallTest
public void testHostWithTrailingDot() {
WebAddress webAddress = new WebAddress("http://google.com./b/c/g");
assertEquals("google.com.", webAddress.mHost);
assertEquals("/b/c/g", webAddress.mPath);
assertEquals("google.com.", webAddress.getHost());
assertEquals("/b/c/g", webAddress.getPath());
}
// http://b/1011602
@SmallTest
public void testPathWithoutLeadingSlash() {
WebAddress webAddress = new WebAddress("http://www.myspace.com?si=1");
assertEquals("www.myspace.com", webAddress.mHost);
assertEquals("/?si=1", webAddress.mPath);
assertEquals("www.myspace.com", webAddress.getHost());
assertEquals("/?si=1", webAddress.getPath());
}
}