Crash while chaning contentType for protobuf response
See original GitHub issueKtor Version and Engine Used (client or server and name) 1.3 Server
Describe the bug When trying to change contentType framework throws exception: io.ktor.http.UnsafeHeaderException: Header Content-Type is controlled by the engine and cannot be set explicitly
To Reproduce Steps to reproduce the behavior:
- I Wrote Protobuf converter for Kotlin serialization library and it works great when client asks for application/protobuf, but response doens’t contain any content type
class ProtobufConverter() : ContentConverter {
override suspend fun convertForSend(
context: PipelineContext<Any, ApplicationCall>,
contentType: ContentType,
value: Any
): Any? {
context.context.response.header(HttpHeaders.ContentType,"application/protobuf")
return ProtoBuf.dump(serializerForSending(value) as KSerializer<Any>, value)
}
override suspend fun convertForReceive(context: PipelineContext<ApplicationReceiveRequest, ApplicationCall>): Any? {
val request = context.subject
val channel = request.value as? ByteReadChannel ?: return null
val serializer = serializerByTypeInfo(request.typeInfo)
val content = channel.readRemaining().readBytes()
return ProtoBuf.load(serializer, content)
}
}
- When I am trying to change contentType with: context.context.response.header(HttpHeaders.ContentType,“application/protobuf”) framework throws exception
- In docs i found that ApplicationResponse class should have function “contentType” but it is not there in Ktor 1.3
Expected behavior Any way to change contentType manually when application asks for application/protobuf
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Overview | Protocol Buffers - Google Developers
After setting the optionality/repeatability of a field, you specify the data type. Protocol buffers support the usual primitive data types, such ...
Read more >Crash when parsing protobuf message containing a string ...
If I try to parse only ints (I change the protobuf message to be without a string/bytes) all works great. If i add...
Read more >tensorflow 2.0.0 crashes with protobuf 3.10.1 on macOS #35573
If this issue is reproducible with the TF 2.0 from pip(pypi) and latest protobuf from pypi(3.11.2, or even 3.10.1), we can debug. Otherwise,...
Read more >Create Protobuf messages for .NET apps - Microsoft Learn
The preceding message definition specifies three fields as name-value pairs. Like properties on .NET types, each field has a name and a type....
Read more >Firebase Apple SDK Release Notes - Google
Fixed a crash when there were nested data structures inside IN filters (#10507) ... when there's no extension in the file name but...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Most likely Protobuf support will be provided via kotlinx.serialization. We just need to design a converter config API for that purpose.
Don’t you think that lack of popularity comes from fact, that serializing and deserializing Protobuf was really hard without Kotlin? Now it is really straightforward, and we get way smaller output (in our company, some responses became 3x smaller)