https://kotlinlang.org logo
#ktor
Title
# ktor
k

KamilH

02/19/2021, 12:52 PM
Is it possible to override response headers? I’m requesting a resource that is a JSON file, but it is in the text file and response
Content-Type
header is
application/octet-stream
. That is why when I’m requesting this resource, I’m getting
No transformation found
exception, because Json serializer doesn’t know it should parse this file. When I tell serializer to handle also this content type it works properly:
Copy code
install(JsonFeature) {
    serializer = serializerProvider.get()
    accept(ContentType.Application.Json, ContentType.Application.OctetStream)
}
but it fell a little bit hacky to do it for all requests Is there a better solution? (of course the best it would be to fix it on the API side, but I don’t have an access to it)
a

Ali Albaali

02/19/2021, 4:52 PM
The accept function seems the most appropriate for me. Otherwise you could interrupt the request by installing a custom feature to change the header, checkout this.
k

KamilH

02/19/2021, 5:04 PM
Good idea, thanks. This way I could limit this solution to only the endpoint I know needs this
2 Views