Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Resources dropped with "Connection: close" header #11141

Open
TimOrme opened this Issue Mar 15, 2013 · 15 comments

Comments

Projects
None yet
5 participants

TimOrme commented Mar 15, 2013

Hello,

I have two css files served from a cdn:

cdn.com/header.css
cdn.com/footer.css

Header.css returns with these request headers:

Cache-Control:public, max-age=86400
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:4459
Content-Type:application/x-javascript
Date:Fri, 15 Mar 2013 19:51:32 GMT
Vary:Accept-Encoding, User-Agent

Footer.css returns with these:

Cache-Control:private
Connection:close
Content-Type:application/x-javascript
Date:Fri, 15 Mar 2013 19:52:13 GMT

When I run the following simple test:

var page = require('webpage').create();
var url = 'http://mytest.com/';

page.onResourceReceived = function(resource) {
    if(resource.status != "200" && resource.status != "302"){
        console.log("Failed to receive resource with code " + resource.status + " : " + resource.url);
    }
};

page.open(url, function (status) {
    //Page is loaded!
    phantom.exit();
});

I get the following ouput:

Failed to receive resource with code null : http://cdn.com/footer.css

It appears that most of the resource object is empty. Running through casper and the only values that are filled are the url and time.

And the resource is not loaded onto the page. Making a little bit of a leap and guessing that maybe the "Connection: close" header is causing these resources to be dropped.

Thanks,
Tim

Collaborator

JamesMGreene commented Mar 17, 2013

The Connection: Close HTTP header should just indicate to the user agent (PhantomJS, in this case) that it shouldn't maintain a persistent connection after this response has ended, so it shouldn't cause a problem like this.

I'm much more suspicious of the conflicting Content-Type HTTP header which indicates this CSS file is actually JavaScript:

Content-Type: application/x-javascript

TimOrme commented Mar 17, 2013

Thats a good point too, but the header.css file works fine with a conflicting content-type header.

Collaborator

JamesMGreene commented Mar 17, 2013

Hmm, true. How about the missing Content-Length header? Pretty sure that is a required header for responses: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

TimOrme commented Mar 19, 2013

Well even the w3 stuff just says it SHOULD exist, but I can't find anything saying it's strictly required. My knowledge of the w3 spec isn't fantastic, but this stack overflow article seems to imply that if the connection type is close, then content length isn't required:

http://stackoverflow.com/questions/4726515/clean-http-response-header

My main concern is that any browser I've tested this in handles these headers gracefully, and content is rendered correctly, but phantom just drops them. If the ideal is to have a stricter implementation of HTTP, then it'd be cool if phantom gave some error information as to why the resources were left out.

Collaborator

JamesMGreene commented Mar 19, 2013

PhantomJS 1.9 (scheduled to come out tomorrow) will add an onResourceError callback.

TimOrme commented Mar 25, 2013

After updating to Phantom 1.9, the error information is much more informative, which is awesome. However, it does look like Phantom is killing resources with "Connection: close" when it shouldn't: Now, with the following handler:

page.onResourceError = function(errorData) {
    console.log('Unable to load resource (URL:' + errorData.url + ')');
    console.log('Error code: ' + errorData.errorCode + '. Description: ' + errorData.errorString);
};

I get the following:

Unable to load resource (URL:http://cdn.com/footer.css)
Error code: 2. Description: Connection closed

Thanks!
Tim

vinnitu commented Nov 12, 2014

I have such problem with http://hotmail.com

In this case we can see
301 -> http://hotmail.com/default.aspx

page load status is fail because

Unable to load resource (#2URL:https://mail.live.com/default.aspx)
Error code: 2. Description: Connection closed

and what?

I see that error with 1.9.7, but it is fixed on the master branch, PhantomJS 2. What platform are you running? They're still working on 2.0, but I have binaries for OS X and Fedora 20 posted here: https://github.com/bprodoehl/phantomjs/releases

vinnitu commented Nov 12, 2014

Yes, I hev 1.9.7
but I cannot use https://github.com/bprodoehl/phantomjs/releases/download/2.0.0-20141016/phantomjs-2.0.0-20141016-linux-x86_64.zip, because have troubles with deps

./phantomjs: error while loading shared libraries: libicudata.so.50: cannot open shared object file: No such file or directory

What platform are you running? I'll post binaries for Ubuntu 14.04 x86_64 today, if that helps.

vinnitu commented Nov 12, 2014

ubuntu 14.10 x64

I posted binaries for 14.04 and 14.10. Let me know how they work for you!

https://github.com/bprodoehl/phantomjs/releases

It should still be possible to statically link everything and provide one 64-bit Linux binary, but distros are moving further and further away from providing static libraries, with good reason.

vinnitu commented Nov 13, 2014

I have rebuild dev version by my self - It works!

thx for your help

vinnitu commented Nov 14, 2014

./phantomjs: error while loading shared libraries: libicui18n.so.52: cannot
open shared object file: No such file or directory

2014-11-12 19:33 GMT+02:00 bprodoehl notifications@github.com:

I posted binaries for 14.04 and 14.10. Let me know how they work for you!

https://github.com/bprodoehl/phantomjs/releases

It should still be possible to statically link everything and provide one
64-bit Linux binary, but distros are moving further and further away from
providing static libraries, with good reason.


Reply to this email directly or view it on GitHub
#11141 (comment).

Tried this with phantomjs-2.0.0 (released on January 23, 2015),seems like this is still not fixed. Getting the same error if Content-Length header is missing:


Resource url:http://cdn.com/resource-with-content-length-missing.css
Resource errorCode:2
Resource errorString:Connection closed
Resource id:79


@vinnitu @bprodoehl is this problem gone for you guys? what version of code did you build?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment