33import com .github .balloonupdate .mcpatch .client .config .AppConfig ;
44import com .github .balloonupdate .mcpatch .client .data .Range ;
55import com .github .balloonupdate .mcpatch .client .exceptions .McpatchBusinessException ;
6+ import com .github .balloonupdate .mcpatch .client .logging .Log ;
67import com .github .balloonupdate .mcpatch .client .network .UpdatingServer ;
78import com .github .balloonupdate .mcpatch .client .utils .BytesUtils ;
89import com .github .balloonupdate .mcpatch .client .utils .ReduceReportingFrequency ;
910import com .github .balloonupdate .mcpatch .client .utils .RuntimeAssert ;
11+ import kotlin .Pair ;
1012import okhttp3 .OkHttpClient ;
1113import okhttp3 .Request ;
1214import okhttp3 .Response ;
@@ -160,11 +162,22 @@ Response request(String path, Range range, String desc) throws McpatchBusinessEx
160162 // 拼接 URL
161163 String url = baseUrl + path ;
162164
165+ Log .debug ("Http Request URL: " + url );
166+
163167 // 构建请求
164168 Request req = buildRequest (url , range , null );
165169
166170 try {
171+
167172 Response rsp = client .newCall (req ).execute ();
173+
174+ // for (Pair<? extends String, ? extends String> header : req.headers()) {
175+ // Log.info("Req Header: " + header.component1() + ": " + header.component2());
176+ // }
177+ // for (Pair<? extends String, ? extends String> header : rsp.headers()) {
178+ // Log.info("Rsp Header: " + header.component1() + ": " + header.component2());
179+ // }
180+
168181 int code = rsp .code ();
169182
170183 // 检查状态码
@@ -177,22 +190,6 @@ Response request(String path, Range range, String desc) throws McpatchBusinessEx
177190 throw new McpatchBusinessException (content );
178191 }
179192
180- if (!config .ignoreHttpContentLength )
181- {
182- // 检查content-length
183- long len = rsp .body ().contentLength ();
184-
185- if (len == -1 ) {
186- throw new McpatchBusinessException (String .format ("服务器(%d)没有返回 content-length 头:%s (%s)" , number , path , desc ));
187- }
188-
189- if (range .len () > 0 && len != range .len ()) {
190- String text = String .format ("服务器(%d)返回的 content-length 头 %d 不等于 %d: %s" , number , len , range .len (), path );
191-
192- throw new McpatchBusinessException (text );
193- }
194- }
195-
196193 return rsp ;
197194 } catch (ConnectException e ) {
198195 throw new McpatchBusinessException ("连接被拒绝,请检查网络。" + url , e );
@@ -246,14 +243,12 @@ public IgnoreSSLCert() {
246243 context = SSLContext .getInstance ("TLS" );
247244
248245 trustManager = new X509TrustManager () {
249- public void checkClientTrusted (X509Certificate [] paramArrayOfX509Certificate , String paramString ) { }
250-
251- public void checkServerTrusted (X509Certificate [] paramArrayOfX509Certificate , String paramString ) { }
252-
253- public X509Certificate [] getAcceptedIssuers () { return new X509Certificate [0 ]; }
246+ public void checkClientTrusted (X509Certificate [] chain , String authType ) {}
247+ public void checkServerTrusted (X509Certificate [] chain , String authType ) {}
248+ public X509Certificate [] getAcceptedIssuers () { return new X509Certificate []{}; }
254249 };
255250
256- context .init (null , new TrustManager []{ trustManager }, null );
251+ context .init (null , new TrustManager []{ trustManager }, new java . security . SecureRandom () );
257252 } catch (NoSuchAlgorithmException | KeyManagementException e ) {
258253 throw new RuntimeException (e );
259254 }
0 commit comments