okhttp3.Cookie.parse()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(292)

本文整理了Java中okhttp3.Cookie.parse()方法的一些代码示例,展示了Cookie.parse()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cookie.parse()方法的具体详情如下:
包路径:okhttp3.Cookie
类名称:Cookie
方法名:parse

Cookie.parse介绍

[英]Attempt to parse a Set-Cookie HTTP header value setCookie as a cookie. Returns null if setCookie is not a well-formed cookie.
[中]尝试将集合Cookie HTTP头值setCookie解析为Cookie。如果setCookie不是格式良好的cookie,则返回null。

代码示例

代码示例来源:origin: square/okhttp

/**
 * Attempt to parse a {@code Set-Cookie} HTTP header value {@code setCookie} as a cookie. Returns
 * null if {@code setCookie} is not a well-formed cookie.
 */
public static @Nullable Cookie parse(HttpUrl url, String setCookie) {
 return parse(System.currentTimeMillis(), url, setCookie);
}

代码示例来源:origin: square/okhttp

/** Returns all of the cookies from a set of HTTP response headers. */
public static List<Cookie> parseAll(HttpUrl url, Headers headers) {
 List<String> cookieStrings = headers.values("Set-Cookie");
 List<Cookie> cookies = null;
 for (int i = 0, size = cookieStrings.size(); i < size; i++) {
  Cookie cookie = Cookie.parse(url, cookieStrings.get(i));
  if (cookie == null) continue;
  if (cookies == null) cookies = new ArrayList<>();
  cookies.add(cookie);
 }
 return cookies != null
   ? Collections.unmodifiableList(cookies)
   : Collections.emptyList();
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

/**
 * Attempt to parse a {@code Set-Cookie} HTTP header value {@code setCookie} as a cookie. Returns
 * null if {@code setCookie} is not a well-formed cookie.
 */
public static @Nullable Cookie parse(HttpUrl url, String setCookie) {
 return parse(System.currentTimeMillis(), url, setCookie);
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

/** Returns all of the cookies from a set of HTTP response headers. */
public static List<Cookie> parseAll(HttpUrl url, Headers headers) {
 List<String> cookieStrings = headers.values("Set-Cookie");
 List<Cookie> cookies = null;
 for (int i = 0, size = cookieStrings.size(); i < size; i++) {
  Cookie cookie = Cookie.parse(url, cookieStrings.get(i));
  if (cookie == null) continue;
  if (cookies == null) cookies = new ArrayList<>();
  cookies.add(cookie);
 }
 return cookies != null
   ? Collections.unmodifiableList(cookies)
   : Collections.emptyList();
}

代码示例来源:origin: seven332/EhViewer

public List<Cookie> parseCookies(HttpUrl url, String cookieStrings) {
  if (cookieStrings == null) {
    return Collections.emptyList();
  }
  List<Cookie> cookies = null;
  String[] pieces = cookieStrings.split(";");
  for (String piece: pieces) {
    Cookie cookie = Cookie.parse(url, piece);
    if (cookie == null) {
      continue;
    }
    if (cookies == null) {
      cookies = new ArrayList<>();
    }
    cookies.add(cookie);
  }
  return cookies != null ? cookies : Collections.<Cookie>emptyList();
}

代码示例来源:origin: seven332/EhViewer

@Override
protected void onDestroy() {
 super.onDestroy();
 webView.destroy();
 // Put cookies back to okhttp cookie store
 CookieManager cookieManager = CookieManager.getInstance();
 String cookiesString = cookieManager.getCookie(url);
 if (cookiesString != null && !cookiesString.isEmpty()) {
  EhCookieStore store = EhApplication.getEhCookieStore(this);
  HttpUrl eUrl = HttpUrl.parse(EhUrl.HOST_E);
  HttpUrl exUrl = HttpUrl.parse(EhUrl.HOST_EX);
  // The cookies saved in the uconfig page should be shared between e and ex
  for (String header : cookiesString.split(";")) {
   Cookie eCookie = Cookie.parse(eUrl, header);
   if (eCookie != null) {
    store.addCookie(longLive(eCookie));
   }
   Cookie exCookie = Cookie.parse(exUrl, header);
   if (exCookie != null) {
    store.addCookie(longLive(exCookie));
   }
  }
 }
}

代码示例来源:origin: yuliskov/SmartYouTubeTV

public static List<Cookie> loadCookie(HttpUrl url) {
  String cookie = sCookie;
  List<Cookie> result = new ArrayList<>();
  if (cookie == null || cookie.isEmpty()) {
    return result;
  }
  String[] cookiesRaw = cookie.split(";");
  for (String rawCookie : cookiesRaw) {
    result.add(Cookie.parse(url, rawCookie));
  }
  return result;
}

代码示例来源:origin: duzechao/OKHttpUtils

/**
 * Attempt to parse a {@code Set-Cookie} HTTP header value {@code setCookie} as a cookie. Returns
 * null if {@code setCookie} is not a well-formed cookie.
 */
public static Cookie parse(HttpUrl url, String setCookie) {
 return parse(System.currentTimeMillis(), url, setCookie);
}

代码示例来源:origin: zJiaJun/adult-download

@Override
public boolean processLine(String line) throws IOException {
  Cookie cookie = Cookie.parse(httpUrl, line);
  if (null != cookie) {
    cookieList.add(cookie);
  }
  return true;
}

代码示例来源:origin: com.github.ljun20160606/okhttp

/**
 * Attempt to parse a {@code Set-Cookie} HTTP header value {@code setCookie} as a cookie. Returns
 * null if {@code setCookie} is not a well-formed cookie.
 */
public static @Nullable Cookie parse(HttpUrl url, String setCookie) {
 return parse(System.currentTimeMillis(), url, setCookie);
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Attempt to parse a {@code Set-Cookie} HTTP header value {@code setCookie} as a cookie. Returns
 * null if {@code setCookie} is not a well-formed cookie.
 */
public static @Nullable Cookie parse(HttpUrl url, String setCookie) {
 return parse(System.currentTimeMillis(), url, setCookie);
}

代码示例来源:origin: duzechao/OKHttpUtils

/** Returns all of the cookies from a set of HTTP response headers. */
public static List<Cookie> parseAll(HttpUrl url, Headers headers) {
 List<String> cookieStrings = headers.values("Set-Cookie");
 List<Cookie> cookies = null;
 for (int i = 0, size = cookieStrings.size(); i < size; i++) {
  Cookie cookie = Cookie.parse(url, cookieStrings.get(i));
  if (cookie == null) continue;
  if (cookies == null) cookies = new ArrayList<>();
  cookies.add(cookie);
 }
 return cookies != null
   ? Collections.unmodifiableList(cookies)
   : Collections.<Cookie>emptyList();
}

代码示例来源:origin: com.github.ljun20160606/okhttp

/** Returns all of the cookies from a set of HTTP response headers. */
public static List<Cookie> parseAll(HttpUrl url, Headers headers) {
 List<String> cookieStrings = headers.values("Set-Cookie");
 List<Cookie> cookies = null;
 for (int i = 0, size = cookieStrings.size(); i < size; i++) {
  Cookie cookie = Cookie.parse(url, cookieStrings.get(i));
  if (cookie == null) continue;
  if (cookies == null) cookies = new ArrayList<>();
  cookies.add(cookie);
 }
 return cookies != null
   ? Collections.unmodifiableList(cookies)
   : Collections.<Cookie>emptyList();
}

代码示例来源:origin: apache/servicemix-bundles

/** Returns all of the cookies from a set of HTTP response headers. */
public static List<Cookie> parseAll(HttpUrl url, Headers headers) {
 List<String> cookieStrings = headers.values("Set-Cookie");
 List<Cookie> cookies = null;
 for (int i = 0, size = cookieStrings.size(); i < size; i++) {
  Cookie cookie = Cookie.parse(url, cookieStrings.get(i));
  if (cookie == null) continue;
  if (cookies == null) cookies = new ArrayList<>();
  cookies.add(cookie);
 }
 return cookies != null
   ? Collections.unmodifiableList(cookies)
   : Collections.<Cookie>emptyList();
}

代码示例来源:origin: com.couchbase.lite/couchbase-lite-java-core

protected void storeCookie(Response response) {
  if (!response.headers("Set-Cookie").isEmpty()) {
    HttpUrl rUrl = response.request().url();
    HttpUrl url = new HttpUrl.Builder()
        .scheme(rUrl.scheme())
        .host(rUrl.host())
        .build();
    List<Cookie> cookies = new ArrayList<Cookie>();
    for (String setCookie : response.headers("Set-Cookie")) {
      cookies.add(Cookie.parse(url, setCookie));
    }
    factory.addCookies(cookies);
  }
}

代码示例来源:origin: couchbase/couchbase-lite-java-core

protected void storeCookie(Response response) {
  if (!response.headers("Set-Cookie").isEmpty()) {
    HttpUrl rUrl = response.request().url();
    HttpUrl url = new HttpUrl.Builder()
        .scheme(rUrl.scheme())
        .host(rUrl.host())
        .build();
    List<Cookie> cookies = new ArrayList<Cookie>();
    for (String setCookie : response.headers("Set-Cookie")) {
      cookies.add(Cookie.parse(url, setCookie));
    }
    factory.addCookies(cookies);
  }
}

代码示例来源:origin: com.couchbase.lite/couchbase-lite-java-core

private void storeCookiesIntoCookieJar(Map<String, Object> requestHeadersParam) {
  try {
    if (requestHeadersParam != null
        && requestHeadersParam.containsKey("Cookie")
        && requestHeadersParam.get("Cookie") instanceof String) {
      String cookieString = (String) requestHeadersParam.get("Cookie");
      if (remote != null) {
        // NOTE: In case that the path of URL is not end with `/`,
        //       last segment of a path is not stored as a path of Cookie.
        Cookie cookie = Cookie.parse(HttpUrl.get(remote), cookieString);
        if (cookie != null) {
          replicationInternal.setCookie(cookie);
          // remove Cookie value from requestHeadersParam if cookie is successfully stored into the cookie jar.
          requestHeadersParam.remove("Cookie");
        }
      }
    }
  } catch (Exception e) {
    Log.e(Log.TAG_SYNC, "Failed to store SyncGatewaySession into the CookieJar.", e);
  }
}

代码示例来源:origin: couchbase/couchbase-lite-java-core

private void storeCookiesIntoCookieJar(Map<String, Object> requestHeadersParam) {
  try {
    if (requestHeadersParam != null
        && requestHeadersParam.containsKey("Cookie")
        && requestHeadersParam.get("Cookie") instanceof String) {
      String cookieString = (String) requestHeadersParam.get("Cookie");
      if (remote != null) {
        // NOTE: In case that the path of URL is not end with `/`,
        //       last segment of a path is not stored as a path of Cookie.
        Cookie cookie = Cookie.parse(HttpUrl.get(remote), cookieString);
        if (cookie != null) {
          replicationInternal.setCookie(cookie);
          // remove Cookie value from requestHeadersParam if cookie is successfully stored into the cookie jar.
          requestHeadersParam.remove("Cookie");
        }
      }
    }
  } catch (Exception e) {
    Log.e(Log.TAG_SYNC, "Failed to store SyncGatewaySession into the CookieJar.", e);
  }
}

代码示例来源:origin: marklogic/java-client-api

public static ClientCookie parse(HttpUrl url, String setCookie) {
 Cookie cookie = Cookie.parse(url, setCookie);
 if(cookie == null) throw new IllegalStateException(setCookie + "is not a well-formed cookie");
 return new ClientCookie(cookie.name(), cookie.value(), cookie.expiresAt(), cookie.domain(), cookie.path(),
   cookie.secure());
}

相关文章