Builds rewrite domain from backend route url.

@param backendRoute Backend route.
@param subzone      Subzone
@return Rewrite domain.
@throws MalformedURLException if backendRoute parameter has invalid format.
5579
public static String buildRewriteDomain(String backendRoute, String subzone) throws MalformedURLException {
        if (backendRoute == null || backendRoute.isEmpty()) {
            logger.error("Backend route can't be null.");
            return null;
        }

        String applicationRoute = backendRoute;

        if (!applicationRoute.startsWith(BMSClient.HTTP_SCHEME)) {
            applicationRoute = String.format("%s://%s", BMSClient.HTTPS_SCHEME, applicationRoute);
        } else if (!applicationRoute.startsWith(BMSClient.HTTPS_SCHEME) && applicationRoute.contains(BLUEMIX_NAME)) {
            applicationRoute = applicationRoute.replace(BMSClient.HTTP_SCHEME, BMSClient.HTTPS_SCHEME);
        }

        URL url = new URL(applicationRoute);

        String host = url.getHost();
        String rewriteDomain;
        String regionInDomain = "ng";
        int port = url.getPort();

        String serviceUrl = String.format("%s://%s", url.getProtocol(), host);

        if (port != 0) {
            serviceUrl += ":" + String.valueOf(port);
        }

        String[] hostElements = host.split("\\.");

        if (!serviceUrl.contains(STAGE1_NAME)) {
            // Multi-region: myApp.eu-gb.mybluemix.net
            // US: myApp.mybluemix.net
            if (hostElements.length == 4) {
                regionInDomain = hostElements[hostElements.length - 3];
            }

            // this is production, because STAGE1 is not found
            // Multi-Region Eg: eu-gb.bluemix.net
            // US Eg: ng.bluemix.net
            rewriteDomain = String.format("%s.%s", regionInDomain, BLUEMIX_DOMAIN);
        } else {
            // Multi-region: myApp.stage1.eu-gb.mybluemix.net
            // US: myApp.stage1.mybluemix.net
            if (hostElements.length == 5) {
                regionInDomain = hostElements[hostElements.length - 3];
            }

            if (subzone != null && !subzone.isEmpty()) {
                // Multi-region Dev subzone Eg: stage1-Dev.eu-gb.bluemix.net
                // US Dev subzone Eg: stage1-Dev.ng.bluemix.net
                rewriteDomain = String.format("%s-%s.%s.%s", STAGE1_NAME, subzone, regionInDomain, BLUEMIX_DOMAIN);
            } else {
                // Multi-region Eg: stage1.eu-gb.bluemix.net
                // US  Eg: stage1.ng.bluemix.net
                rewriteDomain = String.format("%s.%s.%s", STAGE1_NAME, regionInDomain, BLUEMIX_DOMAIN);
            }
        }

        return rewriteDomain;
    }
953645
def get_DID_subdomain(did, db_path=None, zonefiles_dir=None, atlasdb_path=None, check_pending=False):
    
    opts = get_blockstack_opts()
    if not is_subdomains_enabled(opts):
        log.warn("Subdomain support is disabled")
        return None

    if db_path is None:
        db_path = opts['subdomaindb_path']

    if zonefiles_dir is None:
        zonefiles_dir = opts['zonefiles']
    
    if atlasdb_path is None:
        atlasdb_path = opts['atlasdb_path']

    db = SubdomainDB(db_path, zonefiles_dir)
    try:
        subrec = db.get_DID_subdomain(did)
    except Exception as e:
        if BLOCKSTACK_DEBUG:
            log.exception(e)

        log.warn("Failed to load subdomain for {}".format(did))
        return None

    if check_pending:
        # make sure that all of the zone files between this subdomain's
        # domain's creation and this subdomain's zone file index are present,
        # minus the ones that are allowed to be missing.
        subrec.pending = db.subdomain_check_pending(subrec, atlasdb_path)

    return subrec
846480
def make_subdomain_txt(name_or_fqn, domain, address, n, zonefile_str, privkey_bundle):
    
    subrec = Subdomain(str(name_or_fqn), str(domain), str(address), int(n), str(zonefile_str), None, None, None, None, None, None)
    subrec_plaintext = subrec.get_plaintext_to_sign()
    sig = sign(privkey_bundle, subrec_plaintext)
    
    subrec = Subdomain(str(name_or_fqn), str(domain), str(address), int(n), str(zonefile_str), str(sig), None, None, None, None, None)
    return subrec.serialize_to_txt()
1143903
public OvhBackend serviceName_domains_domain_backends_ip_GET(String serviceName, String domain, String ip) throws IOException {
		String qPath = "/cdn/dedicated/{serviceName}/domains/{domain}/backends/{ip}";
		StringBuilder sb = path(qPath, serviceName, domain, ip);
		String resp = exec(qPath, "GET", sb.toString(), null);
		return convertTo(resp, OvhBackend.class);
	}
