Cloudflare pages: _headers file does not work

Hi, I’ve set my _headers file to:

/data/*
  Content-Encoding: gzip

But when I make a request to a file within the data folder, there is no Content-Encoding HTTP header on the response. Is this the correct format of the _headers file? Is there a reason I might not be able to set the Content-Encoding header?

Setting a content-encoding header doesn’t mean it’s actually encoded that way. Is the content you’re applying it to actually encoded with gzip? If it were, that header should already be present.

1 Like

Hi, thank you for the reply. The content is encoded with gzip, but the files extensions are .pbf so I’m not sure how Cloudflare would automatically add the Content-Encoding header. Either way, it is not adding the Content-Encoding: gzip header by deafult, nor is it added when I add it in the _headers file (see above). Perhaps it would help if I create a replication case?

Here are the steps you can follow to see the issue yourself:

  1. Login to Cloudflare Dashboard
  2. Click “Workers & Pages”
  3. On the Workers & Pages “Overview” page, click “Create application” button
  4. Click the “Pages” tab
  5. Under “Create using direct upload”, click the “Upload assets” button
  6. Fill in a project name (e.g. test-content-encoding-issue)
  7. Click “Create project”
  8. Under “Upload your project assets”, click “select from computer” and then “upload zip” and upload this ZIP containing 2 files: https://drive.proton.me/urls/EDR1JVBPRC#JBklW3P9P8sX
    1. scuttle-hair.xyz - this file was created by gzipping a gif, then changing the filename from .gz to .xyz
    2. _headers - a text file with the contents:
    /*.xyz
      Content-Encoding: gzip
    
  9. Click “Deploy site”
  10. Make an HTTP request to the file (e.g. https://test-content-encoding-issue.pages.dev/scuttle-hair.xyz) and check the HTTP headers. (e.g. curl -I https://test-content-encoding-issue.pages.dev/scuttle-hair.xyz)
    • EXPECTED: the request to scuttle-hair.xyz should include an HTTP header of Content-Encoding: gzip
    • ACTUAL: the request to scuttle-hair.xyz does NOT include that HTTP header

@sdayman are you able to follow my replication steps and do you run into the same issue that I am?

Sorry, I’ve not given that a try. I still don’t think that’s going to work. Here’s a list of what Cloudflare will apply compression to: