feat: 优化

pull/241/head
kunfei 5 years ago
parent e6ba8339d1
commit 049097af29
  1. 7
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt

@ -42,7 +42,7 @@ object HttpHelper {
fun simpleGet(url: String, encode: String? = null): String? { fun simpleGet(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl -> NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService<HttpGetApi>(baseUrl, encode) val response = getApiService<HttpGetApi>(baseUrl, encode)
.get(url, mapOf()) .get(url, mapOf(Pair(AppConst.UA_NAME, AppConst.userAgent)))
.execute() .execute()
return response.body() return response.body()
} }
@ -52,7 +52,7 @@ object HttpHelper {
suspend fun simpleGetAsync(url: String, encode: String? = null): String? { suspend fun simpleGetAsync(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl -> NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService<HttpGetApi>(baseUrl, encode) val response = getApiService<HttpGetApi>(baseUrl, encode)
.getAsync(url, mapOf()) .getAsync(url, mapOf(Pair(AppConst.UA_NAME, AppConst.userAgent)))
return response.body() return response.body()
} }
return null return null
@ -62,7 +62,7 @@ object HttpHelper {
NetworkUtils.getBaseUrl(url)?.let { baseUrl -> NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
return getByteRetrofit(baseUrl) return getByteRetrofit(baseUrl)
.create(HttpGetApi::class.java) .create(HttpGetApi::class.java)
.getMapByteAsync(url, mapOf(), mapOf()) .getMapByteAsync(url, mapOf(), mapOf(Pair(AppConst.UA_NAME, AppConst.userAgent)))
.body() .body()
} }
return null return null
@ -91,7 +91,6 @@ object HttpHelper {
return Interceptor { chain -> return Interceptor { chain ->
val request = chain.request() val request = chain.request()
.newBuilder() .newBuilder()
.addHeader(AppConst.UA_NAME, AppConst.userAgent)
.addHeader("Keep-Alive", "300") .addHeader("Keep-Alive", "300")
.addHeader("Connection", "Keep-Alive") .addHeader("Connection", "Keep-Alive")
.addHeader("Cache-Control", "no-cache") .addHeader("Cache-Control", "no-cache")

Loading…
Cancel
Save