Search in sources :

Example 11 with WebAddress

use of android.net.WebAddress in project android_frameworks_base by crdroidandroid.

the class WebAddressTest method testHostWithTrailingDot.

// http://b/2337042
@SmallTest
public void testHostWithTrailingDot() {
    WebAddress webAddress = new WebAddress("http://google.com./b/c/g");
    assertEquals("google.com.", webAddress.getHost());
    assertEquals("/b/c/g", webAddress.getPath());
}
Also used : WebAddress(android.net.WebAddress) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 12 with WebAddress

use of android.net.WebAddress in project platform_frameworks_base by android.

the class URLUtil method guessUrl.

/**
     * Cleans up (if possible) user-entered web addresses
     */
public static String guessUrl(String inUrl) {
    String retVal = inUrl;
    WebAddress webAddress;
    if (TRACE)
        Log.v(LOGTAG, "guessURL before queueRequest: " + inUrl);
    if (inUrl.length() == 0)
        return inUrl;
    if (inUrl.startsWith("about:"))
        return inUrl;
    // Do not try to interpret data scheme URLs
    if (inUrl.startsWith("data:"))
        return inUrl;
    // Do not try to interpret file scheme URLs
    if (inUrl.startsWith("file:"))
        return inUrl;
    // Do not try to interpret javascript scheme URLs
    if (inUrl.startsWith("javascript:"))
        return inUrl;
    // bug 762454: strip period off end of url
    if (inUrl.endsWith(".") == true) {
        inUrl = inUrl.substring(0, inUrl.length() - 1);
    }
    try {
        webAddress = new WebAddress(inUrl);
    } catch (ParseException ex) {
        if (TRACE) {
            Log.v(LOGTAG, "smartUrlFilter: failed to parse url = " + inUrl);
        }
        return retVal;
    }
    // Check host
    if (webAddress.getHost().indexOf('.') == -1) {
        // no dot: user probably entered a bare domain.  try .com
        webAddress.setHost("www." + webAddress.getHost() + ".com");
    }
    return webAddress.toString();
}
Also used : WebAddress(android.net.WebAddress) ParseException(android.net.ParseException)

Example 13 with WebAddress

use of android.net.WebAddress in project android_frameworks_base by ParanoidAndroid.

the class URLUtil method guessUrl.

/**
     * Cleans up (if possible) user-entered web addresses
     */
public static String guessUrl(String inUrl) {
    String retVal = inUrl;
    WebAddress webAddress;
    if (DebugFlags.URL_UTIL)
        Log.v(LOGTAG, "guessURL before queueRequest: " + inUrl);
    if (inUrl.length() == 0)
        return inUrl;
    if (inUrl.startsWith("about:"))
        return inUrl;
    // Do not try to interpret data scheme URLs
    if (inUrl.startsWith("data:"))
        return inUrl;
    // Do not try to interpret file scheme URLs
    if (inUrl.startsWith("file:"))
        return inUrl;
    // Do not try to interpret javascript scheme URLs
    if (inUrl.startsWith("javascript:"))
        return inUrl;
    // bug 762454: strip period off end of url
    if (inUrl.endsWith(".") == true) {
        inUrl = inUrl.substring(0, inUrl.length() - 1);
    }
    try {
        webAddress = new WebAddress(inUrl);
    } catch (ParseException ex) {
        if (DebugFlags.URL_UTIL) {
            Log.v(LOGTAG, "smartUrlFilter: failed to parse url = " + inUrl);
        }
        return retVal;
    }
    // Check host
    if (webAddress.getHost().indexOf('.') == -1) {
        // no dot: user probably entered a bare domain.  try .com
        webAddress.setHost("www." + webAddress.getHost() + ".com");
    }
    return webAddress.toString();
}
Also used : WebAddress(android.net.WebAddress) ParseException(android.net.ParseException)

Example 14 with WebAddress