1162179
@Override
  public Map<String, Object> rewrite(boolean showDebugInfo) throws IOException {
    Map<String, Object> response = new HashMap<>();
    for (String statsItem : getStatsItems()) {
      if (statsItem.equals(CodecUtil.STATS_TYPE_SUM)) {
        response.put(statsItem, valueSum);
      } else if (statsItem.equals(CodecUtil.STATS_TYPE_N)) {
        response.put(statsItem, valueN);
      } else if (statsItem.equals(CodecUtil.STATS_TYPE_MEAN)) {
        response.put(statsItem, getValue(statsItem));
      } else {
        response.put(statsItem, null);
      }
    }
    if (errorNumber > 0) {
      Map<String, Object> errorResponse = new HashMap<String, Object>();
      for (Entry<String, Integer> entry : getErrorList().entrySet()) {
        errorResponse.put(entry.getKey(), entry.getValue());
      }
      response.put("errorNumber", errorNumber);
      response.put("errorList", errorResponse);
    }
    if (showDebugInfo) {
      response.put("sourceNumber", sourceNumber);
      response.put("stats", "basic");
    }
    return response;
  }
803757
def subdomain(self, domain, depth):
        
        p = self.privateparts(domain)
        if p is None or depth > len(p) - 1:
            return None
        else:
            return ".".join(p[-(depth+1):])
420662
public FoxHttpRequest build() throws MalformedURLException, FoxHttpRequestException {
        if (this.url != null) {
            foxHttpRequest.setUrl(this.url);
        }
        return foxHttpRequest;
    }
839504
public static URL toURL(String strUrl, int port, boolean encodeIfNecessary) throws MalformedURLException {
	URL url;
	try {
	    url = new URL(strUrl);
	}
	catch (MalformedURLException mue) {
	    url = new URL("http://" + strUrl);
	}
	if (!encodeIfNecessary) return url;
	return encodeURL(url, port);
    }
667501
public OvhBackend serviceName_zone_backends_ipv4_GET(String serviceName, String ipv4) throws IOException {
		String qPath = "/cdn/website/{serviceName}/zone/backends/{ipv4}";
		StringBuilder sb = path(qPath, serviceName, ipv4);
		String resp = exec(qPath, "GET", sb.toString(), null);
		return convertTo(resp, OvhBackend.class);
	}
1187257
private URI spliceUrl(String resource) throws RestEndpointIOException {
        try {
            return Strings.isNullOrEmpty(baseUrl) ? new URI(resource) : new URI(baseUrl.concat(resource));
        } catch (URISyntaxException e) {
            throw new RestEndpointIOException(
                    "Unable to builder URL with base url '" + baseUrl + "' and resouce '" + resource + "'", e);
        }
    }
280409
public String getProxyURLString(HttpServletRequest req) throws MalformedURLException
    {
    	String proxyUrlString = proxyURLPrefix;
    	if (req.getPathInfo() != null)
    		if (req.getPathInfo().length() > 0)
    			proxyUrlString += req.getPathInfo();
    	if (req.getQueryString() != null)
    		if (req.getQueryString().length() > 0)
    			proxyUrlString += "?" + req.getQueryString();
    	req.getContentType();
    	return proxyUrlString;
    }
106103
function createParams(routePattern, fragment, queryString) {
            var params = routePattern.exec(fragment).slice(1);

            for (var i = 0; i < params.length; i++) {
                var current = params[i];
                params[i] = current ? decodeURIComponent(current) : null;
            }

            var queryParams = router.parseQueryString(queryString);
            if (queryParams) {
                params.push(queryParams);
            }

            return {
                params:params,
                queryParams:queryParams
            };
        }
1371904
function updateLink(proxiedUrl, url /*, subdomain*/ ) {
            var next_uri = URL.parse(url);
            if (next_uri.protocol != uri.protocol || next_uri.host != uri.host) {
                // rewrite the url - we want the old proto and domain, but the new path just in case there are any cookies that are limited to that sub-path (although they won't be on the new protodomain...)
                var cookieProxiedUrl = config.prefix + uri.protocol + '//' + uri.host + next_uri.pathname + '?' + REDIRECT_QUERY_PARAM + '=' + encodeURIComponent(url);
                debug('rewriting link from %s to %s in order to allow cookies to be copied over to new path', proxiedUrl, cookieProxiedUrl);
                return cookieProxiedUrl;
            } else {
                // if neither the proto nor the host have changed, just replace it with the same string
                return proxiedUrl;
            }
        }
1117601
public static URL correct(final URL url) throws MalformedURLException {
        if (url == null) {
            throw new MalformedURLException("The url is null");
        }
        return new URL(correct(url.toString(), false));
    }
504766
private static URL toURL(String url, int port) throws MalformedURLException {
	URL u = HTTPUtil.toURL(url, true);
	if (port == -1) return u;
	return new URL(u.getProtocol(), u.getHost(), port, u.getFile());
    }
1003747
function (route) {
        var staticPrefix = null;
        var hostVariables = [];
        var pathVariables = [];
        var variables = [];
        var tokens = [];
        var regex = null;
        var hostRegex = null;
        var hostTokens = [];
        var host;

        if ('' !== (host = route.domain())) {
            var result = compilePattern(route, host, true);

            hostVariables = result['variables'];
            variables = variables.concat(hostVariables);

            hostTokens = result['tokens'];
            hostRegex = result['regex'];
        }

        var path = route.getPath();

        result = compilePattern(route, path, false);

        staticPrefix = result['staticPrefix'];

        pathVariables = result['variables'];
        variables = variables.concat(pathVariables);

        tokens = result['tokens'];
        regex = result['regex'];

        return new CompiledRoute(
            staticPrefix,
            regex,
            tokens,
            pathVariables,
            hostRegex,
            hostTokens,
            hostVariables,
            _.uniq(variables)
        );
    }
958363
def subdomain?(*jids)
      !jids.flatten.index do |jid|
        !component?(jid) && !pubsub?(jid)
      end
    end