httpserver

This commit is contained in:
lushunming 2025-07-19 20:43:09 +08:00
parent 882b07dd41
commit 55463407e0
8 changed files with 72 additions and 22 deletions

View File

@ -85,12 +85,9 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1"
implementation 'io.ktor:ktor-server-core:2.3.13'
// https://mvnrepository.com/artifact/com.sun.net.httpserver/http
implementation 'io.ktor:ktor-server-netty:2.3.13'
implementation 'io.ktor:ktor-server-call-logging:2.3.13'
implementation("org.slf4j:slf4j-android:1.7.36")
implementation("com.sun.net.httpserver:http:20070405")
//implementation 'wang.harlon.quickjs:wrapper-java:1.0.0'
// implementation(ext: 'aar', name: 'quickjs', group: 'fongmi', version: 'release')

View File

@ -73,7 +73,7 @@
-keep class io.ktor.server.config.HoconConfigLoader { *; }
-keep class io.netty.** { *; }
# Logback (Custom rules, see https://github.com/krschultz/android-proguard-snippets/blob/master/libraries/proguard-logback-android.pro)
# to ignore warnings coming from slf4j and logback
@ -95,8 +95,53 @@
-keepattributes SourceFile,LineNumberTable
-keepattributes Signature,InnerClasses
-keepclasseswithmembers class io.netty.** {
*;
# 保留所有 Netty
-keep class io.netty.** { *; }
# 保留 Netty 的内部类
-keep class io.netty.**$* { *; }
# 保留 Netty 的注解
-keep @interface io.netty.**
# 保留 Netty native 方法
-keepclasseswithmembernames,includedescriptorclasses class io.netty.** {
native <methods>;
}
# 保留 Netty 的序列化相关类
-keepclassmembers class io.netty.** implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# 保留 Netty ChannelFuture 相关类
-keep class io.netty.channel.ChannelFuture { *; }
-keep class io.netty.util.concurrent.Future { *; }
# 保留 Netty 的异常类
-keep class io.netty.** extends java.lang.Exception { *; }
# 保留 Netty 的注解处理器
-keepclassmembers class * extends io.netty.** {
@io.netty.** *;
}
# 不警告 Netty 相关的类
-dontwarn io.netty.**
-dontwarn sun.**
# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn java.beans.BeanInfo
-dontwarn java.beans.IntrospectionException
-dontwarn java.beans.Introspector
-dontwarn java.beans.PropertyDescriptor
-dontwarn javax.lang.model.element.Modifier
# 禁用代码混淆
-dontobfuscate

View File

@ -25,9 +25,9 @@ import com.github.catvod.net.OkResult;
import com.github.catvod.spider.Init;
import com.github.catvod.spider.Proxy;
import com.github.catvod.utils.Json;
import com.github.catvod.utils.KtorServer;
import com.github.catvod.utils.Notify;
import com.github.catvod.utils.Path;
import com.github.catvod.utils.ProxyServer;
import com.github.catvod.utils.ProxyVideo;
import com.github.catvod.utils.QRCode;
import com.github.catvod.utils.ResUtil;
@ -235,7 +235,7 @@ public class QuarkApi {
Map<String, String> header = getHeaders();
header.remove("Host");
header.remove("Content-Type");
return Result.get().url(KtorServer.INSTANCE.buildProxyUrl(playUrl, header)).octet().header(header).string();
return Result.get().url(ProxyServer.INSTANCE.buildProxyUrl(playUrl, header)).octet().header(header).string();
}
private String proxyVideoUrl(String url, Map<String, String> header) {

View File

@ -10,7 +10,7 @@ import android.os.Handler;
import android.os.Looper;
import com.github.catvod.crawler.SpiderDebug;
import com.github.catvod.utils.KtorServer;
import com.github.catvod.utils.ProxyServer;
import java.lang.reflect.Field;
import java.util.Map;
@ -43,8 +43,8 @@ public class Init {
public static void init(Context context) {
get().app = ((Application) context);
SpiderDebug.log("自定義爬蟲代碼載入成功!"+"1");
KtorServer.INSTANCE.stop();
KtorServer.INSTANCE.start();
ProxyServer.INSTANCE.stop();
ProxyServer.INSTANCE.start();
}
public static void execute(Runnable runnable) {

View File

@ -1,3 +1,4 @@
/*
package com.github.catvod.utils
import com.github.catvod.crawler.SpiderDebug
@ -72,14 +73,18 @@ object KtorServer {
SpiderDebug.log("ktorServer start on $port")
}
/** 启动服务器 */
*/
/** 启动服务器 *//*
fun start() {
CoroutineScope(Dispatchers.IO).launch { init() }
}
/** 停止服务器 */
*/
/** 停止服务器 *//*
fun stop() {
ser?.stop(1_000, 2_000)
}
@ -94,9 +99,11 @@ object KtorServer {
}"
}
/**
*/
/**
* 获取是否分片信息顺带请求一个1MB块
*/
*//*
@Throws(java.lang.Exception::class)
fun getInfo(url: String?, headers: Map<String, String>): Array<Any> {
val newHeaders: MutableMap<String, String> = java.util.HashMap(headers)
@ -219,3 +226,4 @@ object KtorServer {
url: String, headerNew: Map<String, String>
): Response? = OkHttp.newCall(url, headerNew)
}
*/

View File

@ -6,7 +6,7 @@ import org.robolectric.RobolectricTestRunner;
import java.util.HashMap;
@RunWith(RobolectricTestRunner.class)
//@RunWith(RobolectricTestRunner.class)
public class ProxyVideoTest {
@Test
@ -17,8 +17,8 @@ public class ProxyVideoTest {
// "https://js.shipin520.com/pc/images/new/banner20250225.mp4", new HashMap<>());
"http://172.16.1.217:18089/ng-grid/video.mp4", new HashMap<>());
System.out.println(url);*/
KtorServer.INSTANCE.start();
System.out.println(KtorServer.INSTANCE.buildProxyUrl("http://172.16.1.217:18089/ng-grid/video.mp4", new HashMap<>()));
ProxyServer.INSTANCE.start();
System.out.println(ProxyServer.INSTANCE.buildProxyUrl("http://172.16.1.217:18089/ng-grid/video.mp4", new HashMap<>()));
while (true) {
}

Binary file not shown.

View File

@ -1 +1 @@
8a9fee904fd090f7eb5ec9eb73fc257a
9013187cddf48a5b4bf4604b07dd534b