It seems like ktor is loosing a header. so I wrote...
# ktor
s
It seems like ktor is loosing a header. so I wrote a simple echoServer with Ktor 3.0.1 that returns information about the request for debug purposes. Here is the part generating the header info part:
Copy code
val req = call.request
...
val headers = req.headers.entries().sortedBy {
    entry -> entry.key
}.map { it.key to it.value }
appendLine("request headers: (nr of headers=${headers.size})")

headers.forEach { (name: String, values: List<String>) ->
    appendLine("$name: ${values.joinToString{"[$it]"}}")
}
but wenn I send the following IntelliJ Http Request
Copy code
### GET request with double Accept header
GET <http://localhost:8080/test>
Accept: text/html; q=0.5
Accept: text/plain; q=0.2

###
I only log:
Copy code
request headers: (nr of headers=4)
Accept: [text/plain; q=0.2]
Accept-Encoding: [br, deflate, gzip, x-gzip]
User-Agent: [IntelliJ HTTP Client/IntelliJ IDEA 2024.3]
host: [localhost:8080]
so the text/html; q=0.5-part is missing. This isn't the indended behaviour, is it? 🤔
âś… 1
t
Haven’t used the IntelliJ Http thingy for a while, but you might override the first definition of the header by the second one? Not sure if HTTP allows multiple header definitions with the same key? i would expect something like
Copy code
Accept: text/html;q=0.5, text/plain;q=0.2
in your case 🤔
s
no, boths ways are fine and equivalent according to Stackoverflow . The whole reason why I'm using the header name 2x is to figure out under which circumstances a header values list has more than one element, because when I send
Accept: text/html;q=0.5, text/plain;q=0.2
it's just a single element containing the whole String "Accept: text/html;q=0.5, text/plain;q=0.2" (which surprised me, I thought ktor would split it up automatically)
a
For the mentioned HTTP request definition, IDE sends the following HTTP request:
Copy code
GET / HTTP/1.1
Accept: text/plain; q=0.2
User-Agent: IntelliJ HTTP Client/IntelliJ IDEA 2024.3
Accept-Encoding: br, deflate, gzip, x-gzip
host: localhost:8092
As you can see, it doesn't contain the first Accept header.
s
👍 must be a limitation of the intelliJ http client. Thanks for figuring that out, I'll use curl then.
yes, that fixed it 👍
Accept: [text/html; q=0.5], [text/plain; q=0.2]