Search in sources :

Example 1 with ParseException

use of android.net.ParseException in project XobotOS by xamarin.

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 2 with ParseException

use of android.net.ParseException in project XobotOS by xamarin.

the class CookieManager method setCookie.

/**
     * Set cookie for a given url. The old cookie with same host/path/name will
     * be removed. The new cookie will be added if it is not expired or it does
     * not have expiration which implies it is session cookie.
     * @param url The url which cookie is set for
     * @param value The value for set-cookie: in http response header
     */
public void setCookie(String url, String value) {
    if (JniUtil.useChromiumHttpStack()) {
        setCookie(url, value, false);
        return;
    }
    WebAddress uri;
    try {
        uri = new WebAddress(url);
    } catch (ParseException ex) {
        Log.e(LOGTAG, "Bad address: " + url);
        return;
    }
    setCookie(uri, value);
}
Also used : WebAddress(android.net.WebAddress) ParseException(android.net.ParseException)

Example 3 with ParseException

use of android.net.ParseException in project XobotOS by xamarin.

the class CookieManager method setCookie.

/**
     * Set cookie for a given url. The old cookie with same host/path/name will
     * be removed. The new cookie will be added if it is not expired or it does
     * not have expiration which implies it is session cookie.
     * @param url The url which cookie is set for
     * @param value The value for set-cookie: in http response header
     * @param privateBrowsing cookie jar to use
     * @hide hiding private browsing
     */
public void setCookie(String url, String value, boolean privateBrowsing) {
    if (!JniUtil.useChromiumHttpStack()) {
        setCookie(url, value);
        return;
    }
    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)

Example 4 with ParseException

use of android.net.ParseException in project XobotOS by xamarin.

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 5 with ParseException

use of android.net.ParseException in project android_frameworks_base by DirtyUnicorns.

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)

Aggregations

ParseException (android.net.ParseException)15 WebAddress (android.net.WebAddress)14 Context (android.content.Context)1 SimpleDateFormat (java.text.SimpleDateFormat)1