Content-length is removed on response of HEAD method

In generally, content-length header on response of HEAD method is used to know size of content for the target file. But cloudflare removes content-length header. So we don’t have a way to know it.

In most of programming language, we want to know how many bytes will be given for guard to large contents, pre-allocated memory.

Today, I send pull-request for fixing minio S3 server to return X-Content-Length. But they answered that it should be a bug of cloudflare and they close that pull-request.

Please fix this issue.

Thay says that cloudflare is broken.

RFC says:

The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.

So the response of HEAD request returned by cloudflare is in violation of the RFC.

Read here for how Cloudflare handles HEAD requests for cacheable requests:
https://developers.cloudflare.com/cache/concepts/cache-behavior/

If the target file is cached by Cloudflare, it would not be the best idea to send the HEAD request to your origin, as the file on the origin might be different from the cached file. Cloudflare will instead evaluate the HEAD request on the Edge, without it ever reaching your server.

If you want the HEAD request to reach your Origin, you must mark the target file as non-cacheable via a Cache Rule.

The RFC also says that you may omit the Content-Length header in responses to HEAD requests for efficiency reasons:

2 Likes

When serving minio deployed on a k8s cluster from cloudflare, this cloudflare behavior breaks minio behavior. How can I work around this?

:point_up:

2 Likes

Where can I disable it ? Rules → Transform Rules → Modify Request Header?

You can find Cache Rules in the Cache section, not in the Rules section.

Which the setting name in Cache Rule?

non-cacheable via a Cache Rule.

image

I have had this setup for my server host for some time now since minio’s preview does not work via cloudflare.

It is called “Bypass Cache”.

Yes, already have (please see above)

What cf-cache-status headers do you see on both GET and HEAD requests for the target file?

mc cat --debug [path/to/minio/bucket/index.html] |& grep ^Cf-Cache-Status
Cf-Cache-Status: DYNAMIC
Cf-Cache-Status: DYNAMIC

It’s already 1:30am here, so I will see if I can reproduce that behaviour tomorrow.

1 Like

Hi, I’ve been looking around some more and found this:

I can confirm that, as soon as I add a Cache control: no-transform header to the file on the Origin, I do receive a content-length header. I haven’t found another way of getting Cloudflare to send the Content-Length header so far, but maybe this helps you find something.

1 Like

Cache-control can not be set.

I could set Cache-control in “Modify Response header” but no effects.

It would have to be set on the origin.

Do you mean modify metadata on minio?

$ mc cp index.html --attr Cache-Control=no-transform [path/to/bucket/path]/