What does this mean? ```TRACE i.k.s.p.c.ContentNeg...
# ktor
c
What does this mean?
Copy code
TRACE i.k.s.p.c.ContentNegotiation - Skipping because the type is ignored.
I'm using
testApplication
with just the
ContentNegotiation
plugin using KotlinX.Serialization The test fails with
400 Bad Request with no provided body
, and Ktor seems to log that it decided to ignore the body for some reason?
e
Hey @CLOVIS, thanks for the question. It means that body with that type is not usually handled with ContentNegotiation plugin(like
String
or
ByteReadChannel
). If it's necessary, you can remove the type from ignored: https://api.ktor.io/ktor-server/ktor-server-plugins/ktor-server-content-negotiatio[…]egotiation/-content-negotiation-config/remove-ignored-type.html
c
Strange. This is the type I'm serializing:
Copy code
@Serializable
class New(
	val name: String,
)
Is it because it has a single String field? It's not a value class
e
This type is not ignored by default
c
Is there an easy way to turn on additional logging to get more information on what's going on?
According the client logging, the entire request is:
Copy code
METHOD: HttpMethod(value=POST)
COMMON HEADERS
-> Accept: application/json
-> Accept-Charset: UTF-8
-> Authorization: Bearer fake:0
CONTENT HEADERS
-> Content-Length: 27
-> Content-Type: application/json
BODY Content-Type: application/json
BODY START
{"name":"A new department"}
BODY END
It's definitely sending my class, not just a primitive
e
Yep, but this logging is for the request body, and the top one is for the response
c
Oh. The client isn't logging anything for the response.
e
Could you tell me how you're receving the response body?
c
Do you mean, the client-side code to deserialize?
e
server side request handler
Sorry, that's anything but a small example 😅
The type is not visible in this file because of generics, but it is the
New
class I shared above
I have used this exact function in other projects so I think it's unlikely that's where the problem is, I expect it's something to do with the
TestApplication
configuration, but I have no idea what it could be
e
could you tell me how the
TestApplication
is configured?
c
It has the
Routing
,
ContentNegotiation
and
Authentication
plugins (don't hesitate to ask for the specific config for each, this project is FOSS) Specifically for ContentNegotiation:
Copy code
val ApiJson = Json {
	encodeDefaults = false
}

install(ContentNegotiation) {
	json(ApiJson)
}
(this is Ktor 2.2.1 btw, I believe it's either the most recent version or close to it?)
e
Could you log an issue with small repro? I will take a look
c
In the process in minifying it, I found something interesting: if I remove the
authenticate {}
block, it works
If you want to run it locally: • The repository is https://gitlab.com/opensavvy/formulaide • The problem can be reproduced on commit 80da9f76f5fd67114346adf8e9ea8b15ee86a56b • The reproduce, run
remote-server:test
, more precisely
opensavvy.formulaide.remote.server.utils.ReproductionTest
• As it is, the test returns a 400 Bad Request with no body • By disabling authentication (line 31), the test passes
Ah 😐 found the probkem
It's the
:
in:
Copy code
-> Authorization: Bearer fake:0
I'm creating an issue to make it a better error message 🙂
483 Views