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

The following examples show how to use java.net.HttpCookie#getVersion() . 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: CookieManager.java    From Kalle with Apache License 2.0 6 votes vote down vote up
private String sortByPath(List<HttpCookie> cookies) {
    Collections.sort(cookies, new CookiePathComparator());
    final StringBuilder result = new StringBuilder();
    int minVersion = 1;
    for (HttpCookie cookie : cookies) {
        if (cookie.getVersion() < minVersion) {
            minVersion = cookie.getVersion();
        }
    }

    if (minVersion == 1) {
        result.append("$Version=\"1\"; ");
    }

    for (int i = 0; i < cookies.size(); ++i) {
        if (i != 0) {
            result.append("; ");
        }

        result.append(cookies.get(i).toString());
    }

    return result.toString();
}
 
Example 2
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 3
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 4
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 5
Source File: RESTViewImpl.java    From rest-client with Apache License 2.0 4 votes vote down vote up
@Override
public void setUIFromRequest(final Request request){
    // Clear first
    clearUIRequest();

    // URL
    jp_url_go.setUrlString(request.getUrl().toString());

    // Method
    final HTTPMethod reqMethod = request.getMethod();
    jp_req_method.setSelectedMethod(reqMethod);

    // Headers
    MultiValueMap<String, String> headers = request.getHeaders();
    jp_2col_req_headers.setData(headers);
    
    // Cookies
    List<HttpCookie> cookies = request.getCookies();
    MultiValueMap<String, String> cookiesMap = new MultiValueMapArrayList<>();
    
    int version = CookieVersion.DEFAULT_VERSION.getIntValue();
    for(HttpCookie cookie: cookies) {
        cookiesMap.put(cookie.getName(), cookie.getValue());
        version = cookie.getVersion();
    }
    jp_2col_req_cookies.setData(cookiesMap);
    
    // Cookie version
    jp_req_etc.setCookieVersion(CookieVersion.getValue(version));
    
    // Body
    ReqEntity body = request.getBody();
    if(body != null){
        if(jp_req_method.doesSelectedMethodSupportEntityBody()){
            jp_req_body.enableBody();
        }
        jp_req_body.setEntity(body);
    }

    // Authentication
    if(request.getAuth() != null) {
        jp_req_auth.setAuth(request.getAuth());
    }

    // SSL
    if(request.getSslReq() != null) {
        jp_req_ssl.setSslReq(request.getSslReq());
    }

    // HTTP Version
    if(request.getHttpVersion() == HTTPVersion.HTTP_1_1){
        jp_req_etc.setHttpVersion(HTTPVersion.HTTP_1_1);
    }
    else if(request.getHttpVersion() == HTTPVersion.HTTP_1_0){
        jp_req_etc.setHttpVersion(HTTPVersion.HTTP_1_0);
    }

    // Follow redirect
    jp_req_etc.setFollowRedirects(request.isFollowRedirect());
    
    // Ignore response body
    jp_req_etc.setIgnoreResponseBody(request.isIgnoreResponseBody());

    // Test script
    jp_req_test.setTestScript(request.getTestScript()==null?"":request.getTestScript());
}