mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
修复重定向没有按照RFC7231规范跳转的问题,修改为除了307外重定向使用GET方式
This commit is contained in:
parent
cefc0fd559
commit
b7ad1e82d1
@ -10,11 +10,11 @@
|
|||||||
* 【core 】 用ArrayList重新实现权重随机类:WeightListRandom(pr#3720@Github)
|
* 【core 】 用ArrayList重新实现权重随机类:WeightListRandom(pr#3720@Github)
|
||||||
* 【crypto 】 SM2解密时,兼容GmSSL非压缩省略的04头的密文(issue#IAP1QJ@Gitee)
|
* 【crypto 】 SM2解密时,兼容GmSSL非压缩省略的04头的密文(issue#IAP1QJ@Gitee)
|
||||||
* 【core 】 兼容NumberUtil.add方法传入整型自动类型转换为浮点类型的精度丢失问题(pr#3721@Github)
|
* 【core 】 兼容NumberUtil.add方法传入整型自动类型转换为浮点类型的精度丢失问题(pr#3721@Github)
|
||||||
* 【http 】 HttpConfig增加配置setUseGetIfRedirect(issue#3722@Github)
|
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【json 】 修复JSONConfig.setDateFormat设置后toBean无效问题(issue#3713@Github)
|
* 【json 】 修复JSONConfig.setDateFormat设置后toBean无效问题(issue#3713@Github)
|
||||||
* 【core 】 修复RegexPool.CHINESE_NAME范围太大的问题(issue#IAOGDR@Gitee)
|
* 【core 】 修复RegexPool.CHINESE_NAME范围太大的问题(issue#IAOGDR@Gitee)
|
||||||
|
* 【http 】 修复重定向没有按照RFC7231规范跳转的问题,修改为除了307外重定向使用GET方式(issue#3722@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
**# 5.8.32(2024-08-30)
|
**# 5.8.32(2024-08-30)
|
||||||
|
@ -100,11 +100,6 @@ public class HttpConfig {
|
|||||||
* @since 5.8.33
|
* @since 5.8.33
|
||||||
*/
|
*/
|
||||||
boolean useDefaultContentTypeIfNull = true;
|
boolean useDefaultContentTypeIfNull = true;
|
||||||
/**
|
|
||||||
* 当重定向时,是否使用Get方式发送请求<br>
|
|
||||||
* issue#3722 部分请求要求重定向时,必须使用Get方式发送请求
|
|
||||||
*/
|
|
||||||
boolean useGetIfRedirect;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置超时,单位:毫秒<br>
|
* 设置超时,单位:毫秒<br>
|
||||||
@ -337,16 +332,4 @@ public class HttpConfig {
|
|||||||
this.useDefaultContentTypeIfNull = useDefaultContentTypeIfNull;
|
this.useDefaultContentTypeIfNull = useDefaultContentTypeIfNull;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 重定向时是否使用GET方式
|
|
||||||
*
|
|
||||||
* @param useGetIfRedirect 重定向时是否使用GET方式
|
|
||||||
* @return this
|
|
||||||
* @since 5.8.33
|
|
||||||
*/
|
|
||||||
public HttpConfig setUseGetIfRedirect(boolean useGetIfRedirect) {
|
|
||||||
this.useGetIfRedirect = useGetIfRedirect;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1313,9 +1313,12 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
|||||||
redirectUrl = UrlBuilder.ofHttpWithoutEncode(location);
|
redirectUrl = UrlBuilder.ofHttpWithoutEncode(location);
|
||||||
}
|
}
|
||||||
setUrl(redirectUrl);
|
setUrl(redirectUrl);
|
||||||
if(config.useGetIfRedirect){
|
// https://www.rfc-editor.org/rfc/rfc7231#section-6.4.7
|
||||||
// since 5.8.33, issue#3722
|
// https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Redirections
|
||||||
setMethod(Method.GET);
|
// 307方法和消息主体都不发生变化。
|
||||||
|
if (HttpStatus.HTTP_TEMP_REDIRECT != responseCode) {
|
||||||
|
// 重定向默认使用GET
|
||||||
|
method(Method.GET);
|
||||||
}
|
}
|
||||||
if (redirectCount < config.maxRedirectCount) {
|
if (redirectCount < config.maxRedirectCount) {
|
||||||
redirectCount++;
|
redirectCount++;
|
||||||
|
Loading…
Reference in New Issue
Block a user