httpserver

This commit is contained in:
lushunming 2025-07-22 10:41:07 +08:00
parent 397b67a704
commit a328a51b03
5 changed files with 40 additions and 34 deletions

View File

@ -42,9 +42,11 @@ public class Init {
public static void init(Context context) {
get().app = ((Application) context);
SpiderDebug.log("自定義爬蟲代碼載入成功!"+"1");
ProxyServer.INSTANCE.stop();
ProxyServer.INSTANCE.start();
SpiderDebug.log("自定義爬蟲代碼載入成功!" + "1");
execute(() -> {
ProxyServer.INSTANCE.stop();
ProxyServer.INSTANCE.start();
});
}
public static void execute(Runnable runnable) {
@ -63,7 +65,8 @@ public class Init {
try {
Activity activity = Init.getActivity();
if (activity == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) return;
if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)
return;
activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 9999);
} catch (Exception e) {
e.printStackTrace();

View File

@ -25,35 +25,36 @@ object ProxyServer {
fun start() {
do {
try {
httpServer = AdvancedHttpServer(port)
httpServer?.addRoutes("/") { _, response ->
run {
response.setContentType("text/html")
response.start()
response.write("Hello, world!")
}
};
httpServer?.addRoutes("/proxy") { req, response ->
run {
val url = Util.base64Decode(req.queryParams["url"])
val header: Map<String, String> = Gson().fromJson<Map<String, String>>(
Util.base64Decode(req.queryParams["headers"]), MutableMap::class.java
)
proxyAsync(url, header, req, response)
}
}
httpServer?.start()
try {
httpServer = AdvancedHttpServer(port)
httpServer?.addRoutes("/") { _, response ->
run {
response.setContentType("text/html")
response.start()
response.write("Hello, world!")
}
};
httpServer?.addRoutes("/proxy") { req, response ->
run {
val url = Util.base64Decode(req.queryParams["url"])
val header: Map<String, String> = Gson().fromJson<Map<String, String>>(
Util.base64Decode(req.queryParams["headers"]), MutableMap::class.java
)
proxyAsync(url, header, req, response)
}
} catch (e: Exception) {
e.printStackTrace()
SpiderDebug.log("启动服务出错:" + e.message)
port++
httpServer?.stop()
}
httpServer?.start()
} catch (e: Exception) {
SpiderDebug.log("start server e:" + e.message)
e.printStackTrace()
httpServer?.stop()
}
SpiderDebug.log("Server start on $port")
} while (port < 20000)
SpiderDebug.log("启动服务 on $port")
}
@ -101,7 +102,9 @@ object ProxyServer {
response.setHeader("Connection", "keep-alive")
response.setHeader("Content-Length", (finalEndPoint - startPoint + 1).toString())
response.setHeader(
"Content-Length", (finalEndPoint - startPoint + 1).toString()
)
response.setHeader(
"Content-Range", "bytes $startPoint-$finalEndPoint/$contentLength"
)

Binary file not shown.

View File

@ -1 +1 @@
4111cbdc5007a7e0510c84e4162e5ad9
f857aaa917fac3bce9f407d7a8262ba7

View File

@ -1,5 +1,5 @@
{
"spider": "https://gh.llkk.cc/https://raw.githubusercontent.com/lushunming/AndroidCatVodSpider/multiThreadNew/jar/custom_spider.jar;md5;4111cbdc5007a7e0510c84e4162e5ad9",
"spider": "https://gh.llkk.cc/https://raw.githubusercontent.com/lushunming/AndroidCatVodSpider/multiThreadNew/jar/custom_spider.jar;md5;f857aaa917fac3bce9f407d7a8262ba7",
"lives": [
{
"name": "电视直播",