Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Oct 22, 2022
1 parent ab35ba1 commit 64e983d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/**
* 全局Cookie管理器,只针对Hutool请求有效
*
*
* @author Looly
* @since 4.5.15
*/
Expand All @@ -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() {
Expand All @@ -58,7 +58,7 @@ public static List<HttpCookie> getCookies(HttpConnection conn){

/**
* 将本地存储的Cookie信息附带到Http请求中,不覆盖用户定义好的Cookie
*
*
* @param conn {@link HttpConnection}
*/
public static void add(HttpConnection conn) {
Expand All @@ -74,14 +74,13 @@ public static void add(HttpConnection conn) {
throw new IORuntimeException(e);
}


// 不覆盖模式回填Cookie头,这样用户定义的Cookie将优先
conn.header(cookieHeader, false);
}

/**
* 存储响应的Cookie信息到本地
*
*
* @param conn {@link HttpConnection}
*/
public static void store(HttpConnection conn) {
Expand Down
22 changes: 22 additions & 0 deletions hutool-http/src/test/java/cn/hutool/http/Issue2658Test.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 64e983d

Please sign in to comment.