Send content-length header

Status
Not open for further replies.

bmccoy11

Member
Messages
101
Reaction score
6
Points
18
Why isn't the content-length header set by default? It looks like it was disabled back when the new Varnish caching system was enabled, and I can't find a way to re-enable it. Disabling the Varnish cache via .htaccess didn't help. Does anyone know how to enable it?
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Content length is set and returned by Varnish.

Where are you seeing that it is not?
 

bmccoy11

Member
Messages
101
Reaction score
6
Points
18
Try https://i.bmccoy.cf/sampletext.txt . No content length header is sent when I try to download anything, and Peerr5 won't work when the content-length header isn't set. (please note that I'm not using this for file hosting, just for downloadable image galleries related to my website.)
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
That would be because you're behind cloudflare. Varnish/Apache on the server are returning a content-length for the file.

2015-03-04_1657.png
 

bmccoy11

Member
Messages
101
Reaction score
6
Points
18
I turned off Cloudflare and I'm still not getting a content-length header.
 

AngusThermopyle

Active Member
Messages
319
Reaction score
52
Points
28
Code:
Accept-Ranges    bytes, bytes
Age    0
Cache-Control    max-age=0, no-cache, no-store, must-revalidate
Connection    keep-alive
Content-Length    364
Content-Type    text/plain
Date    Thu, 05 Mar 2015 00:14:48 GMT
Last-Modified    Wed, 04 Mar 2015 19:59:59 GMT
X-Cache    MISS
X-Varnish    14899040
access-control-allow-orig...    *

The headers I just got.
Try again, and if you still don't get content-length, ping your site and make sure you are not still going through Cloudflare (your site should resolve to IP 198.91.81.3)
 

bmccoy11

Member
Messages
101
Reaction score
6
Points
18
I'm still not receiving any content-length headers. Cloudflare is completely off and the subdomain is resolving to 198.91.81.3.

Edit: It looks like some files are returning content-length headers, while some others are not. Weird.
 
Last edited:

AngusThermopyle

Active Member
Messages
319
Reaction score
52
Points
28
Does it correspond to the value of X-Cache (ie HIT vs MISS) ?
I just retried that file and got a cache HIT that did not have the content-length
 

bmccoy11

Member
Messages
101
Reaction score
6
Points
18
No, it does not correspond to that. I just tried one that got a cache MISS and didn't have the content-length header either.
 

AngusThermopyle

Active Member
Messages
319
Reaction score
52
Points
28
Googling "varnish headers content length" seems to indicate it is/was an issue with Varnish. Not sure if it was ever resolved.
 

Skizzerz

Contributors
Staff member
Contributors
Messages
2,928
Reaction score
118
Points
63
I think your cache disabling bit is working for me because I cannot get any cache hits on that file (they always miss). That said, check the Transfer-Encoding header whenever you see Content-Length missing -- if Transfer-Encoding is set to chunked, then Content-Length cannot be specified (it is actually in violation of the HTTP spec to do so). It is possible that Varnish is chunking cached files and that is why you are not seeing the header. If that is the case, fix whatever app you are using to suck less and actually conform to the HTTP spec (or do your requests in HTTP/1.0 where chunking isn't a thing)
 

bmccoy11

Member
Messages
101
Reaction score
6
Points
18
I just fixed the line to disable caching in .htaccess, I was actually missing a value. Here's the app I'm using, by the way.
 
Last edited:

bmccoy11

Member
Messages
101
Reaction score
6
Points
18
Sorry if that came off wrong... My problem still isn't fixed. I just added one thing to my .htaccess file so X-Cache returns MISS every time. I also tried downgrading to HTTP 1.0 and disabled gzip, which still didn't fix the chunking.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
What is an example link that is not showing a content length? Your previous link is not loading.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
I would recommend that you manually set the content-length headers for these files by serving them using a PHP redirect. It is obvious that the script you are using is unable to deal with chunked encoding, and beyond what we've already tried (namely disabling gzip and attempting to force http-1.0) there is not much else we can do. @Skizzerz might have another suggestion.
 

bmccoy11

Member
Messages
101
Reaction score
6
Points
18
Here's my .htaccess file.

Code:
#
# DIRECTORY LISTING
#

DirectoryIndex index.html index.php /.h5ai/server/php/index.php

Options -Indexes

#
# PEER5 SUPPORT
#

Header set Access-Control-Allow-Origin "*"

#
# DISABLE CACHING
#

Header set Cache-Control "max-age=0, private, no-cache, no-store, must-revalidate"


#
# NO CHUNKING
#

RewriteRule . - [E=no-gzip:1]
SetEnv downgrade-1.0
 

bmccoy11

Member
Messages
101
Reaction score
6
Points
18
Okay, so in case anyone else is having this issue, I've figured it out. Varnish Cache is falsely adding the Transfer-Encoding: Chunked header to a lot of files while removing the content-length header, even when the payload isn't chunked. The bug has been around for a while, and Varnish still hasn't fixed it. Currently, the only way around it is to use port 82 to bypass Varnish completely. x10Hosting has a Varnish cPanel plugin in development which may or may not let users completely disable Varnish, which will probably be released a long time from now.
 
Status
Not open for further replies.
Top