use of android.net.WebAddress in project android_frameworks_base by ParanoidAndroid.

the class RequestHandle method setupRedirect.

/**
     * Create and queue a redirect request.
     *
     * @param redirectTo URL to redirect to
     * @param statusCode HTTP status code returned from original request
     * @param cacheHeaders Cache header for redirect URL
     * @return true if setup succeeds, false otherwise (redirect loop
     * count exceeded, body provider unable to rewind on 307 redirect)
     */
public boolean setupRedirect(String redirectTo, int statusCode, Map<String, String> cacheHeaders) {
    if (HttpLog.LOGV) {
        HttpLog.v("RequestHandle.setupRedirect(): redirectCount " + mRedirectCount);
    }
    // be careful and remove authentication headers, if any
    mHeaders.remove(AUTHORIZATION_HEADER);
    mHeaders.remove(PROXY_AUTHORIZATION_HEADER);
    if (++mRedirectCount == MAX_REDIRECT_COUNT) {
        // Way too many redirects -- fail out
        if (HttpLog.LOGV)
            HttpLog.v("RequestHandle.setupRedirect(): too many redirects " + mRequest);
        mRequest.error(EventHandler.ERROR_REDIRECT_LOOP, com.android.internal.R.string.httpErrorRedirectLoop);
        return false;
    }
    if (mUrl.startsWith("https:") && redirectTo.startsWith("http:")) {
        // implement http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html#sec15.1.3
        if (HttpLog.LOGV) {
            HttpLog.v("blowing away the referer on an https -> http redirect");
        }
        mHeaders.remove("Referer");
    }
    mUrl = redirectTo;
    try {
        mUri = new WebAddress(mUrl);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    // update the "Cookie" header based on the redirected url
    mHeaders.remove("Cookie");
    String cookie = CookieManager.getInstance().getCookie(mUri);
    if (cookie != null && cookie.length() > 0) {
        mHeaders.put("Cookie", cookie);
    }
    if ((statusCode == 302 || statusCode == 303) && mMethod.equals("POST")) {
        if (HttpLog.LOGV) {
            HttpLog.v("replacing POST with GET on redirect to " + redirectTo);
        }
        mMethod = "GET";
    }
    /* Only repost content on a 307.  If 307, reset the body
           provider so we can replay the body */
    if (statusCode == 307) {
        try {
            if (mBodyProvider != null)
                mBodyProvider.reset();
        } catch (java.io.IOException ex) {
            if (HttpLog.LOGV) {
                HttpLog.v("setupRedirect() failed to reset body provider");
            }
            return false;
        }
    } else {
        mHeaders.remove("Content-Type");
        mBodyProvider = null;
    }
    // Update the cache headers for this URL
    mHeaders.putAll(cacheHeaders);
    createAndQueueNewRequest();
    return true;
}
Also used : WebAddress(android.net.WebAddress) ParseException(android.net.ParseException)

Example 15 with WebAddress

use of android.net.WebAddress in project android_frameworks_base by ParanoidAndroid.

the class CookieManagerClassic method setCookie.

/**
     * See {@link #setCookie(String, String)}
     * @param url The URL for which the cookie is set
     * @param value The value of the cookie, as a string, using the format of
     *              the 'Set-Cookie' HTTP response header
     * @param privateBrowsing Whether to use the private browsing cookie jar
     */
void setCookie(String url, String value, boolean privateBrowsing) {
    WebAddress uri;
    try {
        uri = new WebAddress(url);
    } catch (ParseException ex) {
        Log.e(LOGTAG, "Bad address: " + url);
        return;
    }
    nativeSetCookie(uri.toString(), value, privateBrowsing);
}
Also used : WebAddress(android.net.WebAddress) ParseException(android.net.ParseException)

Aggregations

WebAddress (android.net.WebAddress)26 ParseException (android.net.ParseException)14 SmallTest (android.test.suitebuilder.annotation.SmallTest)12