https://kotlinlang.org logo
Title
r

ribesg

03/15/2021, 12:37 PM
When serving static files using Ktor, how do you override what content type Ktor sets on the response?
Looks like you have to reimplement
static
(more specifically
resources
as
static
doesn’t do anything) yourself, and it’s not super easy, not super clean.
h

hhariri

03/15/2021, 3:24 PM
@ribesg Could you please log a feature request with your use-cases at https://youtrack.jetbrains.com/newIssue?project=KTOR ?
r

ribesg

03/15/2021, 3:28 PM
I’m mostly trying to work around a different problem, which is that Ktor assigns a wrong content type to
.map
files (like
.js.map
in my case, or
.css.map
) and while clients retrieving these files usually don’t care about content type, I wanted to set it as json so that I could see them directly in browser
I understand that Ktor should respect the “official” list of mime types so I don’t expect that to change, these kind of files having no default/expected content type anyway. But the inability to somehow override the content type kinda surprised me. I tried an interceptor, but you are not allowed to set the value of the Content-Type header which is weird
h

hhariri

03/15/2021, 3:37 PM
Then that’s a different issue. Could you please log the specific problem with the wrong assignment, or tell me what you’d expect these file types to have?
r

ribesg

03/15/2021, 3:39 PM
As I said there is no specific content type associated to these files, my Google skills only got me to
application/octet-stream
or eventually
application/json
which is useful for specific debugging but may not make sense. I don’t think the mime types list should be changed but I don’t know what should be done to let users do what they want in this case. I’ll open a general issue