[MAGNOLIA-4713] Uncached pages are sent with incorrect content-length response header Created: 05/Dec/12  Updated: 24/May/23  Resolved: 27/Feb/13

Status: Closed
Project: Magnolia
Component/s: cache
Affects Version/s: 4.4.9, 4.5.6
Fix Version/s: 4.5.8, 5.0

Type: Bug Priority: Major
Reporter: Tom Wespi Assignee: Jaroslav Simak
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Tomcat 7


Attachments: PNG File Screen Shot 2012-12-05 at 18.00.33.png     PNG File Screen Shot 2012-12-05 at 18.01.08.png    
Issue Links:
relation
is related to MGNLCACHE-228 Range requests from Facebook don't work Closed
is related to MAGNOLIA-8887 HTTP response to request for asset co... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

This can be seen when sharing a page in Facebook, cached pages are working, while uncached pages cannot be retrieved by Facebook. Since FB is strict about how many bytes it reads from client.

Try to share
http://demopublic.magnolia-cms.com/demo-project.html?test=test
in your Facebook status -> doesen't work

http://demopublic.magnolia-cms.com/demo-project.html
is working



 Comments   
Comment by Tom Wespi [ 05/Dec/12 ]

Use this tool to fetch a page like Facebook
https://developers.facebook.com/tools/debug

Comment by Magnolia International [ 15/Jan/13 ]

Another difference I've noticed is that a request with parameters (which may or may not be related to cache) does not have the Last-Modified and Content-Length headers that a request without parameters has. For some reason, on the other hand, Transfer-Encoding: chunked is present on the with-params request.

Comment by Jaroslav Simak [ 20/Feb/13 ]

Setting flag wrapWriter to false caused that sharing is working. Here is code of the wrapWriter method:

            @Override
            public PrintWriter getWriter() throws IOException {
                if (!wrapWriter) {
                    return super.getWriter();
                }
                if (this.writer == null) {
                    this.writer = new PrintWriter(new OutputStreamWriter(getOutputStream()));
                }
                return writer;
            }
Comment by Jaroslav Simak [ 27/Feb/13 ]

So in the end sharing problem is caused by response.setContentLength(range.lengthOfRange); in RangeSupportFilter. Removing it will "enable" facebook sharing. The problem is that content length is set to bigger value (512K) than real content length (xxK). This means that facebook is trying to download more content but nothing is coming to him. I hope my explanation is clear.
To see what is happening just use this command:

curl --range 0-524287 -H "User-Agent: facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)
    Host: magnolia-cms.com
    Accept: */*
    Accept-Encoding: deflate, gzip
    Range: bytes=0-524287
    Connection: keep-alive
    " http://demopublic.magnolia-cms.com/demo-project.html?test=test > fb_prob

Btw according to RFC it should fine to not set content-length if we don't know it.

Generated at Mon Feb 12 03:58:19 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.