dave08
04/19/2021, 3:34 PMprivate fun ContentType.full() = "$contentType/$contentSubtype"
handleRequest(
<http://HttpMethod.Post|HttpMethod.Post>, "/some-url") {
addHeader(HttpHeaders.Accept, ContentType.Text.Plain.full())
}hfhbd
04/19/2021, 3:37 PMdave08
04/19/2021, 3:37 PMdave08
04/19/2021, 3:39 PMfull() function there, or even better, specialized header functions for testing that accept ContentType.dave08
04/19/2021, 3:40 PMRustam Siniukov
04/19/2021, 4:01 PMfull function? ContentType has proper toString function.
But we agree that testing API can be better and we are working on it. Please create sub tickets with your concerns or just write a comment here https://youtrack.jetbrains.com/issue/KTOR-1649dave08
04/19/2021, 4:03 PMhfhbd
04/19/2021, 4:21 PMaddHeader(HttpHeaders.Accept, ContentType.Text.Plain.toString()). Maybe it should accept Any like the client header api and call the toString() in addHeaderdave08
04/20/2021, 9:02 AMHeaderValueWithParameters that ContentType inherits from has:
override fun toString(): String = when {
parameters.isEmpty() -> content
else -> {
val size = content.length + parameters.sumBy { it.name.length + it.value.length + 3 }
StringBuilder(size).apply {
append(content)
for (index in 0 until parameters.size) {
val (name, value) = parameters[index]
append("; ")
append(name)
append("=")
value.escapeIfNeededTo(this)
}
}.toString()
}
}
And ContentType itself doesn't implement toString()... so how could that work @hfhbd?dave08
04/20/2021, 9:04 AMprotected val content: String in it does contain the full type, but it's protected...hfhbd
04/20/2021, 9:13 AMtoString(), so ContentType.Text.Plain.toString()) results into text/plain.dave08
04/20/2021, 9:14 AMdave08
04/20/2021, 9:15 AMdave08
04/20/2021, 9:16 AMdave08
04/20/2021, 9:18 AMdave08
04/20/2021, 9:50 AMparameters.isEmpty() -> content 🤯... I think this isn't so clear. It would be much better to add a property for this. But, you're right.Rustam Siniukov
04/20/2021, 12:27 PM