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.

  for = "/.well-known/apple-app-site-association"
    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:

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

Some more information:

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?

  for = "/.well-known/apple-app-site-association"
    Cache-Control = '''
    Content-Type = "application/json"
    X-Content-Type-Options = "nosniff"

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"
1 Like

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

Is anyone able to share the exact code I should place in my _headers file for this?
I tried:
# a path:
# headers for that path:
Content-Type: “application/json”
X-Content-Type-Options: “nosniff”
Cache-Control: “public, max-age=0”

But it still doesn’t seem to validate. My domain hosts my SPA built with angular, so I also wonder if angular’s router is missing with it some how?

Hey @sdb,
I don’t see any obvious issues with those headers. Could you please share your Netlify URL so we can take a look? As a sanity check, I’d like to at least confirm that they’re processed as part of the deploy. Thanks!

Thanks Jen, I managed to get it working I think a part of the problem was my app is a SPA (with angular) and it was catching the route. So I added a rule to my _rewrite files which seemed to fix that.’s validation tool says it is correct, but apple’s does not, however it still works on iOS so who knows.