[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: Handling deflated requests.
From: |
gnunet |
Subject: |
[libeufin] branch master updated: Handling deflated requests. |
Date: |
Tue, 26 Sep 2023 21:33:04 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new 2a73485b Handling deflated requests.
2a73485b is described below
commit 2a73485b7e642fa0d6e14c6d50398da92ba49145
Author: MS <ms@taler.net>
AuthorDate: Tue Sep 26 20:46:49 2023 +0200
Handling deflated requests.
---
bank/src/main/kotlin/tech/libeufin/bank/Main.kt | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
index 4273d01d..d69fd15a 100644
--- a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
+++ b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt
@@ -44,6 +44,10 @@ import io.ktor.server.plugins.statuspages.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
+import io.ktor.utils.io.*
+import io.ktor.utils.io.jvm.javaio.*
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@@ -55,6 +59,7 @@ import org.slf4j.LoggerFactory
import org.slf4j.event.Level
import tech.libeufin.util.*
import java.time.Duration
+import java.util.zip.InflaterInputStream
import kotlin.system.exitProcess
// GLOBALS
@@ -169,6 +174,25 @@ object TalerAmountSerializer : KSerializer<TalerAmount> {
}
}
+/**
+ * This plugin inflates the requests that have "Content-Encoding: deflate"
+ */
+val corebankDecompressionPlugin =
createApplicationPlugin("RequestingBodyDecompression") {
+ onCallReceive { call ->
+ transformBody { data ->
+ if (call.request.headers[HttpHeaders.ContentEncoding] ==
"deflate") {
+ val brc = withContext(Dispatchers.IO) {
+ val inflated = InflaterInputStream(data.toInputStream())
+ @Suppress("BlockingMethodInNonBlockingContext")
+ val bytes = inflated.readAllBytes()
+ ByteReadChannel(bytes)
+ }
+ brc
+ } else data
+ }
+ }
+}
+
/**
* Set up web server handlers for the Taler corebank API.
@@ -190,6 +214,7 @@ fun Application.corebankWebApp(db: Database, ctx:
BankApplicationContext) {
allowMethod(HttpMethod.Delete)
allowCredentials = true
}
+ install(corebankDecompressionPlugin)
install(IgnoreTrailingSlash)
install(ContentNegotiation) {
json(Json {
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: Handling deflated requests.,
gnunet <=