Merge pull request #1145 from ag2s20150909/master

Cronet:修复cronet访问支持http3的网站,由于请求头的keep-alive而导致400 Bad Request
pull/1155/head
kunfei 3 years ago committed by GitHub
commit 5cf2ebd463
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      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,7 +231,7 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
private fun getPrefUserAgent(): String {
val ua = appCtx.getPrefString(PreferKey.userAgent)
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
}

@ -41,7 +41,11 @@ fun buildRequest(request: Request, callback: UrlRequest.Callback): UrlRequest {
}
val headers: Headers = request.headers
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
@ -60,6 +64,5 @@ fun buildRequest(request: Request, callback: UrlRequest.Callback): UrlRequest {
}
return requestBuilder.build()
}

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