diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 35f4f02..5097310 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -1,15 +1,15 @@
[versions]
agp = "8.5.2"
-kotlin = "2.0.20"
+kotlin = "2.0.21"
compileSdk = "34"
minSdk = "21"
libraryVersion = "0.1.9"
-ktor = "3.0.0-rc-1"
+ktor = "3.0.0"
ktor2 = "2.3.12"
coroutines = "1.9.0"
kotlinxDatetime = "0.6.1"
kotlinx-io = "0.5.4"
-okio = "3.9.0"
+okio = "3.9.1"
dokka = "1.9.20"
kotlinx-benchmark = "0.4.12"
diff --git a/ksoup-engine-common/src/com/fleeksoft/ksoup/io/SourceReaderByteArray.kt b/ksoup-engine-common/src/com/fleeksoft/ksoup/io/SourceReaderByteArray.kt
index 9aafca5..6b28bf4 100644
--- a/ksoup-engine-common/src/com/fleeksoft/ksoup/io/SourceReaderByteArray.kt
+++ b/ksoup-engine-common/src/com/fleeksoft/ksoup/io/SourceReaderByteArray.kt
@@ -37,11 +37,17 @@ internal class SourceReaderByteArray(bytes: ByteArray) : SourceReader {
override fun read(bytes: ByteArray, offset: Int, length: Int): Int {
var i = offset
+ var pos = currentPosition
while (exhausted().not() && i < length) {
bytes[i] = source[currentPosition++]
i++
}
- return i
+ val totalRead = currentPosition - pos
+ return if (totalRead == 0 && exhausted()) {
+ -1
+ } else {
+ totalRead
+ }
}
override fun readAllBytes(): ByteArray {
diff --git a/ksoup-network-ktor2/src/com/fleeksoft/ksoup/network/KsoupNetwork.kt b/ksoup-network-ktor2/src/com/fleeksoft/ksoup/network/KsoupNetwork.kt
index 8ff0165..bb6b537 100644
--- a/ksoup-network-ktor2/src/com/fleeksoft/ksoup/network/KsoupNetwork.kt
+++ b/ksoup-network-ktor2/src/com/fleeksoft/ksoup/network/KsoupNetwork.kt
@@ -25,7 +25,7 @@ public suspend fun Ksoup.parseGetRequest(
val httpResponse = NetworkHelperKtor.instance.get(url, httpRequestBuilder = httpRequestBuilder)
// url can be changed after redirection
val finalUrl = httpResponse.request.url.toString()
- return parse(sourceReader = httpResponse.asSourceReader(), parser = parser, baseUri = finalUrl)
+ return parse(html = httpResponse.bodyAsText(), parser = parser, baseUri = finalUrl)
}
/**
@@ -52,7 +52,7 @@ public suspend fun Ksoup.parseSubmitRequest(
)
// url can be changed after redirection
val finalUrl = httpResponse.request.url.toString()
- return parse(sourceReader = httpResponse.asSourceReader(), parser = parser, baseUri = finalUrl)
+ return parse(html = httpResponse.bodyAsText(), parser = parser, baseUri = finalUrl)
}
/**
@@ -77,5 +77,5 @@ public suspend fun Ksoup.parsePostRequest(
)
// url can be changed after redirection
val finalUrl = httpResponse.request.url.toString()
- return parse(sourceReader = httpResponse.asSourceReader(), parser = parser, baseUri = finalUrl)
+ return parse(html = httpResponse.bodyAsText(), parser = parser, baseUri = finalUrl)
}
diff --git a/ksoup-network-ktor2/src/com/fleeksoft/ksoup/network/SourceExtNetwork.kt b/ksoup-network-ktor2/src/com/fleeksoft/ksoup/network/SourceExtNetwork.kt
index f28297e..0a05bda 100644
--- a/ksoup-network-ktor2/src/com/fleeksoft/ksoup/network/SourceExtNetwork.kt
+++ b/ksoup-network-ktor2/src/com/fleeksoft/ksoup/network/SourceExtNetwork.kt
@@ -3,6 +3,5 @@ package com.fleeksoft.ksoup.network
import com.fleeksoft.ksoup.io.SourceReader
import com.fleeksoft.ksoup.io.from
import io.ktor.client.statement.*
-import io.ktor.util.*
-suspend fun HttpResponse.asSourceReader() = SourceReader.from(this.bodyAsChannel().toByteArray())
+suspend fun HttpResponse.asSourceReader() = SourceReader.from(this.bodyAsText().encodeToByteArray())
diff --git a/ksoup-test/test/com/fleeksoft/ksoup/meta/MetadataTest.kt b/ksoup-test/test/com/fleeksoft/ksoup/meta/MetadataTest.kt
index 84e8bb6..e9b7c64 100644
--- a/ksoup-test/test/com/fleeksoft/ksoup/meta/MetadataTest.kt
+++ b/ksoup-test/test/com/fleeksoft/ksoup/meta/MetadataTest.kt
@@ -21,6 +21,7 @@ class MetadataTest {
+