修复ReUtil.replaceAll替换变量错误问题

This commit is contained in:
Looly
2022-09-30 20:10:11 +08:00
parent 730d5a00e2
commit 7eb899e226
6 changed files with 102 additions and 54 deletions

View File

@@ -828,13 +828,26 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 设置是否打开重定向如果打开默认重定向次数为2<br>
* 此方法效果与{@link #setMaxRedirectCount(int)} 一致
*
* <p>
* 需要注意的是,当设置为{@code true}时如果全局重定向次数非0直接复用否则设置默认2次。<br>
* 当设置为{@code false}时无论全局是否设置次数都设置为0。<br>
* 不调用此方法的情况下,使用全局默认的次数。
* </p>
*
* @param isFollowRedirects 是否打开重定向
* @return this
*/
public HttpRequest setFollowRedirects(boolean isFollowRedirects) {
if(isFollowRedirects && config.maxRedirectCount <= 0){
// 默认两次跳转
return setMaxRedirectCount(2);
if (isFollowRedirects) {
if (config.maxRedirectCount <= 0) {
// 默认两次跳转
return setMaxRedirectCount(2);
}
} else {
// 手动强制关闭重定向,此时不受全局重定向设置影响
if (config.maxRedirectCount < 0) {
return setMaxRedirectCount(0);
}
}
return this;
}
@@ -1034,10 +1047,10 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 执行Request请求后对响应内容后续处理<br>
* 处理结束后关闭连接
*
* @param <T> 处理结果类型
* @param <T> 处理结果类型
* @param function 响应内容处理函数
* @since 5.8.5
* @return 处理结果
* @since 5.8.5
*/
public <T> T thenFunction(Function<HttpResponse, T> function) {
try (final HttpResponse response = execute(true)) {
@@ -1242,15 +1255,15 @@ public class HttpRequest extends HttpBase<HttpRequest> {
if (HttpStatus.isRedirected(responseCode)) {
final UrlBuilder redirectUrl;
String location = httpConnection.header(Header.LOCATION);
if(false == HttpUtil.isHttp(location) && false == HttpUtil.isHttps(location)){
if (false == HttpUtil.isHttp(location) && false == HttpUtil.isHttps(location)) {
// issue#I5TPSY
// location可能为相对路径
if(false == location.startsWith("/")){
if (false == location.startsWith("/")) {
location = StrUtil.addSuffixIfNot(this.url.getPathStr(), "/") + location;
}
redirectUrl = UrlBuilder.of(this.url.getScheme(), this.url.getHost(), this.url.getPort()
, location, null, null, this.charset);
} else{
} else {
redirectUrl = UrlBuilder.ofHttpWithoutEncode(location);
}
setUrl(redirectUrl);