Java Code Examples for java.net.HttpCookie#getSecure()

The following examples show how to use java.net.HttpCookie#getSecure() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransportableHttpCookie.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
public static List<TransportableHttpCookie> from(URL url, List<HttpCookieWithId> list) {
    List<TransportableHttpCookie> result = new ArrayList<>(list.size());
    for (HttpCookieWithId hcwi : list) {
        HttpCookie cookie = hcwi.httpCookie;
        TransportableHttpCookie thc = new TransportableHttpCookie();
        thc.name = cookie.getName();
        thc.value = cookie.getValue();
        thc.comment = cookie.getComment();
        thc.commentURL = cookie.getCommentURL();
        thc.discard = cookie.getDiscard();
        thc.domain = cookie.getDomain();
        thc.maxAge = cookie.getMaxAge();
        thc.path = cookie.getPath();
        thc.portList = cookie.getPortlist();
        thc.secure = cookie.getSecure();
        thc.version = cookie.getVersion();
        thc.url = url.toString();
        result.add(thc);
    }
    return result;
}
 
Example 2
Source File: CookieDBJar.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private Cookie httpCookie2Cookie(URL url, HttpCookie httpCookie) {
    String domain = httpCookie.getDomain();
    String path = httpCookie.getPath();
    if (TextUtils.isEmpty(domain)) {
        domain = url.getHost();
    }
    if (TextUtils.isEmpty(path)) {
        path = url.getPath();
    }

    Cookie.Builder builder = new Cookie.Builder()
            .name(httpCookie.getName())
            .value(httpCookie.getValue())
            .expiresAt(System.currentTimeMillis() + (httpCookie.getMaxAge() * 1000))
            .domain(domain)
            .path(path);
    if (httpCookie.getSecure()) {
        builder.secure();
    }
    return builder.build();
}
 
Example 3
Source File: CookieEntity.java    From NoHttp with Apache License 2.0 6 votes vote down vote up
/**
 * Cookie building database entities.
 *
 * @param uri    cookie corresponding uri.
 * @param cookie cookie.
 */
public CookieEntity(URI uri, HttpCookie cookie) {
    this.uri = uri == null ? null : uri.toString();
    this.name = cookie.getName();
    this.value = cookie.getValue();
    this.comment = cookie.getComment();
    this.commentURL = cookie.getCommentURL();
    this.discard = cookie.getDiscard();
    this.domain = cookie.getDomain();
    long maxAge = cookie.getMaxAge();
    if (maxAge != -1 && maxAge > 0) {
        this.expiry = (maxAge * 1000L) + System.currentTimeMillis();
        if (this.expiry < 0L) // 溢出
            this.expiry = HeaderUtils.getMaxExpiryMillis();
    } else
        this.expiry = -1L;

    this.path = cookie.getPath();
    if (!TextUtils.isEmpty(path) && path.length() > 1 && path.endsWith("/")) {
        this.path = path.substring(0, path.length() - 1);
    }
    this.portList = cookie.getPortlist();
    this.secure = cookie.getSecure();
    this.version = cookie.getVersion();
}
 
Example 4
Source File: NonBlockingCookieStore.java    From http-builder-ng with Apache License 2.0 6 votes vote down vote up
private boolean matches(final Map.Entry<Key,HttpCookie> entry, final URI uri) {
    final HttpCookie cookie = entry.getValue();
    final boolean secureLink = "https".equalsIgnoreCase(uri.getScheme());
    if(!secureLink && cookie.getSecure()) {
        return false;
    }
    
    final String host = uri.getHost();
    if(entry.getKey() instanceof UriKey) {
        return ((UriKey) entry.getKey()).host.equalsIgnoreCase(host);
    }
    else {
        final String domain = cookie.getDomain();
        if(cookie.getVersion() == 0) {
            return netscapeDomainMatches(domain, host);
        }
        else {
            return HttpCookie.domainMatches(domain, host);
        }
    }
}
 
Example 5
Source File: CookieManager.java    From Kalle with Apache License 2.0 6 votes vote down vote up
/**
 * Get the cookie under the specified URI, where https and secure will be verified.
 *
 * @param uri uri.
 * @return all cookies that match the rules.
 */
public List<String> get(URI uri) {
    boolean secureLink = "https".equalsIgnoreCase(uri.getScheme());
    List<HttpCookie> outCookieList = new ArrayList<>();
    List<HttpCookie> inCookieList = cookieJar.get(uri);
    for (HttpCookie cookie : inCookieList) {
        if (pathMatches(uri, cookie) && (secureLink || !cookie.getSecure())) {
            String portList = cookie.getPortlist();
            int port = getPort(uri);
            if (TextUtils.isEmpty(portList) || containsPort(portList, port)) {
                outCookieList.add(cookie);
            }
        }
    }
    if (outCookieList.isEmpty()) return Collections.emptyList();

    List<String> cookieList = new ArrayList<>();
    cookieList.add(sortByPath(outCookieList));
    return cookieList;
}
 
Example 6
Source File: InMemoryCookieStore.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 7
Source File: InMemoryCookieStore.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 8
Source File: InMemoryCookieStore.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 9
Source File: InMemoryCookieStore.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 10
Source File: InMemoryCookieStore.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 11
Source File: InMemoryCookieStore.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 12
Source File: InMemoryCookieStore.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 13
Source File: InMemoryCookieStore.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has been removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 14
Source File: InMemoryCookieStore.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 15
Source File: InMemoryCookieStore.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 16
Source File: CookieAdapter.java    From SimpleProject with MIT License 5 votes vote down vote up
public CookieAdapter(HttpCookie cookie) {
	this.name = cookie.getName();
	this.value = cookie.getValue();
	this.domain = cookie.getDomain();
	this.path = cookie.getPath();
	this.secure = cookie.getSecure();
}
 
Example 17
Source File: InMemoryCookieStore.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 18
Source File: InMemoryCookieStore.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 19
Source File: InMemoryCookieStore.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}
 
Example 20
Source File: InMemoryCookieStore.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
private <T> void getInternal2(List<HttpCookie> cookies,
                            Map<T, List<HttpCookie>> cookieIndex,
                            Comparable<T> comparator, boolean secureLink)
{
    for (T index : cookieIndex.keySet()) {
        if (comparator.compareTo(index) == 0) {
            List<HttpCookie> indexedCookies = cookieIndex.get(index);
            // check the list of cookies associated with this domain
            if (indexedCookies != null) {
                Iterator<HttpCookie> it = indexedCookies.iterator();
                while (it.hasNext()) {
                    HttpCookie ck = it.next();
                    if (cookieJar.indexOf(ck) != -1) {
                        // the cookie still in main cookie store
                        if (!ck.hasExpired()) {
                            // don't add twice
                            if ((secureLink || !ck.getSecure()) &&
                                    !cookies.contains(ck))
                                cookies.add(ck);
                        } else {
                            it.remove();
                            cookieJar.remove(ck);
                        }
                    } else {
                        // the cookie has beed removed from main store,
                        // so also remove it from domain indexed store
                        it.remove();
                    }
                }
            } // end of indexedCookies != null
        } // end of comparator.compareTo(index) == 0
    } // end of cookieIndex iteration
}