https://kotlinlang.org logo
#ktor
Title
# ktor
b

benkuly

05/24/2022, 12:38 PM
When I add a ktor 2 client plugin with
scope.requestPipeline.intercept(HttpRequestPipeline.Render)
I get
No request transformation found
. Without
intercept
it works (json with content negotiation). Any idea why?
a

Aleksei Tirman [JB]

05/24/2022, 1:38 PM
Could you please share the code for your interceptor?
b

benkuly

05/24/2022, 2:33 PM
Copy code
scope.requestPipeline.intercept(HttpRequestPipeline.State) { body ->
            val content =
                when (body) {
                    is EmptyContent -> null
                    is String -> json.encodeToJsonElement(body)
                    is JsonElement -> body
                    else -> return@intercept
                }
            val requestAuthenticationBody = json.encodeToString(
                RequestAuthenticationBody(
                    method = context.method.value,
                    uri = context.url.encodedPath,
                    origin = hostname,
                    destination = "${context.host}:${context.port}",
                    content = content
                )
            )
            val signature = sign(requestAuthenticationBody)
            context.header(
                HttpHeaders.Authorization,
                """X-Matrix origin="$hostname",key="${signature.algorithm.name}:${signature.keyId}",sig="${signature.value}""""
            )
        }
a

Aleksei Tirman [JB]

05/24/2022, 2:52 PM
Unfortunately, I cannot reproduce that error. Please share the code where an HTTP client makes a request with a body.
b

benkuly

05/24/2022, 3:14 PM
Hm... I cannot reproduce it, seems to be another problem. Sorry for the disturbance 😕
okay found the issue. My test did an assertation within the
sign
function, which seems to be catched by
intercept
and translated to this generic error message.
4 Views