Cronet:修复cronet访问支持http3由于请求头的keep-alive而导致400

pull/1145/head
ag2s20150909 3 years ago
parent 6cdb889c6e
commit 846ce02d93
  1. 4
      app/src/main/java/io/legado/app/help/AppConfig.kt
  2. 7
      app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt
  3. 7
      app/src/main/res/xml/network_security_config.xml

@ -231,8 +231,8 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
private fun getPrefUserAgent(): String { private fun getPrefUserAgent(): String {
val ua = appCtx.getPrefString(PreferKey.userAgent) val ua = appCtx.getPrefString(PreferKey.userAgent)
if (ua.isNullOrBlank()) { if (ua.isNullOrBlank()) {
return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
} }
return ua return ua
} }
} }

@ -41,7 +41,11 @@ fun buildRequest(request: Request, callback: UrlRequest.Callback): UrlRequest {
} }
val headers: Headers = request.headers val headers: Headers = request.headers
headers.forEachIndexed { index, _ -> headers.forEachIndexed { index, _ ->
requestBuilder.addHeader(headers.name(index), headers.value(index)) val name = headers.name(index)
if (!name.equals("Keep-Alive", true)) {
requestBuilder.addHeader(name, headers.value(index))
}
} }
val requestBody = request.body val requestBody = request.body
@ -60,6 +64,5 @@ fun buildRequest(request: Request, callback: UrlRequest.Callback): UrlRequest {
} }
return requestBuilder.build() return requestBuilder.build()
} }

@ -3,4 +3,11 @@
<base-config <base-config
cleartextTrafficPermitted="true" cleartextTrafficPermitted="true"
tools:ignore="InsecureBaseConfiguration" /> tools:ignore="InsecureBaseConfiguration" />
<debug-overrides cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="user" />
<certificates src="system"/>
</trust-anchors>
</debug-overrides>
</network-security-config> </network-security-config>
Loading…
Cancel
Save