Returns the scheme + host + port part of the url.
This allows us to link to services on the same machine.
<p>For example, a URL of http://myhost.com:8080/myapp/doit.do will get a
result "http://myhost.com:8080"

@param request
@return scheme + host + port
769487
public static String getURLshp(final HttpServletRequest request) {
    String scheme = request.getScheme();
    StringBuilder sb = new StringBuilder(scheme);

    sb.append("://");
    sb.append(request.getServerName());

    int port = request.getServerPort();

    if ("http".equalsIgnoreCase(scheme) && (port == 80)) {
      return sb.toString();
    }

    if ("https".equalsIgnoreCase(scheme) && (port == 443)) {
      return sb.toString();
    }

    sb.append(":");
    sb.append(port);

    return sb.toString();
  }
1275936
public static URL buildUrl(String scheme, String host, int port, String path, Map<String, String> parameters) throws MalformedURLException {
        checkSchemeAndPort(scheme, port);
        StringBuilder buffer = new StringBuilder();
        if (!host.startsWith(scheme + "://")) {
            buffer.append(scheme).append("://");
        }
        buffer.append(host);
        if (port > 0) {
            buffer.append(':');
            buffer.append(port);
        }
        if (path == null) {
            path = "/";
        }
        buffer.append(path);

        if (!parameters.isEmpty()) {
            buffer.append('?');
        }
        int size = parameters.size();
        for (Map.Entry<String, String> entry : parameters.entrySet()) {
            buffer.append(entry.getKey());
            buffer.append('=');
            Object value = entry.getValue();
            if (value != null) {
                String string = value.toString();
                try {
                    string = URLEncoder.encode(string, UTF8);
                } catch (UnsupportedEncodingException e) {
                    // Should never happen, but just in case
                }
                buffer.append(string);
            }
            if (--size != 0) {
                buffer.append('&');
            }
        }

        /*
         * RequestContext requestContext = RequestContext.getRequestContext(); Auth auth = requestContext.getAuth(); if (auth != null &&
         * !ignoreMethod(getMethod(parameters))) { buffer.append("&api_sig="); buffer.append(AuthUtilities.getSignature(sharedSecret, parameters)); }
         */

        return new URL(buffer.toString());
    }
1217342
public UrlBuilder withHost(String host) {
        if (host == null || host.isEmpty()) {
            this.host = null;
        } else {
            with(host, UrlTokenizerState.SCHEME_OR_HOST);
        }
        return this;
    }
431650
def eff_request_host(request):
    
    erhn = req_host = request_host(request)
    if req_host.find(".") == -1 and not IPV4_RE.search(req_host):
        erhn = req_host + ".local"
    return req_host, erhn
462003
public static String getAbsoluteUrl(SlingHttpServletRequest request, String url) {
        if (!isExternalUrl(url) && url.startsWith("/")) {
            String scheme = request.getScheme().toLowerCase();
            url = scheme + "://" + getAuthority(request) + url;
        }
        return url;
    }
158854
public static String getClientIpAddr(HttpServletRequest request) {
        for (String header : HEADERS_ABOUT_CLIENT_IP) {
            String ip = request.getHeader(header);
            if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
                return ip;
            }
        }
        return request.getRemoteAddr();
    }
509695
public static Tag clientName(HttpRequest request) {
		String host = request.getURI().getHost();
		if (host == null) {
			host = "none";
		}
		return Tag.of("clientName", host);
	}
1058997
public String mapRequestPath(HttpServletRequest request) {

        String endpointName = Path.newInstance(request).firstSegment();
        return StringUtils.lowerCase(endpointName);
    }
306780
private String getUrlPrefix( HttpServletRequest req )
    {
        StringBuilder url = new StringBuilder();
        String scheme = req.getScheme();
        int port = req.getServerPort();
        url.append( scheme );        // http, https
        url.append( "://" );
        url.append( req.getServerName() );
        if ( ( scheme.equals( "http" ) && port != 80 ) || ( scheme.equals( "https" ) && port != 443 ) )
        {
            url.append( ':' );
            url.append( req.getServerPort() );
        }
        return url.toString();
    }
167882
public String encodeURL(String relativePath, String scheme) {
		StringBuffer urlEncoded = new StringBuffer();
		//Context
		Context context = (Context)sipManager.getContainer();
		//Host
		Host host = (Host)context.getParent();
		//Service
		Service service = ((Engine)host.getParent()).getService();
		String[] aliases = host.findAliases();
		String hostname = null;
		
		// Needed for http://code.google.com/p/sipservlets/issues/detail?id=150
		// to pass TCK test com.bea.sipservlet.tck.agents.api.javax_servlet_sip.ConvergedHttpSessionTest.testEncodeURL002
		if(aliases.length < 1) {
			hostname = host.getName();
		} else {
			// FIXME would be better to try to match the alias by some path or IP but unaware if this is really needed at this point
			// or how it can be effectively done
			hostname = aliases[0];
		}
		
		//retrieving the port corresponding to the specified scheme
		//TODO ask EG what if the scheme is not supported on the server ?
		int port = -1;		
		Connector[] connectors = service.findConnectors();
		int i = 0;
		while (i < connectors.length && port < 0) {
			if(scheme != null && connectors[i].getProtocol().toLowerCase().contains(scheme.toLowerCase())) {
				port = connectors[i].getPort();
			}
			i++;
		}
		urlEncoded = urlEncoded.append(scheme);
		urlEncoded = urlEncoded.append("://");
		urlEncoded = urlEncoded.append(hostname);
		urlEncoded = urlEncoded.append(":");
		urlEncoded = urlEncoded.append(port);
		urlEncoded = urlEncoded.append(((Context)sipManager.getContainer()).getPath());
		urlEncoded = urlEncoded.append(encodeURL(relativePath));
		return urlEncoded.toString();
	}
