diff --git a/CHANGELOG.md b/CHANGELOG.md index 09f630c02..af93085d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * 【crypto 】 MacEngine增加接口update,doFinal,reset等接口 * 【core 】 StrSpliter更名为StrSplitter * 【core 】 NumberUtil的decimalFormat增加数字检查 +* 【http 】 HttpBase的httpVersion方法设置为无效(issue#1644) ### 🐞Bug修复 diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpBase.java b/hutool-http/src/main/java/cn/hutool/http/HttpBase.java index c53003b42..a4ad74f87 100644 --- a/hutool-http/src/main/java/cn/hutool/http/HttpBase.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpBase.java @@ -26,7 +26,7 @@ public abstract class HttpBase { public static final String HTTP_1_0 = "HTTP/1.0"; /**HTTP/1.1*/ public static final String HTTP_1_1 = "HTTP/1.1"; - + /**存储头信息*/ protected Map> headers = new HashMap<>(); /**编码*/ @@ -40,7 +40,7 @@ public abstract class HttpBase { /** * 根据name获取头信息
* 根据RFC2616规范,header的name不区分大小写 - * + * * @param name Header名 * @return Header值 */ @@ -51,7 +51,7 @@ public abstract class HttpBase { } return values.get(0); } - + /** * 根据name获取头信息列表 * @param name Header名 @@ -62,11 +62,11 @@ public abstract class HttpBase { if(StrUtil.isBlank(name)) { return null; } - + final CaseInsensitiveMap> headersIgnoreCase = new CaseInsensitiveMap<>(this.headers); return headersIgnoreCase.get(name.trim()); } - + /** * 根据name获取头信息 * @param name Header名 @@ -78,7 +78,7 @@ public abstract class HttpBase { } return header(name.toString()); } - + /** * 设置一个header
* 如果覆盖模式,则替换之前的值,否则加入到值列表中 @@ -100,7 +100,7 @@ public abstract class HttpBase { } return (T) this; } - + /** * 设置一个header
* 如果覆盖模式,则替换之前的值,否则加入到值列表中 @@ -112,7 +112,7 @@ public abstract class HttpBase { public T header(Header name, String value, boolean isOverride) { return header(name.toString(), value, isOverride); } - + /** * 设置一个header
* 覆盖模式,则替换之前的值 @@ -123,7 +123,7 @@ public abstract class HttpBase { public T header(Header name, String value) { return header(name.toString(), value, true); } - + /** * 设置一个header
* 覆盖模式,则替换之前的值 @@ -134,10 +134,10 @@ public abstract class HttpBase { public T header(String name, String value) { return header(name, value, true); } - + /** * 设置请求头 - * + * * @param headers 请求头 * @param isOverride 是否覆盖已有头信息 * @return this @@ -147,27 +147,27 @@ public abstract class HttpBase { if(CollectionUtil.isEmpty(headers)) { return (T)this; } - + for (Entry entry : headers.entrySet()) { this.header(entry.getKey(), StrUtil.nullToEmpty(entry.getValue()), isOverride); } return (T)this; } - + /** * 设置请求头
* 不覆盖原有请求头 - * + * * @param headers 请求头 * @return this */ public T header(Map> headers) { return header(headers, false); } - + /** * 设置请求头 - * + * * @param headers 请求头 * @param isOverride 是否覆盖已有头信息 * @return this @@ -177,7 +177,7 @@ public abstract class HttpBase { if(CollectionUtil.isEmpty(headers)) { return (T)this; } - + String name; for (Entry> entry : headers.entrySet()) { name = entry.getKey(); @@ -187,11 +187,11 @@ public abstract class HttpBase { } return (T)this; } - + /** * 新增请求头
* 不覆盖原有请求头 - * + * * @param headers 请求头 * @return this * @since 4.0.3 @@ -200,13 +200,13 @@ public abstract class HttpBase { if(CollectionUtil.isEmpty(headers)) { return (T)this; } - + for (Entry entry : headers.entrySet()) { this.header(entry.getKey(), StrUtil.nullToEmpty(entry.getValue()), false); } return (T)this; } - + /** * 移除一个头信息 * @param name Header名 @@ -218,7 +218,7 @@ public abstract class HttpBase { } return (T)this; } - + /** * 移除一个头信息 * @param name Header名 @@ -236,7 +236,7 @@ public abstract class HttpBase { return Collections.unmodifiableMap(headers); } // ---------------------------------------------------------------- Headers end - + /** * 返回http版本 * @return String @@ -244,9 +244,10 @@ public abstract class HttpBase { public String httpVersion() { return httpVersion; } + /** - * 设置http版本 - * + * 设置http版本,此方法不会影响到实际请求的HTTP版本,只用于帮助判断是否connect:Keep-Alive + * * @param httpVersion Http版本,{@link HttpBase#HTTP_1_0},{@link HttpBase#HTTP_1_1} * @return this */ @@ -262,7 +263,7 @@ public abstract class HttpBase { public String charset() { return charset.name(); } - + /** * 设置字符集 * @param charset 字符集 @@ -275,7 +276,7 @@ public abstract class HttpBase { } return (T) this; } - + /** * 设置字符集 * @param charset 字符集 @@ -288,7 +289,7 @@ public abstract class HttpBase { } return (T) this; } - + @Override public String toString() { StringBuilder sb = StrUtil.builder(); @@ -298,10 +299,10 @@ public abstract class HttpBase { entry.getKey()).append(": ").append(CollUtil.join(entry.getValue(), ",")) .append(StrUtil.CRLF); } - + sb.append("Request Body: ").append(StrUtil.CRLF); sb.append(" ").append(StrUtil.str(this.bodyBytes, this.charset)).append(StrUtil.CRLF); - + return sb.toString(); } } diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java index a4612790d..50cd73d08 100644 --- a/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpRequest.java @@ -42,9 +42,6 @@ import java.util.Map; */ public class HttpRequest extends HttpBase { - private static final String CONTENT_TYPE_MULTIPART_PREFIX = ContentType.MULTIPART.getValue() + "; boundary="; - private static final String CONTENT_TYPE_FILE_TEMPLATE = "Content-Type: {}\r\n\r\n"; - /** * 设置全局默认的连接和读取超时时长 * @@ -387,7 +384,7 @@ public class HttpRequest extends HttpBase { public boolean isKeepAlive() { String connection = header(Header.CONNECTION); if (connection == null) { - return !HTTP_1_0.equalsIgnoreCase(httpVersion); + return false == HTTP_1_0.equalsIgnoreCase(httpVersion); } return false == "close".equalsIgnoreCase(connection);