mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
新增followRedirectsCookie配置,支持开启自动重定向携带cookie
This commit is contained in:
parent
afc00aa0b0
commit
5af423ddc2
@ -2,12 +2,14 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.15.M1 (2023-03-08)
|
# 5.8.15.M1 (2023-03-09)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
|
* 【http 】 新增followRedirectsCookie配置,支持开启自动重定向携带cookie(pr#2961@Github)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【all 】 修复Automatic-Module-Name错误问题(issue#2952@Github)
|
* 【all 】 修复Automatic-Module-Name错误问题(issue#2952@Github)
|
||||||
* 【all 】 修复NumberWithFormat导致转换Long异常问题(issue#I6L2LO@Gitee)
|
* 【core 】 修复NumberWithFormat导致转换Long异常问题(issue#I6L2LO@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -305,8 +305,10 @@ public class HttpConfig {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 自动重定向时是否处理cookie
|
* 自动重定向时是否处理cookie
|
||||||
|
*
|
||||||
* @param followRedirectsCookie 自动重定向时是否处理cookie
|
* @param followRedirectsCookie 自动重定向时是否处理cookie
|
||||||
* @return this
|
* @return this
|
||||||
|
* @since 5.8.15
|
||||||
*/
|
*/
|
||||||
public HttpConfig setFollowRedirectsCookie(boolean followRedirectsCookie) {
|
public HttpConfig setFollowRedirectsCookie(boolean followRedirectsCookie) {
|
||||||
this.followRedirectsCookie = followRedirectsCookie;
|
this.followRedirectsCookie = followRedirectsCookie;
|
||||||
|
@ -1262,7 +1262,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
|||||||
private HttpResponse sendRedirectIfPossible(boolean isAsync) {
|
private HttpResponse sendRedirectIfPossible(boolean isAsync) {
|
||||||
// 手动实现重定向
|
// 手动实现重定向
|
||||||
if (config.maxRedirectCount > 0) {
|
if (config.maxRedirectCount > 0) {
|
||||||
int responseCode;
|
final int responseCode;
|
||||||
try {
|
try {
|
||||||
responseCode = httpConnection.responseCode();
|
responseCode = httpConnection.responseCode();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -1271,6 +1271,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
|||||||
throw new HttpException(e);
|
throw new HttpException(e);
|
||||||
}
|
}
|
||||||
// 支持自动重定向时处理cookie
|
// 支持自动重定向时处理cookie
|
||||||
|
// https://github.com/dromara/hutool/issues/2960
|
||||||
if (config.followRedirectsCookie) {
|
if (config.followRedirectsCookie) {
|
||||||
GlobalCookieManager.store(httpConnection);
|
GlobalCookieManager.store(httpConnection);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class RedirectServerTest {
|
|||||||
response.addHeader(Header.SET_COOKIE.getValue(), "redirect3=3; path=/; HttpOnly");
|
response.addHeader(Header.SET_COOKIE.getValue(), "redirect3=3; path=/; HttpOnly");
|
||||||
response.send(301);
|
response.send(301);
|
||||||
}).addAction("/redirect4", (request, response) -> {
|
}).addAction("/redirect4", (request, response) -> {
|
||||||
String cookie = request.getHeader(Header.COOKIE);
|
final String cookie = request.getHeader(Header.COOKIE);
|
||||||
Console.log(cookie);
|
Console.log(cookie);
|
||||||
response.sendOk();
|
response.sendOk();
|
||||||
}).start();
|
}).start();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user