mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-03 16:24:31 +08:00
add test
This commit is contained in:
parent
ab35ba10a2
commit
64e983db0f
@ -15,7 +15,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 全局Cookie管理器,只针对Hutool请求有效
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
* @since 4.5.15
|
||||
*/
|
||||
@ -26,19 +26,19 @@ public class GlobalCookieManager {
|
||||
static {
|
||||
cookieManager = new CookieManager(new ThreadLocalCookieStore(), CookiePolicy.ACCEPT_ALL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自定义{@link CookieManager}
|
||||
*
|
||||
*
|
||||
* @param customCookieManager 自定义的{@link CookieManager}
|
||||
*/
|
||||
public static void setCookieManager(CookieManager customCookieManager) {
|
||||
cookieManager = customCookieManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取全局{@link CookieManager}
|
||||
*
|
||||
*
|
||||
* @return {@link CookieManager}
|
||||
*/
|
||||
public static CookieManager getCookieManager() {
|
||||
@ -58,7 +58,7 @@ public class GlobalCookieManager {
|
||||
|
||||
/**
|
||||
* 将本地存储的Cookie信息附带到Http请求中,不覆盖用户定义好的Cookie
|
||||
*
|
||||
*
|
||||
* @param conn {@link HttpConnection}
|
||||
*/
|
||||
public static void add(HttpConnection conn) {
|
||||
@ -74,14 +74,13 @@ public class GlobalCookieManager {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
// 不覆盖模式回填Cookie头,这样用户定义的Cookie将优先
|
||||
conn.header(cookieHeader, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储响应的Cookie信息到本地
|
||||
*
|
||||
*
|
||||
* @param conn {@link HttpConnection}
|
||||
*/
|
||||
public static void store(HttpConnection conn) {
|
||||
|
22
hutool-http/src/test/java/cn/hutool/http/Issue2658Test.java
Executable file
22
hutool-http/src/test/java/cn/hutool/http/Issue2658Test.java
Executable file
@ -0,0 +1,22 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.cookie.GlobalCookieManager;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.HttpCookie;
|
||||
import java.util.List;
|
||||
|
||||
public class Issue2658Test {
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Test
|
||||
@Ignore
|
||||
public void getWithCookieTest(){
|
||||
HttpRequest.get("https://www.baidu.com/").execute();
|
||||
final List<HttpCookie> cookies = GlobalCookieManager.getCookieManager().getCookieStore().getCookies();
|
||||
Console.log("###" + cookies);
|
||||
HttpRequest.get("https://www.baidu.com/").execute();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user