get-host-info.sub.js (3039B)
1 /** 2 * Host information for cross-origin tests. 3 * @returns {Object} with properties for different host information. 4 */ 5 function get_host_info() { 6 7 var HTTP_PORT = '{{ports[http][0]}}'; 8 var HTTP_PORT2 = '{{ports[http][1]}}'; 9 var HTTPS_PORT = '{{ports[https][0]}}'; 10 var HTTPS_PORT2 = '{{ports[https][1]}}'; 11 var PROTOCOL = self.location.protocol; 12 var IS_HTTPS = (PROTOCOL == "https:"); 13 var PORT = IS_HTTPS ? HTTPS_PORT : HTTP_PORT; 14 var PORT2 = IS_HTTPS ? HTTPS_PORT2 : HTTP_PORT2; 15 var HTTP_PORT_ELIDED = HTTP_PORT == "80" ? "" : (":" + HTTP_PORT); 16 var HTTP_PORT2_ELIDED = HTTP_PORT2 == "80" ? "" : (":" + HTTP_PORT2); 17 var HTTPS_PORT_ELIDED = HTTPS_PORT == "443" ? "" : (":" + HTTPS_PORT); 18 var PORT_ELIDED = IS_HTTPS ? HTTPS_PORT_ELIDED : HTTP_PORT_ELIDED; 19 var ORIGINAL_HOST = '{{host}}'; 20 var REMOTE_HOST = (ORIGINAL_HOST === 'localhost') ? '127.0.0.1' : ('www1.' + ORIGINAL_HOST); 21 var OTHER_HOST = '{{domains[www2]}}'; 22 var NOTSAMESITE_HOST = (ORIGINAL_HOST === 'localhost') ? '127.0.0.1' : ('{{hosts[alt][]}}'); 23 var OTHER_NOTSAMESITE_HOST = '{{hosts[alt][www2]}}'; 24 25 return { 26 HTTP_PORT: HTTP_PORT, 27 HTTP_PORT2: HTTP_PORT2, 28 HTTPS_PORT: HTTPS_PORT, 29 HTTPS_PORT2: HTTPS_PORT2, 30 HTTP_PORT_ELIDED: HTTP_PORT_ELIDED, 31 HTTPS_PORT_ELIDED: HTTPS_PORT_ELIDED, 32 PORT: PORT, 33 PORT2: PORT2, 34 ORIGINAL_HOST: ORIGINAL_HOST, 35 REMOTE_HOST: REMOTE_HOST, 36 NOTSAMESITE_HOST, 37 38 ORIGIN: PROTOCOL + "//" + ORIGINAL_HOST + PORT_ELIDED, 39 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + HTTP_PORT_ELIDED, 40 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + HTTPS_PORT_ELIDED, 41 HTTPS_ORIGIN_WITH_CREDS: 'https://foo:bar@' + ORIGINAL_HOST + HTTPS_PORT_ELIDED, 42 HTTP_ORIGIN_WITH_DIFFERENT_PORT: 'http://' + ORIGINAL_HOST + HTTP_PORT2_ELIDED, 43 REMOTE_ORIGIN: PROTOCOL + "//" + REMOTE_HOST + PORT_ELIDED, 44 OTHER_ORIGIN: PROTOCOL + "//" + OTHER_HOST + PORT_ELIDED, 45 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + HTTP_PORT_ELIDED, 46 HTTP_NOTSAMESITE_ORIGIN: 'http://' + NOTSAMESITE_HOST + HTTP_PORT_ELIDED, 47 HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT: 'http://' + REMOTE_HOST + HTTP_PORT2_ELIDED, 48 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + HTTPS_PORT_ELIDED, 49 HTTPS_REMOTE_ORIGIN_WITH_CREDS: 'https://foo:bar@' + REMOTE_HOST + HTTPS_PORT_ELIDED, 50 HTTPS_NOTSAMESITE_ORIGIN: 'https://' + NOTSAMESITE_HOST + HTTPS_PORT_ELIDED, 51 HTTPS_OTHER_NOTSAMESITE_ORIGIN: 'https://' + OTHER_NOTSAMESITE_HOST + HTTPS_PORT_ELIDED, 52 UNAUTHENTICATED_ORIGIN: 'http://' + OTHER_HOST + HTTP_PORT_ELIDED, 53 AUTHENTICATED_ORIGIN: 'https://' + OTHER_HOST + HTTPS_PORT_ELIDED 54 }; 55 } 56 57 /** 58 * When a default port is used, location.port returns the empty string. 59 * This function attempts to provide an exact port, assuming we are running under wptserve. 60 * @param {*} loc - can be Location/<a>/<area>/URL, but assumes http/https only. 61 * @returns {string} The port number. 62 */ 63 function get_port(loc) { 64 if (loc.port) { 65 return loc.port; 66 } 67 return loc.protocol === 'https:' ? '443' : '80'; 68 }