Search in sources :

Example 1 with WebAddress

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

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

use of android.net.WebAddress 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 3 with WebAddress

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

the class WebAddressTest method testPathWithoutLeadingSlash.

// http://b/1011602
@SmallTest
public void testPathWithoutLeadingSlash() {
    WebAddress webAddress = new WebAddress("http://www.myspace.com?si=1");
    assertEquals("www.myspace.com", webAddress.getHost());
    assertEquals("/?si=1", webAddress.getPath());
}
Also used : WebAddress(android.net.WebAddress) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 4 with WebAddress

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

the class WebAddressTest method testPathWithoutLeadingSlash.

// http://b/1011602
@SmallTest
public void testPathWithoutLeadingSlash() {
    WebAddress webAddress = new WebAddress("http://www.myspace.com?si=1");
    assertEquals("www.myspace.com", webAddress.getHost());
    assertEquals("/?si=1", webAddress.getPath());
}
Also used : WebAddress(android.net.WebAddress) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 5 with WebAddress

use of android.net.WebAddress 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)

Aggregations

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