How to override the content-type of static file?

I am trying to serve my PGP key from my website but the content-type in response is ‘application/pgp-signature’, I want it to be ‘text/plain’ so that it would be rendered in the browser like the way keybase does it.

key from my website: https://rohitgupta.xyz/pgpkey.asc
key from my keybase: https://keybase.io/rohitgupta/pgp_keys.asc

sharing current response (headers) from using curl

❯ curl https://rohitgupta.xyz/pgpkey.asc -I          
HTTP/2 200 
date: Sat, 19 Feb 2022 04:21:32 GMT
content-type: application/pgp-signature
cache-control: public, max-age=0, must-revalidate
etag: "c614904918541626f40f53da22997a04"
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=OLhpffoV%2BFnUIQFJdUjJqpYz7jZ6Bo9Dl8NfXN5ObsoML%2FSg%2Bp%2Ff6R0M4jWI6C1TCetgiozf63SPdTS2D9CbT9iwMvSXO4RYWigpOy6pZNBFpnvnW0d%2FK9pY6SjsHy5Hcg%3D%3D"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
vary: Accept-Encoding
cf-cache-status: DYNAMIC
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
server: cloudflare
cf-ray: 6dfcb57bbdcbdcd6-SIN
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

On localhost as well getting the same issue,

❯ curl http:/localhost:1313/pgpkey.asc -I
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 7140
Content-Type: application/pgp-keys
Last-Modified: Tue, 15 Feb 2022 06:39:18 GMT
Date: Sat, 19 Feb 2022 04:52:00 GMT

How can I override the content-type to ‘text/plain’?

p.s. using github[dotcom]/adityatelange/hugo-PaperMod theme which is built on Hugo

this is my second post as earlier was closed without me replying the response for localhost is similar

This is not a Hugo issue. Looks like you’re a Cloudflare user. Check with their support team to see if you can override the MIME type data.

And what occurs when running hugo server is also platform dependent. For example, on my system:

$ curl -I http://localhost:1313/pgpkey.asc

HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 4
Content-Type: text/plain; charset=utf-8
Last-Modified: Sat, 19 Feb 2022 05:04:13 GMT
Date: Sat, 19 Feb 2022 05:05:12 GMT

You can override your system’s MIME type database when running hugo server with something like this in your site configuration:

[mediaTypes.'text/plain']
suffixes = ['txt','asc']
1 Like

woah! that’s strange.
i am using ubuntu 21

And I’m on 20.04.3 LTS. Like I said, platform dependent. In any case, this is a Cloudflare issue, not a Hugo issue.

Finally, the issue is solved. As @jmooring said this is the issue from Cloudflare only.

So, I found this Transform Rules for response headers.
I simply set the content-type header of the response to text/plain; charset=utf-8 and purged the cache.
Everything is now working as expected :smiley:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.