{"action":"created","issue":{"url":"https://api.github.com/repos/ariya/phantomjs/issues/14164","repository_url":"https://api.github.com/repos/ariya/phantomjs","labels_url":"https://api.github.com/repos/ariya/phantomjs/issues/14164/labels{/name}","comments_url":"https://api.github.com/repos/ariya/phantomjs/issues/14164/comments","events_url":"https://api.github.com/repos/ariya/phantomjs/issues/14164/events","html_url":"https://github.com/ariya/phantomjs/issues/14164","id":145507526,"number":14164,"title":"Messing with `Host:` in custom headers causes \"Operation canceled\" errors","user":{"login":"zackw","id":325899,"avatar_url":"https://avatars.githubusercontent.com/u/325899?v=3","gravatar_id":"","url":"https://api.github.com/users/zackw","html_url":"https://github.com/zackw","followers_url":"https://api.github.com/users/zackw/followers","following_url":"https://api.github.com/users/zackw/following{/other_user}","gists_url":"https://api.github.com/users/zackw/gists{/gist_id}","starred_url":"https://api.github.com/users/zackw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zackw/subscriptions","organizations_url":"https://api.github.com/users/zackw/orgs","repos_url":"https://api.github.com/users/zackw/repos","events_url":"https://api.github.com/users/zackw/events{/privacy}","received_events_url":"https://api.github.com/users/zackw/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ariya/phantomjs/labels/2.0","name":"2.0","color":"52a6e0"},{"url":"https://api.github.com/repos/ariya/phantomjs/labels/Bug","name":"Bug","color":"f45d43"},{"url":"https://api.github.com/repos/ariya/phantomjs/labels/Need%20design","name":"Need design","color":"FBCA04"},{"url":"https://api.github.com/repos/ariya/phantomjs/labels/PJS%20core","name":"PJS core","color":"4C8CE6"},{"url":"https://api.github.com/repos/ariya/phantomjs/labels/Qt","name":"Qt","color":"BFD4F2"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-03T14:40:47Z","updated_at":"2016-04-03T14:42:14Z","closed_at":null,"body":"Originally reported as part of issue #12750, but I'm betting it is not the same problem.\r\n\r\n@gsouf wrote:\r\n> Executing phantomjs with this file will **work**:\r\n>\r\n> ```js\r\n> \"use strict\";\r\n> var page = require('webpage').create();\r\n> var lastResourceError = null;\r\n>\r\n> page.onResourceError = function (resourceError) {\r\n>       console.log(\"Url errored: \" + resourceError.url);\r\n>       console.log(\"message : \" + resourceError.errorString);\r\n>     console.log(\"------\")\r\n> };\r\n>\r\n> var settings = {\r\n> }\r\n>\r\n> var url = \"https://www.wikipedia.org/\";\r\n>\r\n> page.open(url, settings, function (status) {\r\n>     if (status !== 'success') {\r\n>         console.error('Error');\r\n>         phantom.exit(1);\r\n>     } else {\r\n>       console.log(page.plainText);\r\n>         phantom.exit();\r\n>     }\r\n> });\r\n> \"use strict\";\r\n> var page = require('webpage').create();\r\n> var lastResourceError = null;\r\n>\r\n> page.onResourceError = function (resourceError) {\r\n>       console.log(\"Url errored: \" + resourceError.url);\r\n>       console.log(\"message : \" + resourceError.errorString);\r\n>     console.log(\"------\")\r\n> };\r\n>\r\n> var settings = {\r\n> }\r\n>\r\n> var url = \"https://www.wikipedia.org/\";\r\n>\r\n> page.open(url, settings, function (status) {\r\n>     if (status !== 'success') {\r\n>         console.error('Error');\r\n>         phantom.exit(1);\r\n>     } else {\r\n>       console.log(page.plainText);\r\n>         phantom.exit();\r\n>     }\r\n> });\r\n> ```\r\n>\r\n> now replace the ``settings`` variable to this:\r\n>\r\n> ```\r\n> var settings = {\r\n>       \"headers\": {\r\n>               \"Host\": \"wikipedia.org\"\r\n>       }\r\n> }\r\n>\r\n> var url = \"https://www.wikipedia.org/\";\r\n> ```\r\n>\r\n> And execute that will **fail**\r\n>\r\n> Now replace the setting to a different host, and that will **work** (though the server returns a domain error):\r\n>\r\n> ```\r\n> var settings = {\r\n>       \"headers\": {\r\n>               \"Host\": \"google.com\"\r\n>       }\r\n> }\r\n>\r\n> var url = \"https://www.wikipedia.org/\";\r\n> ```\r\n>\r\n> Querying google with different existing tld will fail (google redirects to the tld in the host)\r\n>\r\n> ```\r\n> var settings = {\r\n>       \"headers\": {\r\n>               \"Host\": \"google.fr\"\r\n>       }\r\n> }\r\n>\r\n> var url = \"https://www.google.com/\";\r\n> ```\r\n>\r\n> (redirect to google.fr then fails)\r\n>\r\n> I found a case in which it works: with the website getcomposer.org. Maybe is it due to what resources are loaded or not on the page.\r\n>\r\n> The two following examples **work**:\r\n>\r\n>\r\n> ```\r\n> var settings = {\r\n> }\r\n>\r\n> var url = \"https://getcomposer.org\";\r\n> ```\r\n>\r\n> ```\r\n> var settings = {\r\n>       \"headers\": {\r\n>               \"Host\": \"getcomposer.org\"\r\n>       }\r\n> }\r\n>\r\n> var url = \"https://getcomposer.org\";\r\n> ```\r\n>\r\n> But for some reasons this will also **fail** (operation cancelled)\r\n>\r\n> ```\r\n> var settings = {\r\n>       \"headers\": {\r\n>               \"Host\": \"foo.bar\"\r\n>       }\r\n> }\r\n>\r\n> var url = \"https://getcomposer.org\";\r\n> ```\r\n>\r\n> As a side note for this last example, I tried it in chrome leads to a loop redirection.\r\n>\r\n> Last note: trying this on a page that does not load much resources (http://httpbin.org/get) seems to work in every cases.\r\n\r\nGiven the crucial importance of `Host:` to the low-level workings of HTTP, Qt screwing up the protocol when it's overridden in custom headers is not terribly surprising.  I am inclined to say that this should not be supported and maybe page.open should throw an error if you try it.  @Vitallium @ariya: thoughts?\r\n"},"comment":{"url":"https://api.github.com/repos/ariya/phantomjs/issues/comments/204991648","html_url":"https://github.com/ariya/phantomjs/issues/14164#issuecomment-204991648","issue_url":"https://api.github.com/repos/ariya/phantomjs/issues/14164","id":204991648,"user":{"login":"gsouf","id":3215399,"avatar_url":"https://avatars.githubusercontent.com/u/3215399?v=3","gravatar_id":"","url":"https://api.github.com/users/gsouf","html_url":"https://github.com/gsouf","followers_url":"https://api.github.com/users/gsouf/followers","following_url":"https://api.github.com/users/gsouf/following{/other_user}","gists_url":"https://api.github.com/users/gsouf/gists{/gist_id}","starred_url":"https://api.github.com/users/gsouf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gsouf/subscriptions","organizations_url":"https://api.github.com/users/gsouf/orgs","repos_url":"https://api.github.com/users/gsouf/repos","events_url":"https://api.github.com/users/gsouf/events{/privacy}","received_events_url":"https://api.github.com/users/gsouf/received_events","type":"User","site_admin":false},"created_at":"2016-04-03T14:42:14Z","updated_at":"2016-04-03T14:42:14Z","body":":+1: "}}