mirror of
https://github.com/gedoor/legado.git
synced 2025-01-08 11:47:32 +08:00
优化
This commit is contained in:
parent
cfb88161b7
commit
021e457479
@ -10,13 +10,14 @@ import io.legado.app.api.controller.RssSourceController
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.service.WebService
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.LogUtils
|
||||
import io.legado.app.utils.stackTraceStr
|
||||
import io.legado.app.web.utils.AssetsWeb
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okio.Pipe
|
||||
import okio.buffer
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import kotlin.collections.set
|
||||
|
||||
class HttpServer(port: Int) : NanoHTTPD(port) {
|
||||
private val assetsWeb = AssetsWeb("web")
|
||||
@ -28,6 +29,9 @@ class HttpServer(port: Int) : NanoHTTPD(port) {
|
||||
session.headers["content-type"] = ct.contentTypeHeader
|
||||
var uri = session.uri
|
||||
|
||||
val startAt = System.currentTimeMillis()
|
||||
LogUtils.d(TAG, "${session.method.name} - $uri - ${session.queryParameterString} - Start($startAt)")
|
||||
|
||||
try {
|
||||
when (session.method) {
|
||||
Method.OPTIONS -> {
|
||||
@ -126,11 +130,17 @@ class HttpServer(port: Int) : NanoHTTPD(port) {
|
||||
}
|
||||
response.addHeader("Access-Control-Allow-Methods", "GET, POST")
|
||||
response.addHeader("Access-Control-Allow-Origin", session.headers["origin"])
|
||||
LogUtils.d(TAG, "${session.method.name} - $uri - ${session.queryParameterString} - End($startAt)")
|
||||
return response
|
||||
} catch (e: Exception) {
|
||||
LogUtils.d(TAG, "${session.method.name} - $uri - ${session.queryParameterString} - Error End($startAt)\n$e\n${e.stackTraceStr}")
|
||||
return newFixedLengthResponse(e.message)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "HttpServer"
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user