fix #518: HTTP Redirect in proxy subscribe

This commit is contained in:
luvletter2333 2021-06-02 19:27:40 +08:00
parent 28b9fc4fc2
commit 731de1efec
No known key found for this signature in database
GPG Key ID: BFD68B892BECC1D8
1 changed files with 12 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package tw.nekomimi.nekogram.parts
import cn.hutool.http.HttpResponse
import cn.hutool.http.HttpUtil
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -34,7 +35,17 @@ fun loadProxies(urls: List<String>, exceptions: MutableMap<String, Exception>):
subY = url.substringAfterLast("@")
urlFinal = url.substringBefore("@")
}
var content = HttpUtil.get(urlFinal)
var nextUrl = url
var resp: HttpResponse
while (true) {
resp = HttpUtil.createGet(nextUrl).execute();
if (resp.status == 301 || resp.status == 302 || resp.status == 307) {
nextUrl = resp.header("Location");
continue;
}
break;
}
var content = resp.body()
if (subX.isNotBlank()) {
content = content.substringAfter(subX)
.substringBefore(subY)