question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash while chaning contentType for protobuf response

See original GitHub issue

Ktor 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:

  1. 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)
    }

}
  1. When I am trying to change contentType with: context.context.response.header(HttpHeaders.ContentType,“application/protobuf”) framework throws exception
  2. 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:open
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cy6erGn0mcommented, Feb 10, 2020

Most likely Protobuf support will be provided via kotlinx.serialization. We just need to design a converter config API for that purpose.

0reactions
Coneyscommented, Feb 10, 2020

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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found