Content-Type Header Not Working in netlify.toml

Hey there,

I’m adding a file containing JSON which requires the Content-Type application/json, but can not end with .json. Have made several attempts at configuring this through the netlify.toml, but no matter what it always returns text/plain.

[[headers]]
  for = "/.well-known/apple-app-site-association"
  [headers.values]
    Cache-Control = "public, max-age=0"
    Content-Type = "application/json"
    X-Content-Type-Options = "nosniff"

Any ideas on how to get this to return application/json and not text/plain? You can verify by accessing: http://kawara.app/.well-known/apple-app-site-association

Have you tried setting this custom header through a _headers file instead of in the toml?

Some more information:

https://docs.netlify.com/routing/headers/

That worked! Appreciate the help. Feels like the toml should work w/ this, but hopefully if anyone else runs into a similar issue this topic will appear :slight_smile:

yes, ideally, I would expect the same behaviour regardless of where you set the header, I think. My knowledge isn’t super deep in this area :confused: I’m glad it’s working now, we’ll try and get some eyes on this to understand what is happening here.

I also expect the same behavior regardless of if you’re using a _headers file or a netlify.toml file.

One thing that stood out to me in the netlify.toml snippet you shared is that the Cache-Control line isn’t using the multiline string format that the docs indicate should be used for multi-value headers.

I wonder if that’s what’s causing your netlify.toml header rules to not be applied as expected.

Is the behavior any different if you use the documented multiline string format for multi-value headers like so?

[[headers]]
  for = "/.well-known/apple-app-site-association"
  [headers.values]
    Cache-Control = '''
    public,
    max-age=0'''
    Content-Type = "application/json"
    X-Content-Type-Options = "nosniff"
2 Likes

It also might be useful to this thread to remark that you need to set your customer header with capitalised header values. When I tried it with content-type: "application/json" I ended up with two content-type headers

content-type: text/plain; charset=UTF-8
content-type: "application/json"

thanks for pointing that out, @CrowdHailer. I’ll check with our documentation team to make sure that is expected behaviour.