Missing Content-Length in HTTP headers for some URLs

I’ve got Drupal 7.x website and after setting-up Cloudflare there is a problem on mobile devices (tested on iPhone, but same problem is on Android devices; desktop browsers somehow manage this problem and can download PDF properly even without Content-Length) with PDF files served via Drupal aliases. After “Pause” on CF everything works fine, so it looks like this issue is CF related, not Drupal.
For some reason CF cuts out “Content-Length” for these URLs.

Example:
> curl -I https://mahajana.net/teksty/zazen-kodo-sawaki.pdf
doesn’t return “Content-lenght” in HTTP headers…

…but bypassing CF and going directly to server’s IP returns proper header:
> curl -I --resolve mahajana.net:443:91.121.209.206 https://mahajana.net/teksty/zazen-kodo-sawaki.pdf

I’ve tried to turnoff all CF features and also set-up some page rules, but no result, same problem:
*mahajana.net/teksty/*
Disable Security, Disable Zaraz, Disable Apps, Disable Performance
*mahajana.net/*
Cache Level: Bypass

Any help with that?

Possibly this…?

Thank you, but unfortunately it’s not this and adding ‘no-transform’ doesn’t help.

Strange testing your pdf at https://tools.keycdn.com/curl content-length header only shows for gzip tests

HTTP/2
200
date: Thu, 26 Oct 2023 17:42:34 GMT
content-type: application/pdf
content-length: 65986
x-drupal-cache: HIT
cache-control: public, max-age=14400, no-transform
content-language: pl
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
expires: Sun, 19 Nov 1978 05:00:00 GMT
vary: Cookie,Accept-Encoding
content-encoding: gzip
strict-transport-security: max-age=15552000; includeSubDomains
etag: "1698341264-1"
last-modified: Thu, 26 Oct 2023 17:27:44 GMT
cf-cache-status: MISS
accept-ranges: bytes
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=X%2FnkikMPJrcC3qNDehLNaXUkrJTzPgR6GKgUGfZRbc2hFnwu15sLHg%2BbzE7fosyCCYa8k9lHb0e2HmtIfEZqk5x02%2B75TWscXRvpaKzbkfsxi9cfOF%2Fp0igNxquKnpc%3D"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
server: cloudflare
cf-ray: 81c47f1f0a641e57-FRA

wonder if it's related to `x-drupal-cache` ? If you disable Drupal cache, how does it fair?
2 Likes

Doesn’t that show that in-flight compression by Cloudflare is the reason? If the origin delivers gzip, and then Cloudflare delivers gzip to you, then the file size is known and can be given. If the origin delivers gzip but the browser asks for brotli, or non-compressed, then the change by on-the-fly compression/decompression means the file size is unknown at the time the headers are produced.

Wow, thank you so much! I don’t get exactly why it’s a problem, but I’ve switched off Drupal’s cache and it works!

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