Skip to content

Commit 46bd89e

Browse files
committed
增加忽略http协议中的content-length的选项
1 parent c6ad1f4 commit 46bd89e

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/main/java/com/github/balloonupdate/mcpatch/client/config/AppConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ public class AppConfig {
101101
*/
102102
public boolean ignoreSSLCertificate;
103103

104+
105+
/**
106+
* 是否忽略对http协议中content-length的校验
107+
*/
108+
public boolean ignoreHttpContentLength;
109+
104110
/**
105111
* 测试模式,开启后每次都会重头更新,会增加流量消耗,仅用来测试更新时网速
106112
*/
@@ -122,6 +128,7 @@ public AppConfig(Map<String, Object> map) {
122128
int httpTimeout = getInt(map, "http-timeout", null, 7000);
123129
int reties = getInt(map, "retries", "http-retries", 3);
124130
boolean ignoreSSLCertificate = getBoolean(map, "ignore-ssl-cert", "http-ignore-certificate", false);
131+
boolean ignoreHttpContentLength = getBoolean(map, "ignore-http-content-length", "", false);
125132
boolean testMode = getBoolean(map, "test-mode", null, false);
126133

127134
// if (urls.contains("webda"))
@@ -141,6 +148,7 @@ public AppConfig(Map<String, Object> map) {
141148
this.httpTimeout = httpTimeout;
142149
this.reties = reties;
143150
this.ignoreSSLCertificate = ignoreSSLCertificate;
151+
this.ignoreHttpContentLength = ignoreHttpContentLength;
144152
this.testMode = testMode;
145153
}
146154

src/main/java/com/github/balloonupdate/mcpatch/client/network/impl/HttpProtocol.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,20 @@ Response request(String path, Range range, String desc) throws McpatchBusinessEx
177177
throw new McpatchBusinessException(content);
178178
}
179179

180-
// 检查content-length
181-
long len = rsp.body().contentLength();
180+
if (!config.ignoreHttpContentLength)
181+
{
182+
// 检查content-length
183+
long len = rsp.body().contentLength();
182184

183-
if (len == -1) {
184-
throw new McpatchBusinessException(String.format("服务器(%d)没有返回 content-length 头:%s (%s)", number, path, desc));
185-
}
185+
if (len == -1) {
186+
throw new McpatchBusinessException(String.format("服务器(%d)没有返回 content-length 头:%s (%s)", number, path, desc));
187+
}
186188

187-
if (range.len() > 0 && len != range.len()) {
188-
String text = String.format("服务器(%d)返回的 content-length 头 %d 不等于 %d: %s", number, len, range.len(), path);
189+
if (range.len() > 0 && len != range.len()) {
190+
String text = String.format("服务器(%d)返回的 content-length 头 %d 不等于 %d: %s", number, len, range.len(), path);
189191

190-
throw new McpatchBusinessException(text);
192+
throw new McpatchBusinessException(text);
193+
}
191194
}
192195

193196
return rsp;

src/main/resources/mcpatch.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ retries: 3
8080
# 设置 http 系协议是否忽略SSL证书验证
8181
ignore-ssl-cert: false
8282

83+
# 是否忽略对http协议中content-length的校验
84+
ignore-http-content-length: false
85+
8386
# 测试模式,专门用来调试更新时的网速
8487
# 开启后每次都会重头更新,且不会优化任何文件下载
8588
# 仅用于测试用途,平时正常使用勿开

0 commit comments

Comments
 (0)