mirror of
https://gitee.com/dromara/hutool.git
synced 2026-02-09 09:16:26 +08:00
修复HttpRequest.sendRedirectIfPossible未对308做判断问题。(issue#4053@Github)
This commit is contained in:
@@ -119,10 +119,7 @@ public class JdkClientEngine extends AbstractClientEngine {
|
||||
}
|
||||
|
||||
if (HttpStatus.isRedirected(code)) {
|
||||
// https://www.rfc-editor.org/rfc/rfc7231#section-6.4.7
|
||||
// https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Redirections
|
||||
// 307方法和消息主体都不发生变化。
|
||||
if (HttpStatus.HTTP_TEMP_REDIRECT != code) {
|
||||
if (HttpStatus.isRedirectToGet( code)) {
|
||||
// 重定向默认使用GET
|
||||
message.method(Method.GET);
|
||||
}
|
||||
|
||||
@@ -173,10 +173,7 @@ public class OkHttpEngine extends AbstractClientEngine {
|
||||
if (HttpStatus.isRedirected(code)) {
|
||||
message.locationTo(response.header(HeaderName.LOCATION.getValue()));
|
||||
}
|
||||
// https://www.rfc-editor.org/rfc/rfc7231#section-6.4.7
|
||||
// https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Redirections
|
||||
// 307方法和消息主体都不发生变化。
|
||||
if (HttpStatus.HTTP_TEMP_REDIRECT != code) {
|
||||
if (HttpStatus.isRedirectToGet( code)) {
|
||||
// 重定向默认使用GET
|
||||
message.method(Method.GET);
|
||||
}
|
||||
|
||||
@@ -375,4 +375,22 @@ public interface HttpStatus {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为重定后请求变更为GET方法,307、308方法消息主体都不发生变化,见:<br>
|
||||
* <ul>
|
||||
* <li>https://www.rfc-editor.org/rfc/rfc7231#section-6.4.7</li>
|
||||
* <li>https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Redirections</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param responseCode 被检查的状态码
|
||||
* @return 是否为重定向状态码且需要使用GET方法
|
||||
* @since 7.0.0
|
||||
*/
|
||||
static boolean isRedirectToGet(final int responseCode) {
|
||||
return switch (responseCode) {
|
||||
case HTTP_TEMP_REDIRECT, HTTP_PERMANENT_REDIRECT -> false;
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user