1305069
public static String getStringFromPortletUrl(
            PortletUrl portletUrl, HttpServletRequest request) {
        if (portletUrl == null) {
            return null;
        }
        // Default urlType
        UrlType urlType = UrlType.RENDER;
        final PortletUrlType type = portletUrl.getType();
        switch (type) {
            case ACTION:
                urlType = UrlType.ACTION;
                break;
            case RESOURCE:
                urlType = UrlType.RESOURCE;
                break;
            default:
                urlType = UrlType.RENDER;
                break;
        }

        IPortletWindow marketplaceWindow =
                portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(
                        request, MarketplacePortletDefinition.MARKETPLACE_FNAME);
        IPortalUrlBuilder portalUrlBuilder =
                portalUrlProvider.getPortalUrlBuilderByPortletWindow(
                        request, marketplaceWindow.getPortletWindowId(), urlType);
        IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getTargetedPortletUrlBuilder();

        final String portletMode = portletUrl.getPortletMode();
        if (portletMode != null) {
            portletUrlBuilder.setPortletMode(PortletUtils.getPortletMode(portletMode));
        }
        final String windowState = portletUrl.getWindowState();
        if (windowState != null) {
            portletUrlBuilder.setWindowState(PortletUtils.getWindowState(windowState));
        }
        for (final PortletUrlParameter param : portletUrl.getParam()) {
            final String name = param.getName();
            final List<String> values = param.getValue();
            portletUrlBuilder.addParameter(name, values.toArray(new String[values.size()]));
        }

        return portalUrlBuilder.getUrlString();
    }
493662
public static String repositoryUrl( HttpServletRequest request ) {
        String requestURL = request.getRequestURL().toString();
        int delimiterSegmentIdx = requestURL.length();
        for (String methodName : ALL_METHODS) {
            if (requestURL.indexOf(methodName) != -1) {
                delimiterSegmentIdx = requestURL.indexOf(methodName);
                break;
            }
        }
        return requestURL.substring(0, delimiterSegmentIdx);
    }
714159
protected static String adjustMappedUrl(SlingHttpServletRequest request, String url) {
        // build a pattern with the (false) default port
        Pattern defaultPortPattern = Pattern.compile(
                URL_PATTERN_STRING.replaceFirst("\\(:\\\\d\\+\\)\\?", ":" + getDefaultPort(request)));
        Matcher matcher = defaultPortPattern.matcher(url);
        // remove the port if the URL matches (contains the port nnumber)
        if (matcher.matches()) {
            if (null == matcher.group(1)) url = "//" + matcher.group(2);
            else url = matcher.group(1) + "://" + matcher.group(2);
            String uri = matcher.group(3);
            if (StringUtils.isNotBlank(uri)) {
                url += uri;
            } else {
                url += "/";
            }
        }
        return url;
    }
1343002
def request_host(request):
    
    url = request.get_full_url()
    parse_result = compat.urlparse.urlparse(url)
    scheme, host, port = parse_result.scheme, parse_result.hostname, parse_result.port
    try:
        port = int(port)
    except ValueError:
        pass
    if host == "":
        host = request.get_header("Host", "")

    if port != default_ports.get(scheme):
        host = "%s:%s" % (host, port)
    return host
1244350
public String getHost() {
	String host = Util.getLocalHostAddress();
	try {
	    URL u = new URL("http", host, 80, "/");
	    return u.getHost();
	} catch (MalformedURLException e) {
	    return host;
	}
    }
21736
protected String buildUrl(Request request)
    {
        StringBuilder sb = new StringBuilder(512);
        sb.append(baseUrl).append(request.getEntityName()).append("/");
        if(request.getPath() != null)
            sb.append(request.getPath());

        String queryString = buildQueryString(request);
        if(queryString.length()>0)
        {
            sb.append("?").append(queryString);
        }

        return sb.toString();
    }
433933
public static HttpServletRequest getHttpServletRequest(final Request request)
	{
		final WebRequest webRequest = (WebRequest)request;
		final HttpServletRequest httpServletRequest = (HttpServletRequest)webRequest
			.getContainerRequest();
		return httpServletRequest;
	}